Search in sources :

Example 21 with ConceptSource

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());
}
Also used : Drug(org.openmrs.Drug) ConceptMapType(org.openmrs.ConceptMapType) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 22 with ConceptSource

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());
}
Also used : ConceptSource(org.openmrs.ConceptSource) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 23 with ConceptSource

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());
}
Also used : ConceptSource(org.openmrs.ConceptSource) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test)

Example 24 with ConceptSource

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with ConceptSource

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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptSource (org.openmrs.ConceptSource)39 Test (org.junit.Test)29 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)28 ConceptMapType (org.openmrs.ConceptMapType)6 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)6 BindException (org.springframework.validation.BindException)6 Errors (org.springframework.validation.Errors)6 Drug (org.openmrs.Drug)5 ArrayList (java.util.ArrayList)4 Concept (org.openmrs.Concept)4 Locale (java.util.Locale)3 Criteria (org.hibernate.Criteria)3 ConceptClass (org.openmrs.ConceptClass)2 ConceptDatatype (org.openmrs.ConceptDatatype)2 ConceptSearchResult (org.openmrs.ConceptSearchResult)2 GlobalProperty (org.openmrs.GlobalProperty)2 User (org.openmrs.User)2 ConceptBuilder (org.openmrs.module.metadatadeploy.builder.ConceptBuilder)2 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2