use of org.openmrs.api.OrderService in project openmrs-core by openmrs.
the class DrugOrderValidator method validateForRequireDrug.
private void validateForRequireDrug(Errors errors, DrugOrder order) {
// Reject if global property is set to specify a formulation for drug order
boolean requireDrug = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, false);
OrderService orderService = Context.getOrderService();
if (requireDrug) {
if (order.getConcept() != null && OpenmrsUtil.nullSafeEquals(orderService.getNonCodedDrugConcept(), order.getConcept())) {
if (order.getDrug() == null && !order.isNonCodedDrug()) {
errors.rejectValue("drugNonCoded", "DrugOrder.error.drugNonCodedIsRequired");
} else if (order.getDrug() != null) {
errors.rejectValue("concept", "DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet");
}
} else {
if (order.getDrug() == null && !order.isNonCodedDrug()) {
errors.rejectValue("drug", "DrugOrder.error.drugIsRequired");
} else if (order.getDrug() != null && order.isNonCodedDrug()) {
errors.rejectValue("concept", "DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet");
}
}
}
}
use of org.openmrs.api.OrderService in project openmrs-core by openmrs.
the class EncounterServiceImpl method voidEncounter.
/**
* @see org.openmrs.api.EncounterService#voidEncounter(org.openmrs.Encounter, java.lang.String)
*/
@Override
public Encounter voidEncounter(Encounter encounter, String reason) {
// if authenticated user is not supposed to edit encounter of certain type
if (!canEditEncounter(encounter, null)) {
throw new APIException("Encounter.error.privilege.required.void", new Object[] { encounter.getEncounterType().getEditPrivilege() });
}
if (reason == null) {
throw new IllegalArgumentException("The argument 'reason' is required and so cannot be null");
}
ObsService os = Context.getObsService();
for (Obs o : encounter.getObsAtTopLevel(false)) {
if (!o.getVoided()) {
os.voidObs(o, reason);
}
}
OrderService orderService = Context.getOrderService();
for (Order o : encounter.getOrders()) {
if (!o.getVoided()) {
orderService.voidOrder(o, reason);
}
}
encounter.setVoided(true);
encounter.setVoidedBy(Context.getAuthenticatedUser());
// unvoid handler to work
if (encounter.getDateVoided() == null) {
encounter.setDateVoided(new Date());
}
encounter.setVoidReason(reason);
Context.getEncounterService().saveEncounter(encounter);
return encounter;
}
use of org.openmrs.api.OrderService in project openmrs-core by openmrs.
the class PatientDataUnvoidHandler method handle.
@Override
public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) {
// can't be unvoiding a patient that doesn't exist in the database
if (patient.getId() != null) {
// unvoid all the encounter that got voided as a result of the patient getting voided
EncounterService es = Context.getEncounterService();
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
if (CollectionUtils.isNotEmpty(encounters)) {
for (Encounter encounter : encounters) {
if (encounter.getVoided() && encounter.getDateVoided().equals(origParentVoidedDate) && encounter.getVoidedBy().equals(originalVoidingUser)) {
es.unvoidEncounter(encounter);
}
}
}
// unvoid all the orders that got voided as a result of the patient getting voided
OrderService os = Context.getOrderService();
List<Order> orders = os.getAllOrdersByPatient(patient);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (order.getVoided() && order.getDateVoided().equals(origParentVoidedDate) && order.getVoidedBy().equals(originalVoidingUser)) {
os.unvoidOrder(order);
}
}
}
CohortService cs = Context.getCohortService();
cs.notifyPatientUnvoided(patient, originalVoidingUser, origParentVoidedDate);
}
}
use of org.openmrs.api.OrderService in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldFailValidationIfTheSpecimenSourceIsInvalid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfTheSpecimenSourceIsInvalid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(3);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, not(isIn(orderService.getDrugRoutes())));
TestOrder order = new TestOrder();
Patient patient = new Patient(8);
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(new Provider());
order.setCareSetting(new CareSetting());
Encounter encounter = new Encounter();
encounter.setPatient(patient);
order.setEncounter(encounter);
order.setDateActivated(new Date());
order.setSpecimenSource(specimenSource);
Errors errors = new BindException(order, "order");
new TestOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("specimenSource"));
Assert.assertEquals("TestOrder.error.specimenSourceNotAmongAllowedConcepts", errors.getFieldError("specimenSource").getCode());
}
use of org.openmrs.api.OrderService in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldPassValidationIfTheSpecimenSourceIsValid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfTheSpecimenSourceIsValid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(22);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, isIn(orderService.getDrugRoutes()));
TestOrder order = new TestOrder();
Patient patient = new Patient(8);
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(new CareSetting());
Encounter encounter = new Encounter();
encounter.setPatient(patient);
order.setEncounter(encounter);
order.setDateActivated(new Date());
order.setSpecimenSource(specimenSource);
Errors errors = new BindException(order, "order");
new TestOrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasFieldErrors());
}
Aggregations