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