use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesFragmentControllerTest method testController_createdProperPriorDiagnoses.
@Test
public void testController_createdProperPriorDiagnoses() throws Exception {
EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController();
ConceptName specificName = new ConceptName("Specific Name", Context.getLocale());
specificName.setId(1);
specificName.setLocalePreferred(true);
Concept conceptForSpecificName = new Concept();
conceptForSpecificName.setId(2);
conceptForSpecificName.addName(specificName);
Concept nonSpecificConcept = new Concept();
nonSpecificConcept.setId(3);
ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale());
nonSpecificConceptName.setId(4);
nonSpecificConceptName.setLocalePreferred(true);
nonSpecificConcept.addName(nonSpecificConceptName);
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY));
for (Diagnosis d : diagnoses) {
d.setExistingObs(new Obs());
}
FragmentModel model = new FragmentModel();
controller.controller(new TestUiUtils(), null, diagnoses, model);
assertThat(((List<String>) model.getAttribute("jsForExisting")).size(), is(0));
List<String> jsForPrior = (List<String>) model.getAttribute("jsForPrior");
assertThat(jsForPrior.get(0), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }"));
assertThat(jsForPrior.get(1), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }"));
assertThat(jsForPrior.get(2), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }"));
}
use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method testParsingDiagnoses.
@Test
public void testParsingDiagnoses() throws Exception {
encounter.addObs(diagnosisMetadata.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer("Random Disease"), Diagnosis.Order.PRIMARY)));
ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
assertThat(parsed.getDiagnoses().size(), is(1));
assertThat(parsed.getDispositions().size(), is(0));
assertThat(parsed.getObs().size(), is(0));
assertThat(path(parsed.getDiagnoses(), 0, "question"), is((Object) "coreapps.patientDashBoard.diagnosisQuestion.PRIMARY"));
assertThat(path(parsed.getDiagnoses(), 0, "answer"), is((Object) "(coreapps.Diagnosis.Certainty.PRESUMED) \"Random Disease\""));
assertThat(path(parsed.getDiagnoses(), 0, "order"), is((Object) 0));
}
use of org.openmrs.module.emrapi.diagnosis.Diagnosis 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;
}
use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.
the class DiagnosisWidgetFragmentController method controller.
public void controller(FragmentConfiguration config, @InjectBeans PatientDomainWrapper patientWrapper, @InjectBeans CoreAppsProperties properties) {
config.require("patient");
Object patient = config.get("patient");
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
config.addAttribute("patient", patientWrapper);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
int days = properties.getRecentDiagnosisPeriodInDays();
Calendar recent = Calendar.getInstance();
recent.set(Calendar.DATE, -days);
List<Diagnosis> recentDiagnoses = patientWrapper.getUniqueDiagnosesSince(recent.getTime());
config.addAttribute("recentDiagnoses", recentDiagnoses);
}
use of org.openmrs.module.emrapi.diagnosis.Diagnosis in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesElement method getExistingDiagnoses.
/**
* only visible for testing
* @param context
* @param diagnosisMetadata
* @return
*/
List<Diagnosis> getExistingDiagnoses(FormEntryContext context, DiagnosisMetadata diagnosisMetadata) {
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
Map<Integer, Obs> existing = getExistingDiagnosisObs(context, diagnosisMetadata);
if (existing != null) {
for (Obs group : existing.values()) {
diagnoses.add(diagnosisMetadata.toDiagnosis(group));
}
}
Collections.sort(diagnoses, new Comparator<Diagnosis>() {
@Override
public int compare(Diagnosis left, Diagnosis right) {
return left.getOrder().compareTo(right.getOrder());
}
});
return diagnoses;
}
Aggregations