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