Search in sources :

Example 1 with OrderService

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");
            }
        }
    }
}
Also used : OrderService(org.openmrs.api.OrderService)

Example 2 with OrderService

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;
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) APIException(org.openmrs.api.APIException) ObsService(org.openmrs.api.ObsService) OrderService(org.openmrs.api.OrderService) Date(java.util.Date)

Example 3 with OrderService

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);
    }
}
Also used : Order(org.openmrs.Order) CohortService(org.openmrs.api.CohortService) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService)

Example 4 with OrderService

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with OrderService

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

OrderService (org.openmrs.api.OrderService)8 Encounter (org.openmrs.Encounter)5 Order (org.openmrs.Order)5 Test (org.junit.Test)4 Patient (org.openmrs.Patient)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 Date (java.util.Date)3 EncounterService (org.openmrs.api.EncounterService)3 CareSetting (org.openmrs.CareSetting)2 Concept (org.openmrs.Concept)2 Obs (org.openmrs.Obs)2 TestOrder (org.openmrs.TestOrder)2 APIException (org.openmrs.api.APIException)2 ConceptService (org.openmrs.api.ConceptService)2 ObsService (org.openmrs.api.ObsService)2 EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)2 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 ArrayList (java.util.ArrayList)1