Search in sources :

Example 76 with IdType

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

the class LocationFhirResourceProviderTest method getLocationHistoryById_shouldReturnListOfResource.

@Test
public void getLocationHistoryById_shouldReturnListOfResource() {
    IdType id = new IdType();
    id.setValue(LOCATION_UUID);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    List<Resource> resources = resourceProvider.getLocationHistoryById(id);
    assertThat(resources, notNullValue());
    assertThat(resources, not(empty()));
    assertThat(resources.size(), equalTo(2));
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 77 with IdType

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

the class MedicationFhirResourceProviderTest method updateMedication_shouldThrowMethodNotAllowedIfDoesNotExist.

@Test(expected = MethodNotAllowedException.class)
public void updateMedication_shouldThrowMethodNotAllowedIfDoesNotExist() {
    Medication wrongMedication = new Medication();
    wrongMedication.setId(WRONG_MEDICATION_UUID);
    when(fhirMedicationService.update(WRONG_MEDICATION_UUID, wrongMedication)).thenThrow(MethodNotAllowedException.class);
    resourceProvider.updateMedication(new IdType().setValue(WRONG_MEDICATION_UUID), wrongMedication);
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 78 with IdType

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

the class MedicationFhirResourceProviderTest method getMedicationByUuid_shouldReturnMatchingMedication.

@Test
public void getMedicationByUuid_shouldReturnMatchingMedication() {
    when(fhirMedicationService.get(MEDICATION_UUID)).thenReturn(medication);
    IdType id = new IdType();
    id.setValue(MEDICATION_UUID);
    Medication medication = resourceProvider.getMedicationByUuid(id);
    assertThat(medication, notNullValue());
    assertThat(medication.getId(), notNullValue());
    assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 79 with IdType

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

the class MedicationFhirResourceProviderTest method updateMedication_shouldUpdateRequestedMedication.

@Test
public void updateMedication_shouldUpdateRequestedMedication() {
    Medication med = medication;
    med.setStatus(Medication.MedicationStatus.INACTIVE);
    when(fhirMedicationService.update(MEDICATION_UUID, medication)).thenReturn(med);
    MethodOutcome result = resourceProvider.updateMedication(new IdType().setValue(MEDICATION_UUID), medication);
    assertThat(result, notNullValue());
    assertThat(result.getResource(), equalTo(med));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 80 with IdType

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

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