public DrugOrderBuilder withQuantity(Double quantity) { drugOrder.setQuantity(quantity); return this; }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfQuantityUnitsIsNullWhenQuantityIsPresent() { DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setQuantity(20.0); order.setQuantityUnits(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("quantityUnits")); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept() { Concept concept = Context.getConceptService().getConcept(3); assertThat(concept, not(isIn(Context.getOrderService().getDrugDispensingUnits()))); DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDuration(5); order.setDurationUnits(concept); order.setDose(1.0); order.setDoseUnits(concept); order.setQuantity(30.0); order.setQuantityUnits(concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("quantityUnits")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfQuantityIsNullForOutpatientCareSetting() { DrugOrder OutpatientOrder = new DrugOrder(); OutpatientOrder.setCareSetting(Context.getOrderService().getCareSetting(1)); OutpatientOrder.setQuantity(null); Errors OutpatientOrderErrors = new BindException(OutpatientOrder, "order"); new DrugOrderValidator().validate(OutpatientOrder, OutpatientOrderErrors); Assert.assertTrue(OutpatientOrderErrors.hasFieldErrors("quantity")); DrugOrder inPatientOrder = new DrugOrder(); inPatientOrder.setCareSetting(Context.getOrderService().getCareSetting(2)); inPatientOrder.setQuantity(null); Errors InpatientOrderErrors = new BindException(inPatientOrder, "order"); new DrugOrderValidator().validate(inPatientOrder, InpatientOrderErrors); Assert.assertFalse(InpatientOrderErrors.hasFieldErrors("quantity")); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept() { Concept concept = Context.getConceptService().getConcept(3); assertThat(concept, not(isIn(Context.getOrderService().getDrugDosingUnits()))); DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDuration(5); order.setDurationUnits(concept); order.setDose(1.0); order.setDoseUnits(concept); order.setQuantity(30.0); order.setQuantityUnits(concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("doseUnits")); }
/** * @see DrugOrderValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept() { Concept concept = Context.getConceptService().getConcept(3); assertThat(concept, not(isIn(Context.getOrderService().getDurationUnits()))); DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDuration(5); order.setDurationUnits(concept); order.setDose(1.0); order.setDoseUnits(concept); order.setQuantity(30.0); order.setQuantityUnits(concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("durationUnits")); }
/** * @see org.openmrs.Order#copyHelper(Order) */ protected DrugOrder copyHelper(DrugOrder target) { super.copyHelper(target); target.setDose(getDose()); target.setDoseUnits(getDoseUnits()); target.setFrequency(getFrequency()); target.setAsNeeded(getAsNeeded()); target.setAsNeededCondition(getAsNeededCondition()); target.setQuantity(getQuantity()); target.setQuantityUnits(getQuantityUnits()); target.setDrug(getDrug()); target.setDosingType(getDosingType()); target.setDosingInstructions(getDosingInstructions()); target.setDuration(getDuration()); target.setDurationUnits(getDurationUnits()); target.setNumRefills(getNumRefills()); target.setRoute(getRoute()); target.setBrandName(getBrandName()); target.setDispenseAsWritten(getDispenseAsWritten()); target.setDrugNonCoded(getDrugNonCoded()); return target; }
/** * @see Order#cloneForRevisionHelper(Order) */ protected DrugOrder cloneForRevisionHelper(DrugOrder target) { super.cloneForRevisionHelper(target); target.setDose(getDose()); target.setDoseUnits(getDoseUnits()); target.setFrequency(getFrequency()); target.setAsNeeded(getAsNeeded()); target.setAsNeededCondition(getAsNeededCondition()); target.setQuantity(getQuantity()); target.setQuantityUnits(getQuantityUnits()); target.setDrug(getDrug()); target.setDosingType(getDosingType()); target.setDosingInstructions(getDosingInstructions()); target.setDuration(getDuration()); target.setDurationUnits(getDurationUnits()); target.setRoute(getRoute()); target.setNumRefills(getNumRefills()); target.setBrandName(getBrandName()); target.setDispenseAsWritten(getDispenseAsWritten()); target.setDrugNonCoded(getDrugNonCoded()); return target; }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfRouteIsNotAValidConcept() { Concept concept = Context.getConceptService().getConcept(3); assertThat(concept, not(isIn(Context.getOrderService().getDrugRoutes()))); DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDuration(5); order.setDurationUnits(concept); order.setDose(1.0); order.setDoseUnits(concept); order.setQuantity(30.0); order.setQuantityUnits(concept); order.setRoute(concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("route")); Assert.assertEquals("DrugOrder.error.routeNotAmongAllowedConcepts", errors.getFieldError("route").getCode()); }
order.setDrug(Context.getConceptService().getDrug(3)); order.setCareSetting(Context.getOrderService().getCareSetting(1)); order.setQuantity(2.00); order.setQuantityUnits(Context.getConceptService().getConcept(51)); order.setNumRefills(10);
order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 10 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2);
order.setDrug(Context.getConceptService().getDrug(3)); order.setCareSetting(Context.getOrderService().getCareSetting(1)); order.setQuantity(2.00); order.setQuantityUnits(Context.getConceptService().getConcept(51)); order.setNumRefills(10);
order.setDose(300.0); order.setDoseUnits(conceptService.getConcept(50)); order.setQuantity(20.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setFrequency(orderService.getOrderFrequency(3000));
order.setDrug(Context.getConceptService().getDrug(3)); order.setCareSetting(Context.getOrderService().getCareSetting(1)); order.setQuantity(2.00); order.setQuantityUnits(Context.getConceptService().getConcept(51)); order.setNumRefills(10);
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldThrowAmbiguousOrderExceptionIfAnActiveDrugOrderForTheSameDrugFormulationExists() { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml"); final Patient patient = patientService.getPatient(2); //sanity check that we have an active order for the same concept DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000); assertTrue(existingOrder.isActive()); //New Drug order DrugOrder order = new DrugOrder(); order.setPatient(patient); order.setDrug(existingOrder.getDrug()); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(existingOrder.getCareSetting()); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 5 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2); expectedException.expect(AmbiguousOrderException.class); expectedException.expectMessage("Order.cannot.have.more.than.one"); orderService.saveOrder(order, null); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext) */ @Test public void saveOrder_shouldPassIfAnActiveDrugOrderForTheSameConceptAndCareSettingButDifferentFormulationExists() { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml"); final Patient patient = patientService.getPatient(2); //sanity check that we have an active order DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000); assertTrue(existingOrder.isActive()); //New Drug order DrugOrder order = new DrugOrder(); order.setPatient(patient); order.setConcept(existingOrder.getConcept()); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(existingOrder.getCareSetting()); order.setDrug(conceptService.getDrug(3001)); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 5 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2); Order savedDrugOrder = orderService.saveOrder(order, null); assertNotNull(orderService.getOrder(savedDrugOrder.getOrderId())); }
/** * @see OrderService#saveOrder(org.openmrs.Order, OrderContext, org.openmrs.Order[]) */ @Test public void saveOrder_shouldPassIfAnKnownDrugOrderForTheSameDrugFormulationSpecified() { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml"); final Patient patient = patientService.getPatient(2); //sanity check that we have an active order for the same concept DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000); assertTrue(existingOrder.isActive()); //New Drug order DrugOrder order = new DrugOrder(); order.setPatient(patient); order.setDrug(existingOrder.getDrug()); order.setEncounter(encounterService.getEncounter(6)); order.setOrderer(providerService.getProvider(1)); order.setCareSetting(existingOrder.getCareSetting()); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions("2 for 5 days"); order.setQuantity(10.0); order.setQuantityUnits(conceptService.getConcept(51)); order.setNumRefills(2); OrderContext orderContext = new OrderContext(); orderContext.setAttribute(OrderService.PARALLEL_ORDERS, new String[] { existingOrder.getUuid() }); orderService.saveOrder(order, orderContext); assertNotNull(orderService.getOrder(order.getOrderId())); }
order.setRoute(orderToDiscontinue.getRoute()); order.setFrequency(orderToDiscontinue.getFrequency()); order.setQuantity(orderToDiscontinue.getQuantity()); order.setQuantityUnits(orderToDiscontinue.getQuantityUnits()); order.setNumRefills(orderToDiscontinue.getNumRefills());
drugOrder.setRoute(duplicateOrder.getRoute()); drugOrder.setFrequency(duplicateOrder.getFrequency()); drugOrder.setQuantity(duplicateOrder.getQuantity()); drugOrder.setQuantityUnits(duplicateOrder.getQuantityUnits()); drugOrder.setNumRefills(duplicateOrder.getNumRefills());
@Test public void saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet() throws ParseException { executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrderAutoExpireDate.xml"); Drug drug = conceptService.getDrug(3000); 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.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(0); drugOrder.setOrderType(null); drugOrder.setDateActivated(TestUtil.createDateTime("2014-08-03")); drugOrder.setDuration(20);// 20 days drugOrder.setDurationUnits(conceptService.getConcept(1001)); Order savedOrder = orderService.saveOrder(drugOrder, null); Order loadedOrder = orderService.getOrder(savedOrder.getId()); Assert.assertEquals(TestUtil.createDateTime("2014-08-22 23:59:59"), loadedOrder.getAutoExpireDate()); }