use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), new ConceptMapType()));
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
// concept map type validator should have been called which should reject a null name
Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptMapType.name"));
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)));
drug.setName("name");
drug.setStrength("strength");
drug.setRetireReason("retireReason");
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
Assert.assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class ObsValidatorTest method validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch.
/**
* @see ObsValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch() {
Obs obs = new Obs();
obs.setPerson(new Person(7));
obs.setObsDatetime(new Date());
Concept questionConcept = new Concept(100);
ConceptDatatype dt = new ConceptDatatype(1);
dt.setUuid(ConceptDatatype.CODED_UUID);
questionConcept.setDatatype(dt);
obs.setConcept(questionConcept);
Concept answerConcept = new Concept(101);
obs.setValueCoded(answerConcept);
Drug drug = new Drug();
drug.setConcept(answerConcept);
obs.setValueDrug(drug);
Errors errors = new BindException(obs, "obs");
obsValidator.validate(obs, errors);
assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class ObsValidatorTest method validate_shouldRejectAnInvalidConceptAndDrugCombination.
/**
* @see ObsValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldRejectAnInvalidConceptAndDrugCombination() {
Obs obs = new Obs();
obs.setPerson(new Person(7));
obs.setObsDatetime(new Date());
Concept questionConcept = new Concept(100);
ConceptDatatype dt = new ConceptDatatype(1);
dt.setUuid(ConceptDatatype.CODED_UUID);
questionConcept.setDatatype(dt);
obs.setConcept(questionConcept);
obs.setValueCoded(new Concept(101));
Drug drug = new Drug();
drug.setConcept(new Concept(102));
obs.setValueDrug(drug);
Errors errors = new BindException(obs, "obs");
obsValidator.validate(obs, errors);
assertTrue(errors.hasFieldErrors("valueDrug"));
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugsByNameComparatorTest method compareDrugNamesIgnoringNumericals_shouldReturnNegativeIfNameForDrug1ComesBeforeThatOfDrug2.
/**
* @see DrugsByNameComparator#compareDrugNamesIgnoringNumericals(Drug,Drug)
*/
@Test
public void compareDrugNamesIgnoringNumericals_shouldReturnNegativeIfNameForDrug1ComesBeforeThatOfDrug2() {
Drug drug1 = new Drug();
drug1.setName("ABCD");
Drug drug2 = new Drug();
drug2.setName("BCDE");
DrugsByNameComparator dComparator = new DrugsByNameComparator();
int actualValue = dComparator.compare(drug1, drug2);
Assert.assertEquals(actualValue, -1);
}
Aggregations