use of org.openmrs.ConceptSearchResult 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.ConceptSearchResult in project openmrs-module-coreapps by openmrs.
the class DiagnosesFragmentController method searchNonCoded.
public List<SimpleObject> searchNonCoded(UiSessionContext context, UiUtils ui, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("emrConceptService") EmrConceptService emrConceptService, @RequestParam("term") String query, @RequestParam(value = "start", defaultValue = "0") Integer start, @RequestParam(value = "size", defaultValue = "50") Integer size) throws Exception {
Collection<Concept> diagnosisSets = emrApiProperties.getDiagnosisSets();
Locale locale = context.getLocale();
List<ConceptSource> sources = emrApiProperties.getConceptSourcesForDiagnosisSearch();
List<ConceptSearchResult> hits = emrConceptService.conceptSearch(query, locale, null, diagnosisSets, sources, null);
List<SimpleObject> ret = new ArrayList<SimpleObject>();
for (ConceptSearchResult hit : hits) {
ret.add(simplify(hit, ui, locale));
}
return ret;
}
use of org.openmrs.ConceptSearchResult in project openmrs-module-coreapps by openmrs.
the class CodedOrFreeTextAnswerListWidget method initialValueAsJson.
private String initialValueAsJson(List<CodedOrFreeTextAnswer> initialValue) {
if (initialValue == null || initialValue.size() == 0) {
return null;
}
// TODO large scale refactoring to have a proper REST-compatible representation of CodedOrFreeTextAnswer, and have diagnosis search use this
try {
// the controller is in the web layer, so we handle it in a very hacky way here.
Object controller = Context.loadClass("org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController").newInstance();
Method simplify = controller.getClass().getMethod("simplify", ConceptSearchResult.class, UiUtils.class, Locale.class);
List<Object> simplified = new ArrayList<Object>();
for (CodedOrFreeTextAnswer answer : initialValue) {
if (answer.getNonCodedAnswer() != null) {
simplified.add(SimpleObject.create("matchedName", answer.getNonCodedAnswer(), "nonCodedValue", answer.getNonCodedAnswer()));
} else {
ConceptSearchResult result = new ConceptSearchResult(null, answer.getCodedAnswer(), answer.getSpecificCodedAnswer());
simplified.add(simplify.invoke(controller, result, uiUtils, Context.getLocale()));
}
}
return uiUtils.toJson(simplified);
} catch (Exception ex) {
// In an API-layer unit test this will fail due to not being able to load the class
return null;
}
}
use of org.openmrs.ConceptSearchResult in project openmrs-module-coreapps by openmrs.
the class CodedOrFreeTextAnswerWidget method initialValueAsJson.
private String initialValueAsJson(CodedOrFreeTextAnswer initialValue) {
if (initialValue == null) {
return null;
}
ConceptSearchResult initial = new ConceptSearchResult(initialValue.getNonCodedAnswer(), initialValue.getCodedAnswer(), initialValue.getSpecificCodedAnswer());
if (initial.getConcept() == null) {
return uiUtils.toJson(SimpleObject.create("word", initial.getWord()));
}
try {
// the code we are calling is in the web layer, so we handle it in a very hacky way here.
Class<?> representationClass = Context.loadClass("org.openmrs.module.webservices.rest.web.representation.Representation");
Object defaultRepresentation = representationClass.getField("DEFAULT").get(null);
Class<?> conversionUtil = Context.loadClass("org.openmrs.module.webservices.rest.web.ConversionUtil");
Method convert = conversionUtil.getMethod("convertToRepresentation", Object.class, representationClass);
return uiUtils.toJson(convert.invoke(null, initial, defaultRepresentation));
} catch (Exception ex) {
// In an API-layer unit test this will fail due to not being able to load the class
return null;
}
}
use of org.openmrs.ConceptSearchResult in project openmrs-module-coreapps by openmrs.
the class DiagnosesFragmentController method search.
public List<SimpleObject> search(UiSessionContext context, UiUtils ui, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("emrConceptService") EmrConceptService emrConceptService, @RequestParam("term") String query, @RequestParam(value = "start", defaultValue = "0") Integer start, @RequestParam(value = "size", defaultValue = "50") Integer size) throws Exception {
Collection<Concept> diagnosisSets = emrApiProperties.getDiagnosisSets();
Locale locale = context.getLocale();
List<ConceptSource> sources = emrApiProperties.getConceptSourcesForDiagnosisSearch();
List<ConceptSearchResult> hits = emrConceptService.conceptSearch(query, locale, null, diagnosisSets, sources, null);
List<SimpleObject> ret = new ArrayList<SimpleObject>();
for (ConceptSearchResult hit : hits) {
ret.add(simplify(hit, ui, locale));
}
return ret;
}
Aggregations