Search in sources :

Example 26 with OrderType

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

the class PihRadiologyOrdersMergeActions method beforeMergingPatients.

/**
 * This method will be called before calling the underlying OpenMRS
 * {@link org.openmrs.api.PatientService#mergePatients(org.openmrs.Patient, org.openmrs.Patient)} method, but in the
 * same transaction. Any thrown exception will cancel the merge
 *
 * @param preferred
 * @param notPreferred
 */
@Override
public void beforeMergingPatients(Patient preferred, Patient notPreferred) {
    if (config.isComponentEnabled(Components.RADIOLOGY)) {
        OrderType radiologyTestOrderType = radiologyProperties.getRadiologyTestOrderType();
        List<Order> orders = orderService.getAllOrdersByPatient(notPreferred);
        if (orders != null && orders.size() > 0) {
            this.unvoidOrders = new ArrayList<Integer>();
            for (Order order : orders) {
                if (order.getOrderType().equals(radiologyTestOrderType) && !order.isVoided()) {
                    // void Radiology orders so openmrs-core will allowed them to be merged
                    orderService.voidOrder(order, "pre-merge radiology orders");
                    this.unvoidOrders.add(order.getId());
                }
            }
        }
    }
}
Also used : Order(org.openmrs.Order) OrderType(org.openmrs.OrderType)

Example 27 with OrderType

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

the class OrderTypeBundle method orderType.

private static OrderType orderType(String name, String description, String uuid, String javaClassName, String parentUuid) {
    OrderType obj = new OrderType();
    obj.setName(name);
    obj.setDescription(description);
    obj.setUuid(uuid);
    obj.setJavaClassName(javaClassName);
    if (StringUtils.isNotBlank(parentUuid)) {
        obj.setParent(MetadataUtils.existing(OrderType.class, parentUuid));
    }
    return obj;
}
Also used : OrderType(org.openmrs.OrderType)

Example 28 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceImpl method getActiveOrders.

/**
 * @see org.openmrs.api.OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Override
@Transactional(readOnly = true)
public List<Order> getActiveOrders(Patient patient, OrderType orderType, CareSetting careSetting, Date asOfDate) {
    if (patient == null) {
        throw new IllegalArgumentException("Patient is required when fetching active orders");
    }
    if (asOfDate == null) {
        asOfDate = new Date();
    }
    List<OrderType> orderTypes = null;
    if (orderType != null) {
        orderTypes = new ArrayList<>();
        orderTypes.add(orderType);
        orderTypes.addAll(getSubtypes(orderType, true));
    }
    return dao.getActiveOrders(patient, orderTypes, careSetting, asOfDate);
}
Also used : OrderType(org.openmrs.OrderType) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderServiceImpl method getSubtypes.

/**
 * @see org.openmrs.api.OrderService#getSubtypes(org.openmrs.OrderType, boolean)
 */
@Override
@Transactional(readOnly = true)
public List<OrderType> getSubtypes(OrderType orderType, boolean includeRetired) {
    List<OrderType> allSubtypes = new ArrayList<>();
    List<OrderType> immediateAncestors = dao.getOrderSubtypes(orderType, includeRetired);
    while (!immediateAncestors.isEmpty()) {
        List<OrderType> ancestorsAtNextLevel = new ArrayList<>();
        for (OrderType type : immediateAncestors) {
            allSubtypes.add(type);
            ancestorsAtNextLevel.addAll(dao.getOrderSubtypes(type, includeRetired));
        }
        immediateAncestors = ancestorsAtNextLevel;
    }
    return allSubtypes;
}
Also used : OrderType(org.openmrs.OrderType) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder.

@Test
public void saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder() {
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setDrug(Context.getConceptService().getDrug(3));
    order.setDrugNonCoded("paracetemol drug non coded");
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors());
    assertEquals("DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet", errors.getFieldError("concept").getCode());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

OrderType (org.openmrs.OrderType)54 Test (org.junit.Test)46 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)45 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 BindException (org.springframework.validation.BindException)22 Errors (org.springframework.validation.Errors)22 Patient (org.openmrs.Patient)17 DrugOrder (org.openmrs.DrugOrder)16 CareSetting (org.openmrs.CareSetting)15 Encounter (org.openmrs.Encounter)11 GlobalProperty (org.openmrs.GlobalProperty)8 Order (org.openmrs.Order)8 TestOrder (org.openmrs.TestOrder)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)5 ConceptClass (org.openmrs.ConceptClass)5 HashSet (java.util.HashSet)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Criteria (org.hibernate.Criteria)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2