Search in sources :

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

use of org.hl7.fhir.r5.model in project elexis-server by elexis.

the class PractitionerRoleTest method getPractitionerRole.

@Test
public void getPractitionerRole() {
    // search by role
    Bundle results = client.search().forResource(PractitionerRole.class).where(PractitionerRole.ROLE.exactly().systemAndCode(org.hl7.fhir.r4.model.codesystems.PractitionerRole.DOCTOR.getSystem(), org.hl7.fhir.r4.model.codesystems.PractitionerRole.DOCTOR.toCode())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    PractitionerRole practitionerRole = (PractitionerRole) entries.get(0).getResource();
    List<CodeableConcept> roles = practitionerRole.getCode();
    boolean doctorRoleFound = false;
    for (CodeableConcept role : roles) {
        List<Coding> codings = role.getCoding();
        for (Coding coding : codings) {
            if (coding.getSystem().equals(org.hl7.fhir.r4.model.codesystems.PractitionerRole.DOCTOR.getSystem()) && coding.getCode().equals(org.hl7.fhir.r4.model.codesystems.PractitionerRole.DOCTOR.toCode())) {
                doctorRoleFound = true;
            }
        }
    }
    assertTrue(doctorRoleFound);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

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

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

the class GroupFhirResourceProviderTest method shouldThrowMethodNotAllowedIfGroupToUpdateDoesNotExist.

@Test(expected = MethodNotAllowedException.class)
public void shouldThrowMethodNotAllowedIfGroupToUpdateDoesNotExist() {
    org.hl7.fhir.r4.model.Group wrongGroup = new org.hl7.fhir.r4.model.Group();
    wrongGroup.setId(BAD_COHORT_UUID);
    when(fhirGroupService.update(eq(BAD_COHORT_UUID), any(org.hl7.fhir.r4.model.Group.class))).thenThrow(MethodNotAllowedException.class);
    resourceProvider.updateGroup(new IdType().setValue(BAD_COHORT_UUID), wrongGroup);
}
Also used : Group(org.hl7.fhir.r4.model.Group) Group(org.hl7.fhir.r4.model.Group) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

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

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

the class GroupFhirResourceProviderTest method shouldUpdateExistingGroup.

@Test
public void shouldUpdateExistingGroup() {
    Group.GroupMemberComponent groupMemberComponent = mock(Group.GroupMemberComponent.class);
    group.setActual(false);
    group.addMember(groupMemberComponent);
    when(fhirGroupService.update(eq(COHORT_UUID), any(org.hl7.fhir.r4.model.Group.class))).thenReturn(group);
    MethodOutcome result = resourceProvider.updateGroup(new IdType().setValue(COHORT_UUID), group);
    assertThat(result, notNullValue());
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(group.getId()));
    assertThat(result.getResource().getStructureFhirVersionEnum(), equalTo(FhirVersionEnum.R4));
}
Also used : Group(org.hl7.fhir.r4.model.Group) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

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

use of org.hl7.fhir.r5.model 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 100 with org.hl7.fhir.r5.model

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

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