Search in sources :

Example 6 with ConceptSearchResult

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

Example 7 with ConceptSearchResult

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;
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Example 8 with ConceptSearchResult

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;
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleObject(org.openmrs.ui.framework.SimpleObject) Method(java.lang.reflect.Method) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ConceptSearchResult(org.openmrs.ConceptSearchResult) IOException(java.io.IOException)

Example 9 with ConceptSearchResult

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;
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ConceptSearchResult(org.openmrs.ConceptSearchResult) Method(java.lang.reflect.Method)

Example 10 with ConceptSearchResult

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;
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Aggregations

ConceptSearchResult (org.openmrs.ConceptSearchResult)16 Test (org.junit.Test)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)10 Locale (java.util.Locale)8 Concept (org.openmrs.Concept)8 ArrayList (java.util.ArrayList)5 SimpleObject (org.openmrs.ui.framework.SimpleObject)5 ConceptName (org.openmrs.ConceptName)4 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)4 Method (java.lang.reflect.Method)2 Ignore (org.junit.Ignore)2 ConceptClass (org.openmrs.ConceptClass)2 ConceptDatatype (org.openmrs.ConceptDatatype)2 ConceptSource (org.openmrs.ConceptSource)2 ConceptService (org.openmrs.api.ConceptService)2 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)2 IOException (java.io.IOException)1 ConceptDescription (org.openmrs.ConceptDescription)1 ConceptStopWord (org.openmrs.ConceptStopWord)1 DiagnosesFragmentController (org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController)1