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);
}
}
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"));
}
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);
}
}
}
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;
}
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;
}
Aggregations