Search in sources :

Example 26 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject 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 27 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseObservations.

public ParsedObs parseObservations(Locale locale) {
    DiagnosisMetadata diagnosisMetadata = emrApiProperties.getDiagnosisMetadata();
    DispositionDescriptor dispositionDescriptor = null;
    try {
        dispositionDescriptor = dispositionService.getDispositionDescriptor();
    } catch (IllegalStateException ex) {
    // No problem. We do not require dispositions to be configured here
    }
    ParsedObs parsedObs = new ParsedObs();
    for (Obs obs : encounter.getObsAtTopLevel(false)) {
        if (diagnosisMetadata.isDiagnosis(obs)) {
            parsedObs.getDiagnoses().add(parseDiagnosis(diagnosisMetadata, obs));
        } else if (dispositionDescriptor != null && dispositionDescriptor.isDisposition(obs)) {
            parsedObs.getDispositions().add(parseDisposition(dispositionDescriptor, obs, locale));
        } else {
            parsedObs.getObs().add(parseObs(obs, locale));
        }
    }
    // just sort the obs by obsId--not perfect, but a decent "natural" object
    Collections.sort(parsedObs.getObs(), new Comparator<SimpleObject>() {

        @Override
        public int compare(SimpleObject o1, SimpleObject o2) {
            return (Integer) o1.get("obsId") < (Integer) o2.get("obsId") ? -1 : 1;
        }
    });
    Collections.sort(parsedObs.getDiagnoses(), new Comparator<SimpleObject>() {

        @Override
        public int compare(SimpleObject o1, SimpleObject o2) {
            Integer order1 = (Integer) o1.get("order");
            Integer order2 = (Integer) o2.get("order");
            return order1 - order2;
        }
    });
    return parsedObs;
}
Also used : Obs(org.openmrs.Obs) SimpleObject(org.openmrs.ui.framework.SimpleObject) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor)

Example 28 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseObsWithLocationAnswer.

private SimpleObject parseObsWithLocationAnswer(Obs obs, Location location) {
    SimpleObject simpleObject = SimpleObject.create("obsId", obs.getObsId());
    simpleObject.put("question", capitalizeString(uiUtils.format(obs.getConcept())));
    simpleObject.put("answer", uiUtils.format(location));
    return simpleObject;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject)

Example 29 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseDisposition.

private SimpleObject parseDisposition(DispositionDescriptor dispositionDescriptor, Obs obs, Locale locale) {
    Obs dispositionObs = dispositionDescriptor.getDispositionObs(obs);
    Obs admissionLocationObs = dispositionDescriptor.getAdmissionLocationObs(obs);
    Obs internalTransferLocationObs = dispositionDescriptor.getInternalTransferLocationObs(obs);
    Obs dateOfDeathObs = dispositionDescriptor.getDateOfDeathObs(obs);
    List<Obs> additionalObs = dispositionDescriptor.getAdditionalObs(obs);
    SimpleObject simpleObject = SimpleObject.create("obsId", obs.getObsId());
    simpleObject.put("disposition", dispositionObs.getValueAsString(locale));
    List<SimpleObject> simplifiedAdditionalObs = new ArrayList<SimpleObject>();
    if (admissionLocationObs != null) {
        simplifiedAdditionalObs.add(parseObsWithLocationAnswer(admissionLocationObs, dispositionDescriptor.getAdmissionLocation(obs, locationService)));
    }
    if (internalTransferLocationObs != null) {
        simplifiedAdditionalObs.add(parseObsWithLocationAnswer(internalTransferLocationObs, dispositionDescriptor.getInternalTransferLocation(obs, locationService)));
    }
    if (dateOfDeathObs != null) {
        simplifiedAdditionalObs.add(parseObs(dateOfDeathObs, locale));
    }
    for (Obs additional : additionalObs) {
        simplifiedAdditionalObs.add(parseObs(additional, locale));
    }
    simpleObject.put("additionalObs", simplifiedAdditionalObs);
    return simpleObject;
}
Also used : Obs(org.openmrs.Obs) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList)

Example 30 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseOrders.

public List<SimpleObject> parseOrders() {
    List<SimpleObject> orders = new ArrayList<SimpleObject>();
    // hacky reflection to allow core 1.9 compatibility, which doesn't support order.orderNumber
    Method getOrderNumber = null;
    for (Method m : new Order().getClass().getMethods()) {
        if (m.getName().equals("getOrderNumber")) {
            getOrderNumber = m;
            break;
        }
    }
    for (Order order : encounter.getOrders()) {
        try {
            orders.add(SimpleObject.create("concept", uiUtils.format(order.getConcept()), "orderNumber", // prior to 1.10 we display accession number, 1.10+ we display order number
            uiUtils.format(getOrderNumber != null ? getOrderNumber.invoke(order) : order.getAccessionNumber())));
        }// fail softly for now
         catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        }
    }
    return orders;
}
Also used : Order(org.openmrs.Order) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3