Search in sources :

Example 81 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.

the class PersonSearchQueryTest method shouldAddPersonLinksToResultListWhenIncluded.

@Test
public void shouldAddPersonLinksToResultListWhenIncluded() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("Person:link:Patient"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = results.getResources(START_INDEX, END_INDEX);
    assertThat(resultList, not(empty()));
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    assertThat(((org.hl7.fhir.r4.model.Person) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(PERSON_UUID));
    org.hl7.fhir.r4.model.Person returnedPerson = (org.hl7.fhir.r4.model.Person) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), hasProperty("id", equalTo(returnedPerson.getLinkFirstRep().getTarget().getReferenceElement().getIdPart())))));
}
Also used : Include(ca.uhn.fhir.model.api.Include) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Person(org.hl7.fhir.r4.model.Person) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Person(org.hl7.fhir.r4.model.Person) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 82 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.

the class FhirTaskTranslatorImplTest method toFhirResource_shouldAddProvenanceResources.

@Test
public void toFhirResource_shouldAddProvenanceResources() {
    FhirTask task = new FhirTask();
    task.setUuid(TASK_UUID);
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    when(provenanceTranslator.getCreateProvenance(task)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(task)).thenReturn(provenance);
    org.hl7.fhir.r4.model.Task result = taskTranslator.toFhirResource(task);
    assertThat(result, notNullValue());
    assertThat(result.getContained(), not(empty()));
    assertThat(result.getContained().size(), greaterThanOrEqualTo(2));
    assertThat(result.getContained().stream().anyMatch(resource -> resource.getResourceType().name().equals(Provenance.class.getSimpleName())), is(true));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Date(java.util.Date) Mock(org.mockito.Mock) Matchers.not(org.hamcrest.Matchers.not) Identifier(org.hl7.fhir.r4.model.Identifier) RunWith(org.junit.runner.RunWith) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FhirReference(org.openmrs.module.fhir2.model.FhirReference) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Task(org.hl7.fhir.r4.model.Task) FhirUtils(org.openmrs.module.fhir2.api.util.FhirUtils) StringType(org.hl7.fhir.r4.model.StringType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FhirConstants(org.openmrs.module.fhir2.FhirConstants) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) Collection(java.util.Collection) Set(java.util.Set) Provenance(org.hl7.fhir.r4.model.Provenance) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IdType(org.hl7.fhir.r4.model.IdType) Consumer(java.util.function.Consumer) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) Task(org.hl7.fhir.r4.model.Task) Provenance(org.hl7.fhir.r4.model.Provenance) FhirTask(org.openmrs.module.fhir2.model.FhirTask) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 83 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.

the class ConditionTranslatorImplTest method shouldTranslateOpenMrsConditionOnsetDateToFhirType.

@Test
public void shouldTranslateOpenMrsConditionOnsetDateToFhirType() {
    openmrsCondition.setObsDatetime(new Date());
    org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition);
    assertThat(condition, notNullValue());
    assertThat(condition.getOnsetDateTimeType().getValue(), notNullValue());
    assertThat(condition.getOnsetDateTimeType().getValue(), DateMatchers.sameDay(new Date()));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Date(java.util.Date) Test(org.junit.Test)

Example 84 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.

the class ConditionTranslatorImplTest method shouldAddProvenanceToConditionResource.

@Test
public void shouldAddProvenanceToConditionResource() {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    when(provenanceTranslator.getCreateProvenance(openmrsCondition)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(openmrsCondition)).thenReturn(provenance);
    org.hl7.fhir.r4.model.Condition result = conditionTranslator.toFhirResource(openmrsCondition);
    List<Resource> resources = result.getContained();
    assertThat(resources, Matchers.notNullValue());
    assertThat(resources, Matchers.not(empty()));
    assertThat(resources.stream().findAny().isPresent(), CoreMatchers.is(true));
    assertThat(resources.stream().findAny().get().isResource(), CoreMatchers.is(true));
    assertThat(resources.stream().findAny().get().getResourceType().name(), Matchers.equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Resource(org.hl7.fhir.r4.model.Resource) Condition(org.hl7.fhir.r4.model.Condition) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 85 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project openmrs-module-fhir2 by openmrs.

the class ConditionTranslatorImplTest method shouldTranslateConditionDateCreatedToRecordedDateFhirType.

@Test
public void shouldTranslateConditionDateCreatedToRecordedDateFhirType() {
    openmrsCondition.setDateCreated(new Date());
    org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition);
    assertThat(condition, notNullValue());
    assertThat(condition.getRecordedDate(), notNullValue());
    assertThat(condition.getRecordedDate(), DateMatchers.sameDay(new Date()));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)435 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)289 ArrayList (java.util.ArrayList)112 FHIRException (org.hl7.fhir.exceptions.FHIRException)111 IOException (java.io.IOException)84 List (java.util.List)73 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)66 File (java.io.File)61 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 InputStream (java.io.InputStream)55 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Bundle (org.hl7.fhir.dstu3.model.Bundle)49 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Collectors (java.util.stream.Collectors)48 Arrays (java.util.Arrays)46