use of org.openmrs.module.htmlformentry.widget.HiddenFieldWidget in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesElement method generateHtml.
@Override
public String generateHtml(FormEntryContext context) {
List<Diagnosis> existingDiagnoses = getExistingDiagnoses(context, emrApiProperties.getDiagnosisMetadata());
if (FormEntryContext.Mode.VIEW == context.getMode()) {
StringBuilder sb = new StringBuilder();
if (existingDiagnoses != null) {
List<ConceptSource> conceptSourcesForDiagnosisSearch = emrApiProperties.getConceptSourcesForDiagnosisSearch();
for (Diagnosis diagnosis : existingDiagnoses) {
sb.append("<p><small>");
// question (e.g. "Primary diagnosis")
sb.append(message("coreapps.patientDashBoard.diagnosisQuestion." + diagnosis.getOrder()));
sb.append("</small><span>");
// answer (e.g. "(Confirmed) Malaria [code]")
sb.append("(" + message("coreapps.Diagnosis.Certainty." + diagnosis.getCertainty()) + ") ");
sb.append(diagnosis.getDiagnosis().formatWithCode(getLocale(), conceptSourcesForDiagnosisSearch));
sb.append("</span></p>");
}
}
return sb.toString();
} else {
hiddenDiagnoses = new HiddenFieldWidget();
errorWidget = new ErrorWidget();
context.registerWidget(hiddenDiagnoses);
context.registerErrorWidget(hiddenDiagnoses, errorWidget);
try {
Map<String, Object> fragmentConfig = new HashMap<String, Object>();
fragmentConfig.put("formFieldName", "encounterDiagnoses");
fragmentConfig.put("existingDiagnoses", existingDiagnoses);
// add the prior diagnoses if requested
if (FormEntryContext.Mode.ENTER == context.getMode() && dispositionTypeForPriorDiagnoses != null) {
fragmentConfig.put("priorDiagnoses", getPriorDiagnoses(context, dispositionTypeForPriorDiagnoses));
}
try {
StringBuilder output = new StringBuilder();
output.append(errorWidget.generateHtml(context));
output.append(uiUtils.includeFragment("coreapps", "diagnosis/encounterDiagnoses", fragmentConfig));
if (selectedDiagnosesTarget != null) {
output.append("\n <script type=\"text/javascript\"> \n $(function() { $('#display-encounter-diagnoses-container').appendTo('" + selectedDiagnosesTarget + "'); }); \n </script>");
}
return output.toString();
} catch (NullPointerException ex) {
// (This is hacky, but I don't see a better way to do it.)
return "Submitting the form, so we don't generate HTML";
}
} catch (PageAction pageAction) {
throw new IllegalStateException("Included fragment threw a PageAction", pageAction);
}
}
}
Aggregations