From 41ed7cef3b407e183a8fee09e85a61b2433b78a3 Mon Sep 17 00:00:00 2001 From: Cosmin Date: Thu, 11 Jul 2024 11:17:41 -0400 Subject: [PATCH 1/2] SL-618: handle additional inital values for registering a baby --- omod/src/main/webapp/pages/registerPatient.gsp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/omod/src/main/webapp/pages/registerPatient.gsp b/omod/src/main/webapp/pages/registerPatient.gsp index 361ede1f..bc3ea5f7 100644 --- a/omod/src/main/webapp/pages/registerPatient.gsp +++ b/omod/src/main/webapp/pages/registerPatient.gsp @@ -141,6 +141,16 @@ 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]); } } }); From df77db454f2eb195d9039e7615e1689821d7be70 Mon Sep 17 00:00:00 2001 From: Cosmin Date: Thu, 11 Jul 2024 18:56:50 -0400 Subject: [PATCH 2/2] SL-618, implement the ability to skip questions and navigate directly to a given question --- .../controller/RegisterPatientPageController.java | 6 ++++-- omod/src/main/webapp/pages/registerPatient.gsp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/page/controller/RegisterPatientPageController.java b/omod/src/main/java/org/openmrs/module/registrationapp/page/controller/RegisterPatientPageController.java index ed052f77..e140358d 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/page/controller/RegisterPatientPageController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/page/controller/RegisterPatientPageController.java @@ -31,6 +31,7 @@ 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, @@ -38,10 +39,10 @@ public void get(UiSessionContext sessionContext, PageModel model, 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()); @@ -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()); diff --git a/omod/src/main/webapp/pages/registerPatient.gsp b/omod/src/main/webapp/pages/registerPatient.gsp index bc3ea5f7..ca5a295d 100644 --- a/omod/src/main/webapp/pages/registerPatient.gsp +++ b/omod/src/main/webapp/pages/registerPatient.gsp @@ -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) { @@ -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"); @@ -154,6 +156,19 @@ fieldset[id\$="-fieldset"] div > div { } } }); + 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(); } } });