use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug() {
DrugOrder order = new DrugOrder();
Drug drug = Context.getConceptService().getDrug(3);
drug.setConcept(null);
order.setDrug(drug);
Errors errors = new BindException(order, "order");
adminService.validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class ConceptServiceImpl method getDrugs.
/**
* @see org.openmrs.api.ConceptService#getDrugs(java.lang.String)
*/
@Override
@Transactional(readOnly = true)
public List<Drug> getDrugs(String phrase) {
List<Drug> drugs = new ArrayList<>();
// trying to treat search phrase as drug id
try {
Integer drugId = Integer.parseInt(phrase);
Drug targetDrug = Context.getConceptService().getDrug(drugId);
// if drug was found add it to result
if (targetDrug != null) {
drugs.add(targetDrug);
}
} catch (NumberFormatException e) {
// do nothing
}
// also try to treat search phrase as drug concept id
try {
Integer conceptId = Integer.parseInt(phrase);
Concept targetConcept = Context.getConceptService().getConcept(conceptId);
if (targetConcept != null) {
drugs.addAll(Context.getConceptService().getDrugsByConcept(targetConcept));
}
} catch (NumberFormatException e) {
// do nothing
}
drugs.addAll(dao.getDrugs(phrase));
return drugs;
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldInvokeConceptReferenceTermValidatorIfTermOnDrugReferenceMapIsNew.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldInvokeConceptReferenceTermValidatorIfTermOnDrugReferenceMapIsNew() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(new ConceptReferenceTerm(), null));
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
// reference term validator should have been called which should reject a null code
Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptReferenceTerm.code"));
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldFailIfTheDrugObjectIsNull.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfTheDrugObjectIsNull() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The parameter obj should not be null and must be of type" + Drug.class);
new DrugValidator().validate(null, new BindException(new Drug(), "drug"));
}
use of org.openmrs.Drug in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldFailIfConceptReferenceTermOnDrugReferenceMapIsNull.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfConceptReferenceTermOnDrugReferenceMapIsNull() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap());
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptReferenceTerm"));
}
Aggregations