use of org.openmrs.ConceptSource in project openmrs-core by openmrs.
the class ConceptServiceTest method getDrugByMapping_shouldReturnADrugThatMatchesTheCodeAndSourceAndTheBestMapType.
/**
* @see ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection
*/
@Test
public void getDrugByMapping_shouldReturnADrugThatMatchesTheCodeAndSourceAndTheBestMapType() {
executeDataSet(GET_DRUG_MAPPINGS);
final Integer expectedDrugId = 2;
final ConceptSource source = conceptService.getConceptSource(2);
final ConceptMapType mapTypeWithMatch = conceptService.getConceptMapType(1);
final ConceptMapType mapTypeWithNoMatch = conceptService.getConceptMapType(2);
List<ConceptMapType> conceptMapTypeList = new ArrayList<>();
conceptMapTypeList.add(mapTypeWithMatch);
conceptMapTypeList.add(mapTypeWithNoMatch);
Drug drug = conceptService.getDrugByMapping("WGT234", source, conceptMapTypeList);
assertEquals(expectedDrugId, drug.getDrugId());
// Lets switch the order is the map types in the list to make sure that
// if there is no match on the first map type, the logic matches on the second
// sanity check that actually there will be no match on the first map type in the list
conceptMapTypeList.clear();
conceptMapTypeList.add(mapTypeWithNoMatch);
assertNull(conceptService.getDrugByMapping("WGT234", source, conceptMapTypeList));
conceptMapTypeList.add(mapTypeWithMatch);
drug = conceptService.getDrugByMapping("WGT234", source, conceptMapTypeList);
assertEquals(expectedDrugId, drug.getDrugId());
}
use of org.openmrs.ConceptSource in project openmrs-core by openmrs.
the class ConceptServiceTest method getConceptReferenceTermByName_shouldReturnAConceptReferenceTermThatMatchesTheGivenNameFromTheGivenSource.
/**
* @see ConceptService#getConceptReferenceTermByName(String,ConceptSource)
*/
@Test
public void getConceptReferenceTermByName_shouldReturnAConceptReferenceTermThatMatchesTheGivenNameFromTheGivenSource() {
ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTermByName("weight term", new ConceptSource(1));
Assert.assertNotNull(term);
Assert.assertEquals("weight term", term.getName());
}
use of org.openmrs.ConceptSource in project openmrs-core by openmrs.
the class OpenmrsObjectSaveHandlerTest method handle_shouldTrimStringsWithoutAllowLeadingOrTrailingWhitespaceAnnotation.
/**
* @see OpenmrsObjectSaveHandler#handle(OpenmrsObject,User,Date,String)
*/
@Test
public void handle_shouldTrimStringsWithoutAllowLeadingOrTrailingWhitespaceAnnotation() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
term.setCode(" code ");
term.setConceptSource(new ConceptSource(1));
new OpenmrsObjectSaveHandler().handle(term, null, null, null);
Assert.assertEquals("code", term.getCode());
}
use of org.openmrs.ConceptSource in project openmrs-core by openmrs.
the class ConceptSourceValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
ConceptSource conceptSource = new ConceptSource();
conceptSource.setName(null);
conceptSource.setDescription("Some description");
Errors errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
conceptSource.setName("");
errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
conceptSource.setName(" ");
errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.ConceptSource in project openmrs-core by openmrs.
the class ConceptSourceValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptSource conceptSource = new ConceptSource();
conceptSource.setName(StringUtils.repeat("a", 51));
conceptSource.setDescription(StringUtils.repeat("a", 1025));
conceptSource.setHl7Code(StringUtils.repeat("a", 51));
conceptSource.setUniqueId(StringUtils.repeat("a", 251));
conceptSource.setRetireReason(StringUtils.repeat("a", 256));
Errors errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("hl7Code"));
Assert.assertTrue(errors.hasFieldErrors("uniqueId"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Aggregations