Search in sources :

Example 81 with IdType

use of org.hl7.fhir.r4b.model.IdType 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 82 with IdType

use of org.hl7.fhir.r4b.model.IdType 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)

Example 83 with IdType

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

the class AllergyIntoleranceFhirR3ResourceProviderTest method getAllergyIntoleranceByUuid_shouldReturnMatchingAllergy.

@Test
public void getAllergyIntoleranceByUuid_shouldReturnMatchingAllergy() {
    when(service.get(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    IdType id = new IdType();
    id.setValue(ALLERGY_UUID);
    AllergyIntolerance allergy = resourceProvider.getAllergyIntoleranceById(id);
    assertThat(allergy, notNullValue());
    assertThat(allergy.getId(), notNullValue());
    assertThat(allergy.getId(), equalTo(ALLERGY_UUID));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 84 with IdType

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

the class AllergyIntoleranceFhirR3ResourceProviderTest method getAllergyIntoleranceHistory_shouldReturnProvenanceResources.

@Test
public void getAllergyIntoleranceHistory_shouldReturnProvenanceResources() {
    IdType id = new IdType();
    id.setValue(ALLERGY_UUID);
    when(service.get(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    List<Resource> resources = resourceProvider.getAllergyIntoleranceHistoryById(id);
    assertThat(resources, not(empty()));
    assertThat(resources.stream().findAny().isPresent(), is(true));
    assertThat(resources.stream().findAny().get().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.dstu3.model.Resource) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 85 with IdType

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

the class AllergyIntoleranceFhirR3ResourceProviderTest method updateAllergyIntolerance_shouldUpdateAllergyIntolerance.

@Test
public void updateAllergyIntolerance_shouldUpdateAllergyIntolerance() {
    when(service.update(eq(ALLERGY_UUID), any(org.hl7.fhir.r4.model.AllergyIntolerance.class))).thenReturn(allergyIntolerance);
    MethodOutcome result = resourceProvider.updateAllergyIntolerance(new IdType().setValue(ALLERGY_UUID), AllergyIntolerance30_40.convertAllergyIntolerance(allergyIntolerance));
    assertThat(result, notNullValue());
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Aggregations

IdType (org.hl7.fhir.r4.model.IdType)240 Test (org.junit.Test)240 IdType (org.hl7.fhir.dstu3.model.IdType)217 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)87 Test (org.junit.jupiter.api.Test)72 HashMap (java.util.HashMap)70 JsonObject (javax.json.JsonObject)55 Path (javax.ws.rs.Path)55 Produces (javax.ws.rs.Produces)55 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)50 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)49 Bundle (org.hl7.fhir.r4.model.Bundle)45 Date (java.util.Date)44 GET (javax.ws.rs.GET)40 ArrayList (java.util.ArrayList)38 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)36 Coding (org.hl7.fhir.r4.model.Coding)34 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)33 Resource (org.hl7.fhir.r4.model.Resource)33 Provenance (org.hl7.fhir.r4.model.Provenance)32