Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SL-618: handle additional inital values for registering a baby #141

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading