Skip to content

Commit

Permalink
SL-618: handle additional inital values for registering a baby (#141)
Browse files Browse the repository at this point in the history
* SL-618: handle additional initial values for registering a baby, and the ability to navigate directly to a given question.
  • Loading branch information
cioan authored Jul 11, 2024
1 parent a567365 commit 207592d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ public void get(UiSessionContext sessionContext, PageModel model,
@RequestParam(value = "breadcrumbOverride", required = false) String breadcrumbOverride,
@RequestParam(value="returnUrl", required=false) String returnUrl,
@RequestParam(value = "initialValues", required = false) String initialValues,
@RequestParam(value = "goToSectionId", required = false) String goToSectionId,
@RequestParam(value = "mother", required = false) Patient mother,
@ModelAttribute("patient") @BindParams Patient patient,
@SpringBean("emrApiProperties") EmrApiProperties emrApiProperties,
@SpringBean("appFrameworkService") AppFrameworkService appFrameworkService,
UiUtils ui) throws Exception {

sessionContext.requireAuthentication();
addModelAttributes(model, patient, app, emrApiProperties.getPrimaryIdentifierType(), breadcrumbOverride, returnUrl, initialValues, mother,appFrameworkService, sessionContext);
addModelAttributes(model, patient, app, emrApiProperties.getPrimaryIdentifierType(), breadcrumbOverride, returnUrl, initialValues, goToSectionId, mother,appFrameworkService, sessionContext);
}

public void addModelAttributes(PageModel model, Patient patient, AppDescriptor app, PatientIdentifierType primaryIdentifierType, String breadcrumbOverride, String returnUrl, String initialValues, Patient mother, AppFrameworkService appFrameworkService, UiSessionContext sessionContext) throws Exception {
public void addModelAttributes(PageModel model, Patient patient, AppDescriptor app, PatientIdentifierType primaryIdentifierType, String breadcrumbOverride, String returnUrl, String initialValues, String goToSectionId, Patient mother, AppFrameworkService appFrameworkService, UiSessionContext sessionContext) throws Exception {
NavigableFormStructure formStructure = RegisterPatientFormBuilder.buildFormStructure(app, app.getConfig().get("combineSections") != null ? app.getConfig().get("combineSections").getBooleanValue() : false,
appFrameworkService, sessionContext.generateAppContextModel());

Expand Down Expand Up @@ -72,6 +73,7 @@ public void addModelAttributes(PageModel model, Patient patient, AppDescriptor a
model.addAttribute("breadcrumbOverride", breadcrumbOverride);
model.addAttribute("returnUrl", returnUrl);
model.addAttribute("initialFieldValues", initialValues);
model.addAttribute("goToSectionId", goToSectionId);
model.addAttribute("mother", mother);
model.addAttribute("relationshipTypes", Context.getPersonService().getAllRelationshipTypes());

Expand Down
25 changes: 25 additions & 0 deletions omod/src/main/webapp/pages/registerPatient.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fieldset[id\$="-fieldset"] div > div {
jq(document).ready(function() {
if ('${initialFieldValues}') {
const registrationQuestions = new Set();
let initialValues = JSON.parse('${initialFieldValues}');
let fields = Object.keys(initialValues);
if (fields) {
Expand All @@ -133,6 +134,7 @@ fieldset[id\$="-fieldset"] div > div {
//section.question.field
let fieldName = fieldProps[2];
let questionName = fieldProps[1];
registrationQuestions.add(questionName);
jq('#' + questionName + ' input[name="' + fieldName + '"]').val(initialValues[field]);
if (NavigatorController.getQuestionById(questionName) != undefined) {
NavigatorController.getQuestionById(questionName).questionLi.addClass("done");
Expand All @@ -141,9 +143,32 @@ fieldset[id\$="-fieldset"] div > div {
if (fieldName == 'mother-field') {
// otherwise the field's change() event that gets trigger automatically would clear the initial values which we just set above
jq('#mother-field').autocomplete("option", "disabled", true);
} else if (fieldName == 'gender') {
// the gender field is a select list of options
jq('#' + questionName + ' select[name="' + fieldName + '"] > option').each(function(){
if (jq(this).text() == initialValues[field]) {
jq(this).prop('selected', true);
}
});
} else if (fieldName == 'birthdateMonth') {
// the birthdateMonth field is a dropdown list of months
jq('#' + questionName + ' select[name="' + fieldName + '"]').val(initialValues[field]);
}
}
});
if (registrationQuestions.size > 0) {
let formQuestions = NavigatorController.getQuestions();
for (let index = 0; index < formQuestions.length; index++) {
let questionId = formQuestions[index].id;
if (registrationQuestions.has(questionId)) {
NavigatorController.getQuestionById(questionId).click();
}
}
}
}
if ('${goToSectionId}') {
let sectionId = '${goToSectionId}';
NavigatorController.getQuestionById(sectionId).click();
}
}
});
Expand Down

0 comments on commit 207592d

Please sign in to comment.