Search in sources :

Example 56 with Encounter

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

the class OrderServiceTest method discontinueOrder_shouldSetCorrectAttributesOnTheDiscontinueAndDiscontinuedOrders.

/**
 * @see OrderService#discontinueOrder(org.openmrs.Order, org.openmrs.Concept, java.util.Date,
 *      org.openmrs.Provider, org.openmrs.Encounter)
 */
@Test
public void discontinueOrder_shouldSetCorrectAttributesOnTheDiscontinueAndDiscontinuedOrders() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueReason.xml");
    Order order = orderService.getOrderByOrderNumber("111");
    Encounter encounter = encounterService.getEncounter(3);
    Provider orderer = providerService.getProvider(1);
    Date discontinueDate = new Date();
    Concept concept = Context.getConceptService().getConcept(1);
    Order discontinueOrder = orderService.discontinueOrder(order, concept, discontinueDate, orderer, encounter);
    Assert.assertEquals(order.getDateStopped(), discontinueDate);
    Assert.assertNotNull(discontinueOrder);
    Assert.assertNotNull(discontinueOrder.getId());
    Assert.assertEquals(discontinueOrder.getDateActivated(), discontinueOrder.getAutoExpireDate());
    Assert.assertEquals(discontinueOrder.getAction(), Action.DISCONTINUE);
    Assert.assertEquals(discontinueOrder.getOrderReason(), concept);
    Assert.assertEquals(discontinueOrder.getPreviousOrder(), order);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) Encounter(org.openmrs.Encounter) Date(java.util.Date) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 57 with Encounter

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

the class OrderServiceTest method saveOrder_shouldSetOrderTypeOfDrugOrderToDrugOrderIfNotSetAndConceptNotMapped.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderTypeOfDrugOrderToDrugOrderIfNotSetAndConceptNotMapped() {
    Drug drug = conceptService.getDrug(2);
    Concept unmappedConcept = conceptService.getConcept(113);
    Assert.assertNull(orderService.getOrderTypeByConcept(unmappedConcept));
    drug.setConcept(unmappedConcept);
    DrugOrder drugOrder = new DrugOrder();
    Encounter encounter = encounterService.getEncounter(3);
    drugOrder.setEncounter(encounter);
    drugOrder.setPatient(patientService.getPatient(7));
    drugOrder.setCareSetting(orderService.getCareSetting(1));
    drugOrder.setOrderer(Context.getProviderService().getProvider(1));
    drugOrder.setDateActivated(encounter.getEncounterDatetime());
    drugOrder.setDrug(drug);
    drugOrder.setDosingType(SimpleDosingInstructions.class);
    drugOrder.setDose(300.0);
    drugOrder.setDoseUnits(conceptService.getConcept(50));
    drugOrder.setQuantity(20.0);
    drugOrder.setQuantityUnits(conceptService.getConcept(51));
    drugOrder.setFrequency(orderService.getOrderFrequency(3));
    drugOrder.setRoute(conceptService.getConcept(22));
    drugOrder.setNumRefills(10);
    drugOrder.setOrderType(null);
    orderService.saveOrder(drugOrder, null);
    Assert.assertNotNull(drugOrder.getOrderType());
    Assert.assertEquals(orderService.getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID), drugOrder.getOrderType());
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 58 with Encounter

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

the class OrderValidator method validateDateActivated.

private void validateDateActivated(Order order, Errors errors) {
    Date dateActivated = order.getDateActivated();
    if (dateActivated != null) {
        if (dateActivated.after(new Date())) {
            errors.rejectValue("dateActivated", "Order.error.dateActivatedInFuture");
            return;
        }
        Date dateStopped = order.getDateStopped();
        if (dateStopped != null && dateActivated.after(dateStopped)) {
            errors.rejectValue("dateActivated", "Order.error.dateActivatedAfterDiscontinuedDate");
            errors.rejectValue("dateStopped", "Order.error.dateActivatedAfterDiscontinuedDate");
        }
        Date autoExpireDate = order.getAutoExpireDate();
        if (autoExpireDate != null && dateActivated.after(autoExpireDate)) {
            errors.rejectValue("dateActivated", "Order.error.dateActivatedAfterAutoExpireDate");
            errors.rejectValue("autoExpireDate", "Order.error.dateActivatedAfterAutoExpireDate");
        }
        Encounter encounter = order.getEncounter();
        if (encounter != null && encounter.getEncounterDatetime() != null && encounter.getEncounterDatetime().after(dateActivated)) {
            errors.rejectValue("dateActivated", "Order.error.encounterDatetimeAfterDateActivated");
        }
    }
}
Also used : Encounter(org.openmrs.Encounter) Date(java.util.Date)

Example 59 with Encounter

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

the class EncounterValidator method validate.

/**
 * Validates the given Encounter. Currently checks if the patient has been set and also ensures
 * that the patient for an encounter and the visit it is associated to if any, are the same.
 *
 * @param obj The encounter to validate.
 * @param errors Errors
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail if the patients for the visit and the encounter dont match
 * @should fail if patient is not set
 * @should fail if encounter type is not set
 * @should fail if encounter dateTime is not set
 * @should fail if encounter dateTime is after current dateTime
 * @should fail if encounter dateTime is before visit startDateTime
 * @should fail if encounter dateTime is after visit stopDateTime
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) throws APIException {
    if (log.isDebugEnabled()) {
        log.debug(this.getClass().getName() + ".validate...");
    }
    if (obj == null || !(obj instanceof Encounter)) {
        throw new IllegalArgumentException("The parameter obj should not be null and must be of type " + Encounter.class);
    }
    Encounter encounter = (Encounter) obj;
    ValidationUtils.rejectIfEmpty(errors, "encounterType", "Encounter.error.encounterType.required", "Encounter type is Required");
    ValidationUtils.rejectIfEmpty(errors, "patient", "Encounter.error.patient.required", "Patient is required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "encounterDatetime", "Encounter.datetime.required");
    if (encounter.getVisit() != null && !ObjectUtils.equals(encounter.getVisit().getPatient(), encounter.getPatient())) {
        errors.rejectValue("visit", "Encounter.visit.patients.dontMatch", "The patient for the encounter and visit should be the same");
    }
    Date encounterDateTime = encounter.getEncounterDatetime();
    if (encounterDateTime != null && encounterDateTime.after(new Date())) {
        errors.rejectValue("encounterDatetime", "Encounter.datetimeShouldBeBeforeCurrent", "The encounter datetime should be before the current date.");
    }
    Visit visit = encounter.getVisit();
    if (visit != null && encounterDateTime != null) {
        if (visit.getStartDatetime() != null && encounterDateTime.before(visit.getStartDatetime())) {
            errors.rejectValue("encounterDatetime", "Encounter.datetimeShouldBeInVisitDatesRange", "The encounter datetime should be between the visit start and stop dates.");
        }
        if (visit.getStopDatetime() != null && encounterDateTime.after(visit.getStopDatetime())) {
            errors.rejectValue("encounterDatetime", "Encounter.datetimeShouldBeInVisitDatesRange", "The encounter datetime should be between the visit start and stop dates.");
        }
    }
    ValidateUtil.validateFieldLengths(errors, obj.getClass(), "voidReason");
}
Also used : Visit(org.openmrs.Visit) Encounter(org.openmrs.Encounter) Date(java.util.Date)

Example 60 with Encounter

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

the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime() {
    Date encounterDate = new Date();
    Date orderDate = DateUtils.addDays(encounterDate, -1);
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    encounter.setEncounterDatetime(encounterDate);
    Order order = new Order();
    order.setDateActivated(orderDate);
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setEncounter(encounter);
    order.setOrderer(Context.getProviderService().getProvider(1));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19