Search in sources :

Example 6 with Diagnosis

use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesElement method handleSubmission.

@Override
public void handleSubmission(FormEntrySession formEntrySession, HttpServletRequest request) {
    DiagnosisMetadata diagnosisMetadata = emrApiProperties.getDiagnosisMetadata();
    String submitted = request.getParameter("encounterDiagnoses");
    // if we are in edit mode, we need to map the submitted diagnoses to their existing obs
    Map<Integer, Obs> existingDiagnosisObs = getExistingDiagnosisObs(formEntrySession.getContext(), diagnosisMetadata);
    FormSubmissionActions submissionActions = formEntrySession.getSubmissionActions();
    try {
        // we need to void any existing that isn't resubmitted
        Set<Integer> resubmittedObs = new HashSet<Integer>();
        List<Diagnosis> diagnoses = parseDiagnoses(submitted, existingDiagnosisObs);
        for (Diagnosis diagnosis : diagnoses) {
            if (diagnosis.getExistingObs() != null) {
                resubmittedObs.add(diagnosis.getExistingObs().getId());
            }
            Obs obsGroup = diagnosisMetadata.buildDiagnosisObsGroup(diagnosis);
            createObsGroup(submissionActions, obsGroup);
        }
        if (formEntrySession.getContext().getMode().equals(FormEntryContext.Mode.EDIT)) {
            // void any diagnosis that wasn't resubmitted
            Collection<Integer> obsToVoid = CollectionUtils.subtract(existingDiagnosisObs.keySet(), resubmittedObs);
            for (Integer obsId : obsToVoid) {
                submissionActions.modifyObs(existingDiagnosisObs.get(obsId), null, null, null, null, null);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (InvalidActionException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Obs(org.openmrs.Obs) InvalidActionException(org.openmrs.module.htmlformentry.InvalidActionException) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) IOException(java.io.IOException) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) FormSubmissionActions(org.openmrs.module.htmlformentry.FormSubmissionActions) HashSet(java.util.HashSet)

Example 7 with Diagnosis

use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.

the class DiagnosesFragmentController method codeDiagnosis.

public FragmentActionResult codeDiagnosis(UiUtils ui, @RequestParam("nonCodedObsId") Integer nonCodedObsId, // each string is json, like {"certainty":"PRESUMED","diagnosisOrder":"PRIMARY","diagnosis":"ConceptName:840"}
@RequestParam("diagnosis") List<String> diagnoses, @SpringBean("obsService") ObsService obsService, @SpringBean("emrDiagnosisService") DiagnosisService diagnosisService, @SpringBean("conceptService") ConceptService conceptService) throws Exception {
    if (nonCodedObsId != null) {
        Obs nonCodedObs = obsService.getObs(nonCodedObsId);
        if (nonCodedObs != null) {
            List<Diagnosis> diagnosisList = new ArrayList<Diagnosis>();
            for (String diagnosisJson : diagnoses) {
                ObjectMapper mapper = new ObjectMapper();
                JsonNode rootNode = mapper.readTree(diagnosisJson);
                Iterator<JsonNode> iterator = rootNode.iterator();
                while (iterator.hasNext()) {
                    JsonNode next = iterator.next();
                    Diagnosis diagnosis = parseDiagnosisJson(next.toString(), conceptService);
                    diagnosisList.add(diagnosis);
                }
            }
            List<Obs> newDiagnoses = diagnosisService.codeNonCodedDiagnosis(nonCodedObs, diagnosisList);
            if ((newDiagnoses != null) && (newDiagnoses.size() > 0)) {
                return new SuccessResult(ui.message("coreapps.dataManagement.codeDiagnosis.success"));
            }
        }
    }
    return new FailureResult(ui.message("coreapps.dataManagement.codeDiagnosis.failure"));
}
Also used : Obs(org.openmrs.Obs) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) ArrayList(java.util.ArrayList) SuccessResult(org.openmrs.ui.framework.fragment.action.SuccessResult) JsonNode(org.codehaus.jackson.JsonNode) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 8 with Diagnosis

use of org.openmrs.module.emrapi.diagnosis.Diagnosis 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);
        }
    }
}
Also used : PageAction(org.openmrs.ui.framework.page.PageAction) HashMap(java.util.HashMap) ConceptSource(org.openmrs.ConceptSource) ErrorWidget(org.openmrs.module.htmlformentry.widget.ErrorWidget) HiddenFieldWidget(org.openmrs.module.htmlformentry.widget.HiddenFieldWidget) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Example 9 with Diagnosis

use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesElement method parseDiagnoses.

private List<Diagnosis> parseDiagnoses(String jsonList, Map<Integer, Obs> existingDiagnosisObs) throws IOException {
    // low-priority: refactor this so that a Diagnosis can parse itself via jackson.
    // requires changing org.openmrs.module.emrapi.diagnosis.ConceptCodeDeserializer to also handle parse by id.
    List<Diagnosis> parsed = new ArrayList<Diagnosis>();
    JsonNode list = new ObjectMapper().readTree(jsonList);
    for (JsonNode node : list) {
        CodedOrFreeTextAnswer answer = new CodedOrFreeTextAnswer(node.get("diagnosis").getTextValue(), conceptService);
        Diagnosis.Order diagnosisOrder = Diagnosis.Order.valueOf(node.get("order").getTextValue());
        Diagnosis.Certainty certainty = Diagnosis.Certainty.valueOf(node.get("certainty").getTextValue());
        Obs existingObs = null;
        if (existingDiagnosisObs != null && node.path("existingObs").getNumberValue() != null) {
            existingObs = existingDiagnosisObs.get(node.get("existingObs").getNumberValue());
        }
        Diagnosis diagnosis = new Diagnosis(answer, diagnosisOrder);
        diagnosis.setCertainty(certainty);
        diagnosis.setExistingObs(existingObs);
        parsed.add(diagnosis);
    }
    return parsed;
}
Also used : Obs(org.openmrs.Obs) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 10 with Diagnosis

use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesElement method getPriorDiagnoses.

private List<Diagnosis> getPriorDiagnoses(FormEntryContext context, DispositionType dispositionType) {
    List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
    if (context.getVisit() != null) {
        VisitDomainWrapper visitDomainWrapper;
        if (context.getVisit() instanceof Visit) {
            visitDomainWrapper = adtService.wrap((Visit) context.getVisit());
        } else {
            visitDomainWrapper = (VisitDomainWrapper) context.getVisit();
        }
        diagnoses = visitDomainWrapper.getDiagnosesFromMostRecentDispositionByType(dispositionType);
    }
    return diagnoses;
}
Also used : Visit(org.openmrs.Visit) ArrayList(java.util.ArrayList) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper)

Aggregations

Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)16 ArrayList (java.util.ArrayList)8 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)8 Obs (org.openmrs.Obs)7 Test (org.junit.Test)5 List (java.util.List)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 JsonNode (org.codehaus.jackson.JsonNode)3 Concept (org.openmrs.Concept)3 TestUiUtils (org.openmrs.module.appui.TestUiUtils)3 DiagnosisMetadata (org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata)3 SimpleObject (org.openmrs.ui.framework.SimpleObject)3 HashMap (java.util.HashMap)2 ConceptName (org.openmrs.ConceptName)2 Patient (org.openmrs.Patient)2 FragmentModel (org.openmrs.ui.framework.fragment.FragmentModel)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1