Search in sources :

Example 16 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class MockConcepts method finding.

private Concept finding(String name, ConceptDatatype datatype, ConceptSource source, String mapping) {
    Concept concept = baseConcept(name);
    concept.setDatatype(datatype);
    concept.setConceptClass(finding);
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(source, mapping).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)

Example 17 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class DrugOrdersPageController method get.

public void get(PageModel model, UiUtils ui, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(required = false, value = "patient") Patient patient, @RequestParam(required = false, value = "hivemrId") String hivemrId, @SpringBean("conceptService") ConceptService conceptService, @SpringBean("patientService") PatientService patientService, @SpringBean("orderService") OrderService orderService, @SpringBean("obsService") ObsService obsService) throws IOException {
    if (patient == null) {
        PatientIdentifierType hivemrV1 = patientService.getPatientIdentifierTypeByUuid(ZlConfigConstants.PATIENTIDENTIFIERTYPE_HIVEMRV1_UUID);
        List<PatientIdentifier> idList = patientService.getPatientIdentifiers(hivemrId, Arrays.asList(hivemrV1), null, null, null);
        if (idList.isEmpty()) {
            throw new IllegalArgumentException("No patients found with identifier: " + hivemrId);
        }
        if (idList.size() > 1) {
            throw new IllegalArgumentException(idList.size() + " patients found with identifier: " + hivemrId);
        }
        patient = idList.get(0).getPatient();
    }
    // Get all of the drug orders for the patient
    List<DrugOrder> drugOrders = new ArrayList<>();
    for (Order order : orderService.getAllOrdersByPatient(patient)) {
        order = HibernateUtil.getRealObjectFromProxy(order);
        if (order instanceof DrugOrder && BooleanUtils.isNotTrue(order.getVoided())) {
            DrugOrder drugOrder = (DrugOrder) order;
            drugOrders.add(drugOrder);
        }
    }
    // Sort these drug orders in chronological order
    Collections.sort(drugOrders, (d1, d2) -> {
        // Get all of the previous orders for d1.  If any are d2, then d1 is later
        for (Order d1Prev = d1.getPreviousOrder(); d1Prev != null; d1Prev = d1Prev.getPreviousOrder()) {
            if (d1Prev.equals(d2)) {
                return 1;
            }
        }
        // Get all of the previous orders for d2.  If any are d1, then d2 is later
        for (Order d2Prev = d2.getPreviousOrder(); d2Prev != null; d2Prev = d2Prev.getPreviousOrder()) {
            if (d2Prev.equals(d1)) {
                return -1;
            }
        }
        // If neither is a revision of the other, then compare based on effective start date
        int dateCompare = d1.getEffectiveStartDate().compareTo(d2.getEffectiveStartDate());
        if (dateCompare != 0) {
            return dateCompare;
        }
        // If they are still the same, then order based on end date
        int ret = OpenmrsUtil.compareWithNullAsLatest(d1.getEffectiveStopDate(), d2.getEffectiveStopDate());
        if (ret == 0) {
            // Finally, order based on orderId
            ret = d1.getOrderId().compareTo(d2.getOrderId());
        }
        return ret;
    });
    /*
            TODO: For now we will organize these by order reason, as this is the way they are being migrated in
            from the HIV EMR.  Once we have established concept sets for organizing orderables by areas we can adjust
            to organize in that way.  We'll keep our model generic (based on string category names) to allow for this
            We also remove the discontinue orders and associate them back with the orders they discontinue in a map so that
            we can organize them together in a single row.
         */
    List<Concept> categories = new ArrayList<>();
    // HIV
    categories.add(conceptService.getConceptByUuid("138405AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    // TB
    categories.add(conceptService.getConceptByUuid("3ccca7cc-26fe-102b-80cb-0017a47871b2"));
    // PTME
    categories.add(conceptService.getConceptByUuid("160538AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    // Prophylaxis
    categories.add(conceptService.getConceptByUuid("1691AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    List<DrugOrder> activeOrders = new ArrayList<>();
    List<DrugOrder> completedOrders = new ArrayList<>();
    Map<String, List<DrugOrder>> activeOrdersByCategory = new LinkedHashMap<>();
    Map<String, List<DrugOrder>> completedOrdersByCategory = new LinkedHashMap<>();
    Map<DrugOrder, DrugOrder> ordersToDiscontinueOrders = new HashMap<>();
    for (Concept category : categories) {
        activeOrdersByCategory.put(category.getDisplayString(), new ArrayList<>());
        completedOrdersByCategory.put(category.getDisplayString(), new ArrayList<>());
    }
    activeOrdersByCategory.put("", new ArrayList<>());
    completedOrdersByCategory.put("", new ArrayList<>());
    for (DrugOrder d : drugOrders) {
        if (d.getAction() == Order.Action.DISCONTINUE) {
            ordersToDiscontinueOrders.put((DrugOrder) d.getPreviousOrder(), d);
        } else {
            String category = "";
            if (d.getOrderReason() != null && categories.contains(d.getOrderReason())) {
                category = d.getOrderReason().getDisplayString();
            }
            if (d.isActive()) {
                activeOrders.add(d);
                activeOrdersByCategory.get(category).add(d);
            } else {
                completedOrders.add(d);
                completedOrdersByCategory.get(category).add(d);
            }
        }
    }
    // In the legacy HIV EMR, we supported entering notes/comments about a patient's medications.  Include those here.
    Concept medicationComments = conceptService.getConceptByMapping("10637", "PIH");
    List<Obs> medicationCommentObs = obsService.getObservationsByPersonAndConcept(patient, medicationComments);
    medicationCommentObs.sort((obs, t1) -> t1.getObsDatetime().compareTo(obs.getObsDatetime()));
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("drugOrders", drugOrders);
    model.addAttribute("categories", categories);
    model.addAttribute("activeOrders", activeOrders);
    model.addAttribute("completedOrders", completedOrders);
    model.addAttribute("activeOrdersByCategory", activeOrdersByCategory);
    model.addAttribute("completedOrdersByCategory", completedOrdersByCategory);
    model.addAttribute("ordersToDiscontinueOrders", ordersToDiscontinueOrders);
    model.addAttribute("medicationCommentObs", medicationCommentObs);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) PatientIdentifier(org.openmrs.PatientIdentifier) LinkedHashMap(java.util.LinkedHashMap) DrugOrder(org.openmrs.DrugOrder) ArrayList(java.util.ArrayList) List(java.util.List) PatientIdentifierType(org.openmrs.PatientIdentifierType)

Example 18 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class ConceptsFromMetadataSharing method diagnosis.

private Concept diagnosis(String name, ConceptSource source, String mapping) {
    Concept concept = diagnosis(name);
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(source, mapping).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)

Example 19 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class ConceptsFromMetadataSharing method question.

private Concept question(String name, ConceptDatatype datatype, ConceptSource source, String mapping) {
    Concept concept = baseConcept(name);
    concept.setDatatype(datatype);
    concept.setConceptClass(question);
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(source, mapping).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)

Example 20 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class ConceptsFromMetadataSharing method finding.

private Concept finding(String name, ConceptDatatype datatype, ConceptSource source, String mapping) {
    Concept concept = baseConcept(name);
    concept.setDatatype(datatype);
    concept.setConceptClass(finding);
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(source, mapping).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19