Search in sources :

Example 1 with DiagnosesFragmentController

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;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) DiagnosesFragmentController(org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Aggregations

ArrayList (java.util.ArrayList)1 ConceptSearchResult (org.openmrs.ConceptSearchResult)1 DiagnosesFragmentController (org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController)1 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)1 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1