public DrugOrderBuilder withDosingType(Class<? extends DosingInstructions> dosingType) { drugOrder.setDosingType(dosingType); return this; }
/** * @see DosingInstructions#setDosingInstructions(DrugOrder) */ @Override public void setDosingInstructions(DrugOrder order) { order.setDosingType(this.getClass()); order.setDosingInstructions(this.getInstructions()); }
@Test public void shouldAllowToSetCustomDosingTypes() { DrugOrder drugOrder = new DrugOrder(); assertEquals(SimpleDosingInstructions.class, drugOrder.getDosingType()); CustomDosingInstructions customDosingInstructions = new CustomDosingInstructions(); drugOrder.setDosingType(customDosingInstructions.getClass()); DosingInstructions dosingInstructionsObject = drugOrder.getDosingInstructionsInstance(); assertEquals(customDosingInstructions.getClass(), dosingInstructionsObject.getClass()); assertEquals(customDosingInstructions.getClass(), drugOrder.getDosingType()); }
/** * @see DosingInstructions#setDosingInstructions(DrugOrder) */ @Override public void setDosingInstructions(DrugOrder order) { order.setDosingType(this.getClass()); order.setDose(this.dose); order.setDoseUnits(this.doseUnits); order.setRoute(this.route); order.setFrequency(this.frequency); order.setDuration(this.duration); order.setDurationUnits(this.durationUnits); order.setAsNeeded(this.asNeeded); order.setAsNeededCondition(this.asNeededCondition); order.setDosingInstructions(this.administrationInstructions); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfRouteIsNullForSimpleDosingInstructionsDosingType() { DrugOrder order = new DrugOrder(); order.setDosingType(SimpleDosingInstructions.class); order.setRoute(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("route")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldNotValidateACustomDosingTypeAgainstAnyOtherDosingTypeValidation() { DrugOrder order = new DrugOrder(); order.setDosingType(CustomDosingInstructions.class); order.setDosingInstructions(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasFieldErrors("dosingInstructions")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() { DrugOrder order = new DrugOrder(); order.setDosingType(SimpleDosingInstructions.class); order.setDose(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dose")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDoseUnitsIsNullForSimpleDosingInstructionsDosingType() { DrugOrder order = new DrugOrder(); order.setDosingType(SimpleDosingInstructions.class); order.setDoseUnits(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("doseUnits")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfFrequencyIsNullForSimpleDosingInstructionsDosingType() { DrugOrder order = new DrugOrder(); order.setDosingType(SimpleDosingInstructions.class); order.setFrequency(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("frequency")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDosingInstructionsIsNullForFreeTextDosingInstructionsDosingType() { DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDosingInstructions(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dosingInstructions")); }
/** * @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, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDurationUnitsIsNullWhenDurationIsPresent() { DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDuration(20); order.setDurationUnits(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("durationUnits")); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfDoseUnitsIsNullWhenDoseIsPresent() { DrugOrder order = new DrugOrder(); order.setDosingType(FreeTextDosingInstructions.class); order.setDose(20.0); order.setDoseUnits(null); 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_shouldFailValidationIfDosingTypeIsNull() { DrugOrder order = new DrugOrder(); order.setDosingType(null); order.setDrug(Context.getConceptService().getDrug(3)); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("dosingType")); }
/** * @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,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 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()); }
/** * @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())); }
/** * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldNotRequireAllFieldsForADiscontinuationOrder() { DrugOrder orderToDiscontinue = (DrugOrder) Context.getOrderService().getOrder(111); assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null)); DrugOrder discontinuationOrder = new DrugOrder(); discontinuationOrder.setDosingType(null); discontinuationOrder.setCareSetting(orderToDiscontinue.getCareSetting()); discontinuationOrder.setConcept(orderToDiscontinue.getConcept()); discontinuationOrder.setAction(Order.Action.DISCONTINUE); discontinuationOrder.setPreviousOrder(orderToDiscontinue); discontinuationOrder.setPatient(orderToDiscontinue.getPatient()); discontinuationOrder.setDrug(orderToDiscontinue.getDrug()); discontinuationOrder.setOrderType(orderToDiscontinue.getOrderType()); discontinuationOrder.setOrderer(Context.getProviderService().getProvider(1)); discontinuationOrder.setEncounter(Context.getEncounterService().getEncounter(3)); Errors errors = new BindException(discontinuationOrder, "order"); new DrugOrderValidator().validate(discontinuationOrder, errors); Assert.assertFalse(errors.hasErrors()); }