Search in sources :

Example 1 with Provenance

use of org.hl7.fhir.r4.model.Provenance 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 2 with Provenance

use of org.hl7.fhir.r4.model.Provenance 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 3 with Provenance

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

the class ObservationTranslatorImplTest method shouldAddProvenanceResources.

@Test
public void shouldAddProvenanceResources() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    when(provenanceTranslator.getCreateProvenance(obs)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(obs)).thenReturn(provenance);
    org.hl7.fhir.r4.model.Observation result = observationTranslator.toFhirResource(obs);
    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 : ObservationBasedOnReferenceTranslator(org.openmrs.module.fhir2.api.translators.ObservationBasedOnReferenceTranslator) DateMatchers(org.exparity.hamcrest.date.DateMatchers) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) Reference(org.hl7.fhir.r4.model.Reference) BigDecimal(java.math.BigDecimal) FhirUtils(org.openmrs.module.fhir2.api.util.FhirUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) FhirConstants(org.openmrs.module.fhir2.FhirConstants) EncounterReferenceTranslator(org.openmrs.module.fhir2.api.translators.EncounterReferenceTranslator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Provenance(org.hl7.fhir.r4.model.Provenance) ObservationReferenceTranslator(org.openmrs.module.fhir2.api.translators.ObservationReferenceTranslator) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ObservationEffectiveDatetimeTranslator(org.openmrs.module.fhir2.api.translators.ObservationEffectiveDatetimeTranslator) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PatientReferenceTranslator(org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator) Matchers.is(org.hamcrest.Matchers.is) Extension(org.hl7.fhir.r4.model.Extension) Mockito.any(org.mockito.Mockito.any) ConceptNumeric(org.openmrs.ConceptNumeric) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Patient(org.openmrs.Patient) ObservationCategoryTranslator(org.openmrs.module.fhir2.api.translators.ObservationCategoryTranslator) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ObservationReferenceRangeTranslator(org.openmrs.module.fhir2.api.translators.ObservationReferenceRangeTranslator) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ArgumentCaptor(org.mockito.ArgumentCaptor) ObservationStatusTranslator(org.openmrs.module.fhir2.api.translators.ObservationStatusTranslator) ObservationInterpretationTranslator(org.openmrs.module.fhir2.api.translators.ObservationInterpretationTranslator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) Before(org.junit.Before) Person(org.openmrs.Person) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Encounter(org.openmrs.Encounter) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) ConceptTranslator(org.openmrs.module.fhir2.api.translators.ConceptTranslator) Order(org.openmrs.Order) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IdType(org.hl7.fhir.r4.model.IdType) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Concept(org.openmrs.Concept) ObservationValueTranslator(org.openmrs.module.fhir2.api.translators.ObservationValueTranslator) Collections(java.util.Collections) Obs(org.openmrs.Obs) Provenance(org.hl7.fhir.r4.model.Provenance) Observation(org.hl7.fhir.r4.model.Observation) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 4 with Provenance

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

the class PatientTranslatorImplTest method shouldNotAddUpdateProvenanceIfDateChangedAndChangedByAreBothNull.

@Test
public void shouldNotAddUpdateProvenanceIfDateChangedAndChangedByAreBothNull() {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    org.openmrs.Patient patient = new org.openmrs.Patient();
    patient.setUuid(PATIENT_UUID);
    patient.setDateChanged(null);
    patient.setChangedBy(null);
    when(provenanceTranslator.getCreateProvenance(patient)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(patient)).thenReturn(null);
    org.hl7.fhir.r4.model.Patient result = patientTranslator.toFhirResource(patient);
    assertThat(result, notNullValue());
    assertThat(result.getContained(), not(empty()));
    assertThat(result.getContained().size(), equalTo(1));
    assertThat(result.getContained().stream().anyMatch(resource -> resource.getResourceType().name().equals(Provenance.class.getSimpleName())), is(true));
}
Also used : FhirPersonDao(org.openmrs.module.fhir2.api.dao.FhirPersonDao) DateMatchers(org.exparity.hamcrest.date.DateMatchers) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) Identifier(org.hl7.fhir.r4.model.Identifier) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) FhirUtils(org.openmrs.module.fhir2.api.util.FhirUtils) HumanName(org.hl7.fhir.r4.model.HumanName) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) PatientIdentifierTranslator(org.openmrs.module.fhir2.api.translators.PatientIdentifierTranslator) Patient(org.hl7.fhir.r4.model.Patient) PersonName(org.openmrs.PersonName) DateType(org.hl7.fhir.r4.model.DateType) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) PersonAttribute(org.openmrs.PersonAttribute) Provenance(org.hl7.fhir.r4.model.Provenance) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Instant(java.time.Instant) Sets(com.google.common.collect.Sets) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Mockito.any(org.mockito.Mockito.any) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Address(org.hl7.fhir.r4.model.Address) Calendar(java.util.Calendar) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PersonAddress(org.openmrs.PersonAddress) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) PatientIdentifier(org.openmrs.PatientIdentifier) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) Enumerations(org.hl7.fhir.r4.model.Enumerations) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IdType(org.hl7.fhir.r4.model.IdType) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PersonAttributeType(org.openmrs.PersonAttributeType) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) Provenance(org.hl7.fhir.r4.model.Provenance) Patient(org.hl7.fhir.r4.model.Patient) Patient(org.hl7.fhir.r4.model.Patient) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 5 with Provenance

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

the class PatientTranslatorImplTest method shouldAddProvenanceResources.

@Test
public void shouldAddProvenanceResources() {
    org.openmrs.Patient patient = new org.openmrs.Patient();
    patient.setUuid(PATIENT_UUID);
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    when(provenanceTranslator.getCreateProvenance(patient)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(patient)).thenReturn(provenance);
    org.hl7.fhir.r4.model.Patient result = patientTranslator.toFhirResource(patient);
    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 : FhirPersonDao(org.openmrs.module.fhir2.api.dao.FhirPersonDao) DateMatchers(org.exparity.hamcrest.date.DateMatchers) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) Identifier(org.hl7.fhir.r4.model.Identifier) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) FhirUtils(org.openmrs.module.fhir2.api.util.FhirUtils) HumanName(org.hl7.fhir.r4.model.HumanName) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) PatientIdentifierTranslator(org.openmrs.module.fhir2.api.translators.PatientIdentifierTranslator) Patient(org.hl7.fhir.r4.model.Patient) PersonName(org.openmrs.PersonName) DateType(org.hl7.fhir.r4.model.DateType) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) PersonAttribute(org.openmrs.PersonAttribute) Provenance(org.hl7.fhir.r4.model.Provenance) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Instant(java.time.Instant) Sets(com.google.common.collect.Sets) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Mockito.any(org.mockito.Mockito.any) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Address(org.hl7.fhir.r4.model.Address) Calendar(java.util.Calendar) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PersonAddress(org.openmrs.PersonAddress) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) PatientIdentifier(org.openmrs.PatientIdentifier) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) Enumerations(org.hl7.fhir.r4.model.Enumerations) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IdType(org.hl7.fhir.r4.model.IdType) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PersonAttributeType(org.openmrs.PersonAttributeType) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) Provenance(org.hl7.fhir.r4.model.Provenance) Patient(org.hl7.fhir.r4.model.Patient) Patient(org.hl7.fhir.r4.model.Patient) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Aggregations

Provenance (org.hl7.fhir.r4.model.Provenance)63 Test (org.junit.Test)59 Date (java.util.Date)37 IdType (org.hl7.fhir.r4.model.IdType)27 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)21 Coding (org.hl7.fhir.r4.model.Coding)21 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)16 Reference (org.hl7.fhir.r4.model.Reference)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)9 Matchers.empty (org.hamcrest.Matchers.empty)9 Matchers.equalTo (org.hamcrest.Matchers.equalTo)9 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)9 Matchers.is (org.hamcrest.Matchers.is)9 Matchers.not (org.hamcrest.Matchers.not)9 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)9 Bundle (org.hl7.fhir.r4.model.Bundle)9 Before (org.junit.Before)9 RunWith (org.junit.runner.RunWith)9 Mock (org.mockito.Mock)9 Mockito.when (org.mockito.Mockito.when)9