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-614, implement fields initial values #137

Merged
merged 1 commit into from
May 30, 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 @@ -13,6 +13,7 @@
import org.openmrs.module.registrationapp.RegistrationAppUiUtils;
import org.openmrs.module.registrationapp.form.RegisterPatientFormBuilder;
import org.openmrs.module.registrationapp.model.NavigableFormStructure;
import org.openmrs.module.registrationapp.model.Question;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.BindParams;
import org.openmrs.ui.framework.annotation.SpringBean;
Expand All @@ -28,16 +29,17 @@ public class RegisterPatientPageController extends AbstractRegistrationAppPageCo
public void get(UiSessionContext sessionContext, PageModel model,
@RequestParam("appId") AppDescriptor app,
@RequestParam(value = "breadcrumbOverride", required = false) String breadcrumbOverride,
@RequestParam(value = "initialValues", required = false) String initialValues,
@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, appFrameworkService, sessionContext);
addModelAttributes(model, patient, app, emrApiProperties.getPrimaryIdentifierType(), breadcrumbOverride, initialValues, appFrameworkService, sessionContext);
}

public void addModelAttributes(PageModel model, Patient patient, AppDescriptor app, PatientIdentifierType primaryIdentifierType, String breadcrumbOverride, AppFrameworkService appFrameworkService, UiSessionContext sessionContext) throws Exception {
public void addModelAttributes(PageModel model, Patient patient, AppDescriptor app, PatientIdentifierType primaryIdentifierType, String breadcrumbOverride, String initialValues, 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 @@ -66,6 +68,7 @@ public void addModelAttributes(PageModel model, Patient patient, AppDescriptor a
model.addAttribute("enableOverrideOfAddressPortlet",
Context.getAdministrationService().getGlobalProperty("addresshierarchy.enableOverrideOfAddressPortlet", "false"));
model.addAttribute("breadcrumbOverride", breadcrumbOverride);
model.addAttribute("initialFieldValues", initialValues);
model.addAttribute("relationshipTypes", Context.getPersonService().getAllRelationshipTypes());

List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser("registerPatient.includeFragments");
Expand Down
26 changes: 26 additions & 0 deletions omod/src/main/webapp/pages/registerPatient.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ fieldset[id\$="-fieldset"] div > div {
sections.push('${section.id}');
<% } %>

jq(document).ready(function() {
if ('${initialFieldValues}') {
let initialValues = JSON.parse('${initialFieldValues}');
let fields = Object.keys(initialValues);
if (fields) {
fields.forEach((field) => {
// fields initial values are passed as a list of property-value
// e.g. {
// "demographics.mothersFirstNameLabel.mothersFirstName": "Jen",
// "contactInfo.phoneNumberLabel.phoneNumber" : "432-098-0987"
// }
// following the existing format of the registration form: SECTION.QUESTION.FIELD
const fieldProps = field.split(".");
if (fieldProps && fieldProps.length == 3 ) {
//section.question.field
let fieldName = fieldProps[2];
jq('input[name="' + fieldName + '"]').val(initialValues[field]);
let questionName = fieldProps[1];
if (NavigatorController.getQuestionById(questionName) != undefined) {
NavigatorController.getQuestionById(questionName).questionLi.addClass("done");
}
}
});
}
}
});
</script>

<div id="validation-errors" class="note-container" style="display: none" >
Expand Down
Loading