Search in sources :

Example 81 with org.hl7.fhir.r5.utils.validation.constants

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

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

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

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

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

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