Search in sources :

Example 66 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation 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 67 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation 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 68 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation 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 69 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation 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)

Example 70 with org.hl7.fhir.r5.utils.validation

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

the class ConditionTranslatorImplTest method shouldTranslateConditionConceptToFhirType.

@Test
public void shouldTranslateConditionConceptToFhirType() {
    Concept concept = new Concept();
    concept.setUuid(CONCEPT_UUID);
    concept.setConceptId(CODE);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setCode(CODE.toString());
    coding.setSystem(SYSTEM);
    codeableConcept.addCoding(coding);
    openmrsCondition.setValueCoded(concept);
    when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
    org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition);
    assertThat(condition, notNullValue());
    assertThat(condition.getCode(), notNullValue());
    assertThat(condition.getCode().getCoding(), not(Collections.emptyList()));
    assertThat(condition.getCode().getCoding().get(0).getCode(), equalTo(CODE.toString()));
    assertThat(condition.getCode().getCoding().get(0).getSystem(), equalTo(SYSTEM));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Condition(org.hl7.fhir.r4.model.Condition) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)427 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)104 ArrayList (java.util.ArrayList)101 IOException (java.io.IOException)78 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)65 List (java.util.List)64 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 FileOutputStream (java.io.FileOutputStream)59 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 File (java.io.File)57 InputStream (java.io.InputStream)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Bundle (org.hl7.fhir.dstu3.model.Bundle)48 MethodSource (org.junit.jupiter.params.provider.MethodSource)46 Arrays (java.util.Arrays)45 Collectors (java.util.stream.Collectors)45