Search in sources :

Example 16 with TestOrder

use of org.openmrs.TestOrder 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)

Example 17 with TestOrder

use of org.openmrs.TestOrder in project openmrs-module-mirebalais by PIH.

the class RadiologyOrderNumberGeneratorComponentTest method shouldGenerateStandardOrderNumber.

@Test
public void shouldGenerateStandardOrderNumber() {
    // new test order
    Order order = new TestOrder();
    order.setEncounter(encounterService.getEncounter(6));
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderType(orderService.getOrderType(2));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    OrderContext orderContext = new OrderContext();
    order = orderService.saveOrder(order, orderContext);
    // the GP "order.nextOrderNumberSeed" is set to 1 in the standard test dataset
    assertThat(order.getOrderNumber(), is("ORD-1"));
}
Also used : RadiologyOrder(org.openmrs.module.radiologyapp.RadiologyOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Date(java.util.Date) OrderContext(org.openmrs.api.OrderContext) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 18 with TestOrder

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

the class EncounterServiceTest method saveEncounter_shouldNotOverwriteObsAndOrdersCreatorOrDateCreated.

/**
 * Make sure the obs and order creator and dateCreated is preserved when passed into
 * {@link EncounterService#saveEncounter(Encounter)}
 *
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldNotOverwriteObsAndOrdersCreatorOrDateCreated() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    EncounterService encounterService = Context.getEncounterService();
    // the encounter to save without a dateCreated
    Encounter encounter = buildEncounter();
    // make sure we
    Date date = new Date(System.currentTimeMillis() - 5000);
    // have a date that isn't "right now"
    encounter.setDateCreated(date);
    User creator = new User(1);
    encounter.setCreator(creator);
    ConceptService cs = Context.getConceptService();
    // create and add an obs to this encounter
    Obs obs = new Obs(new Patient(2), cs.getConcept(1), new Date(), new Location(1));
    obs.setDateCreated(date);
    obs.setCreator(creator);
    obs.setValueNumeric(50d);
    encounter.addObs(obs);
    OrderService os = Context.getOrderService();
    // create and add an order to this encounter
    TestOrder order = new TestOrder();
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(new Patient(2));
    order.setDateActivated(new Date());
    order.setOrderType(os.getOrderType(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    Field field = Order.class.getDeclaredField("orderNumber");
    field.setAccessible(true);
    field.set(order, "ORD-1");
    order.setDateCreated(date);
    order.setCreator(creator);
    order.setCareSetting(os.getCareSetting(1));
    encounter.addOrder(order);
    // make sure the logged in user isn't the user we're testing with
    assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser());
    encounterService.saveEncounter(encounter);
    // make sure the obs date created and creator are the same as what we
    // set
    Obs createdObs = Context.getObsService().getObs(obs.getObsId());
    assertEquals(DateUtil.truncateToSeconds(date), createdObs.getDateCreated());
    assertEquals(creator, createdObs.getCreator());
    // make sure the order date created and creator are the same as what we
    // set
    Order createdOrder = os.getOrder(order.getOrderId());
    assertEquals(DateUtil.truncateToSeconds(date), createdOrder.getDateCreated());
    assertEquals(creator, createdOrder.getCreator());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Obs(org.openmrs.Obs) Field(java.lang.reflect.Field) User(org.openmrs.User) TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 19 with TestOrder

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

the class TestOrderValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if the specimen source is invalid
 * @should pass validation if the specimen source is valid
 */
@Override
public void validate(Object obj, Errors errors) {
    super.validate(obj, errors);
    TestOrder order = (TestOrder) obj;
    if (order == null) {
        errors.reject("error.general");
    } else {
        if (order.getSpecimenSource() != null) {
            List<Concept> specimenSources = Context.getOrderService().getTestSpecimenSources();
            if (!specimenSources.contains(order.getSpecimenSource())) {
                errors.rejectValue("specimenSource", "TestOrder.error.specimenSourceNotAmongAllowedConcepts");
            }
        }
    }
}
Also used : Concept(org.openmrs.Concept) TestOrder(org.openmrs.TestOrder)

Example 20 with TestOrder

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

the class OrderServiceTest method saveOrder_shouldSetOrderNumberSpecifiedInTheContextIfSpecified.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetOrderNumberSpecifiedInTheContextIfSpecified() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "orderEntry.OrderNumberGenerator");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Order order = new TestOrder();
    order.setEncounter(encounterService.getEncounter(6));
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderType(orderService.getOrderType(2));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    OrderContext orderCtxt = new OrderContext();
    final String expectedOrderNumber = "Testing";
    orderCtxt.setAttribute(TimestampOrderNumberGenerator.NEXT_ORDER_NUMBER, expectedOrderNumber);
    order = orderService.saveOrder(order, orderCtxt);
    assertEquals(expectedOrderNumber, order.getOrderNumber());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

TestOrder (org.openmrs.TestOrder)21 Test (org.junit.Test)19 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 OrderUtilTest (org.openmrs.order.OrderUtilTest)13 Date (java.util.Date)12 Order (org.openmrs.Order)12 DrugOrder (org.openmrs.DrugOrder)10 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)9 Concept (org.openmrs.Concept)9 Patient (org.openmrs.Patient)8 Encounter (org.openmrs.Encounter)6 CareSetting (org.openmrs.CareSetting)4 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Ignore (org.junit.Ignore)2 GlobalProperty (org.openmrs.GlobalProperty)2 OrderType (org.openmrs.OrderType)2 ConceptService (org.openmrs.api.ConceptService)2