Skip to content

Commit

Permalink
UHM-7476, prevent the user from typing in invalid person names (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
cioan committed Oct 31, 2023
1 parent 0c579bf commit 3d1edb6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public void setConfig(Config config) {

public static class Config {

@JsonProperty
private String id;
@JsonProperty
private String relationshipType;

Expand All @@ -41,6 +43,13 @@ public static class Config {
public Config() {
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getRelationshipType() {
return relationshipType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ function RegisterPatientRelationship(patientRelationship) {

let selectedPersons = [];

var relationshipExitHandler = {
handleExit: function(field) {
let fieldId = patientRelationship.id + "-field";
let element = getInputElementFor(fieldId);
// clear any previous errors
$(element).next(".field-error").remove();
if (!field.value()) {
return true;
} else {
let selectedVal = getValue(patientRelationship.id + "-relationship_type");
if ( !selectedVal ) {
// no person from the search results list was selected
$('<span class="field-error" style="">Invalid entry</span>').insertAfter('#' + fieldId);
return false;
} else {
return true;
}
}
return false;
}
}
ExitHandlers['relationships-' + patientRelationship.id] = relationshipExitHandler;
//returns Date in the String format YYYY-MM-DD
function formatDate(inputDate) {
if (inputDate) {
Expand Down Expand Up @@ -76,6 +98,7 @@ function RegisterPatientRelationship(patientRelationship) {
},
select: function (event, ui) {
setValue(patientRelationship.id + "-other_person_uuid", ui.item.data);
$(getInputElementFor(patientRelationship.id + "-field")).next(".field-error").remove();
if (ui.item.data) {
setValue(patientRelationship.id + "-relationship_type", patientRelationship.relationshipType + "-" + patientRelationship.relationshipDirection);
} else {
Expand All @@ -87,35 +110,6 @@ function RegisterPatientRelationship(patientRelationship) {
let element = getInputElementFor(fieldId);
if ( !ui.item ) {
setValue(patientRelationship.id + "-relationship_type", '');
if (getValue(fieldId).length > 0 ) {
if (typeof(NavigatorController) != 'undefined') {
let currentSection = selectedModel(NavigatorController.getSections());
let currentQuestion = selectedModel(NavigatorController.getQuestions());
var field = NavigatorController.getFieldById(fieldId);
if ( currentSection && currentQuestion ) {
setTimeout(function () {
let newSection = selectedModel(NavigatorController.getSections());
let newQuestion = selectedModel(NavigatorController.getQuestions());
if ( newQuestion ) {
newQuestion.toggleSelection();
}
if ( newSection && newSection != currentSection) {
newSection.toggleSelection();
currentSection.toggleSelection();
}
currentQuestion.toggleSelection();
if (field) {
field.select();
}
$('<span class="field-error" style="">Invalid entry</span>').insertAfter('#' + patientRelationship.id + '-field');
});
}
}
} else {
$(element).next(".field-error").remove();
}
} else {
$(element).next(".field-error").remove();
}
}
});
Expand Down

0 comments on commit 3d1edb6

Please sign in to comment.