use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldPassForAValidNewOrderFrequency.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidNewOrderFrequency() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConditionValidatorTest method shouldPassIfConditionClassIsPassedWithRequiredConditionProperties.
@Test
public void shouldPassIfConditionClassIsPassedWithRequiredConditionProperties() {
Condition condition = new Condition();
condition.setCondition(new CodedOrFreeText(new Concept(), new ConceptName("name", new Locale("en")), "nonCoded"));
condition.setClinicalStatus(ConditionClinicalStatus.ACTIVE);
validator.validate(condition, errors);
Assert.assertFalse(errors.hasFieldErrors("condition"));
Assert.assertFalse(errors.hasFieldErrors("clinicalStatus"));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept.
/**
* @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"));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept() {
DrugOrder order = new DrugOrder();
Drug drug = Context.getConceptService().getDrug(3);
Concept concept = Context.getConceptService().getConcept(792);
order.setDrug(drug);
// the actual concept which matches with drug is "88"
order.setConcept(concept);
Assert.assertNotEquals(drug.getConcept(), concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
Assert.assertTrue(errors.hasFieldErrors("drug"));
}
Aggregations