use of org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesFragmentController method generateJsForDiagnoses.
private List<String> generateJsForDiagnoses(List<Diagnosis> diagnoses, UiUtils ui) throws Exception {
// to ensure we have the exact same json format as search results, borrow the simplify method from here
DiagnosesFragmentController diagnosesFragmentController = new DiagnosesFragmentController();
List<String> jsForDiagnoses = new ArrayList<String>();
Collections.sort(diagnoses, new Comparator<Diagnosis>() {
@Override
public int compare(Diagnosis left, Diagnosis right) {
return left.getOrder().compareTo(right.getOrder());
}
});
for (Diagnosis d : diagnoses) {
CodedOrFreeTextAnswer diagnosis = d.getDiagnosis();
String jsDiagnosis;
if (diagnosis.getNonCodedAnswer() != null) {
jsDiagnosis = "'" + ui.escapeJs(diagnosis.getNonCodedAnswer()) + "'";
} else {
ConceptSearchResult csr = new ConceptSearchResult(null, diagnosis.getCodedAnswer(), diagnosis.getSpecificCodedAnswer());
SimpleObject simple = diagnosesFragmentController.simplify(csr, ui, Context.getLocale());
jsDiagnosis = simple.toJson();
}
jsForDiagnoses.add("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer(" + jsDiagnosis + "), confirmed: " + (d.getCertainty().equals(Diagnosis.Certainty.CONFIRMED)) + ", primary: " + (d.getOrder().equals(Diagnosis.Order.PRIMARY)) + ", existingObs: " + d.getExistingObs().getId() + " }");
}
return jsForDiagnoses;
}
Aggregations