Search in sources :

Example 36 with Practitioner

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

the class FhirImmunizationServiceImplTest method updateImmunization_shouldUpdateImmunizationAccordingly.

@Test
public void updateImmunization_shouldUpdateImmunizationAccordingly() {
    // setup
    FhirContext ctx = FhirContext.forR4();
    IParser parser = ctx.newJsonParser();
    Immunization updatedImmunization = parser.parseResource(Immunization.class, "{\n" + "  \"resourceType\": \"Immunization\",\n" + "  \"id\": \"9353776b-dead-4588-8723-d687197d8438\",\n" + "  \"status\": \"completed\",\n" + "  \"vaccineCode\": {\n" + "    \"coding\": [\n" + "      {\n" + "        \"code\": \"d144d24f-6913-4b63-9660-a9108c2bebef\",\n" + "        \"display\": \"STAVUDINE LAMIVUDINE AND NEVIRAPINE\"\n" + "      }\n" + "    ]\n" + "  },\n" + "  \"patient\": {\n" + "    \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + "    \"type\": \"Patient\"\n" + "  },\n" + "  \"encounter\": {\n" + "    \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + "    \"type\": \"Encounter\"\n" + "  },\n" + "  \"occurrenceDateTime\": \"2020-07-08T20:30:00+02:00\",\n" + "  \"manufacturer\": {\n" + "    \"display\": \"Pharma Inc.\"\n" + "  },\n" + "  \"lotNumber\": \"YU765YT-1\",\n" + "  \"expirationDate\": \"2020-10-08\",\n" + "  \"performer\": [\n" + "    {\n" + "      \"actor\": {\n" + "        \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + "        \"type\": \"Practitioner\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"protocolApplied\": [\n" + "    {\n" + "      \"doseNumberPositiveInt\": 4\n" + "    }\n" + "  ]\n" + "}");
    // replay
    Immunization savedImmunization = service.update("9353776b-dead-4588-8723-d687197d8438", updatedImmunization);
    Obs obs = obsService.getObsByUuid(savedImmunization.getId());
    // verify
    helper.validateImmunizationObsGroup(obs);
    assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
    obs.getGroupMembers().forEach(o -> {
        assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
    });
    Map<String, Obs> members = helper.getObsMembersMap(obs);
    assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("d144d24f-6913-4b63-9660-a9108c2bebef"));
    assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T20:30:00+02:00").getValue()));
    assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(4.0));
    assertThat(members.get(CIEL_1419).getValueText(), is("Pharma Inc."));
    assertThat(members.get(CIEL_1420).getValueText(), is("YU765YT-1"));
    assertThat(members.get(CIEL_165907).getValueDate(), equalTo(new DateType("2020-10-08").getValue()));
}
Also used : Obs(org.openmrs.Obs) FhirContext(ca.uhn.fhir.context.FhirContext) Immunization(org.hl7.fhir.r4.model.Immunization) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DateType(org.hl7.fhir.r4.model.DateType) IParser(ca.uhn.fhir.parser.IParser) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 37 with Practitioner

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

the class FhirImmunizationServiceImplTest method searchImmunizations_shouldFetchImmunizationsByPatientIdentifier.

@Test
public void searchImmunizations_shouldFetchImmunizationsByPatientIdentifier() {
    // setup
    ReferenceAndListParam param = new ReferenceAndListParam();
    param.addValue(new ReferenceOrListParam().add(new ReferenceParam(SP_IDENTIFIER, "12345K")));
    // replay
    List<Immunization> immunizations = get(service.searchImmunizations(param, null));
    // verify (in chronological order)
    assertThat(immunizations.size(), is(2));
    {
        Immunization immunization = immunizations.get(0);
        Coding coding = immunization.getVaccineCode().getCoding().get(0);
        assertThat(coding.getDisplay(), is("STAVUDINE LAMIVUDINE AND NEVIRAPINE"));
        assertThat(coding.getCode(), is("d144d24f-6913-4b63-9660-a9108c2bebef"));
        assertThat(immunization.getPatient().getReference(), is("Patient/a7e04421-525f-442f-8138-05b619d16def"));
        assertThat(immunization.getPatient().getType(), is(PATIENT));
        assertThat(immunization.getEncounter().getReference(), is("Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc"));
        assertThat(immunization.getEncounter().getType(), is(ENCOUNTER));
        assertThat(immunization.getOccurrenceDateTimeType().getValue().toString(), is("2020-07-08 20:30:00.0"));
        assertThat(immunization.getManufacturer().getDisplay(), is("Pharma Inc."));
        assertThat(immunization.getLotNumber(), is("YU765YT"));
        assertThat(immunization.getExpirationDate().toString(), is("2022-01-01 12:00:00.0"));
        assertThat(immunization.getPerformer().size(), is(1));
        assertThat(immunization.getPerformer().get(0).getActor().getReference(), is("Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66"));
        assertThat(immunization.getPerformer().get(0).getActor().getType(), is(PRACTITIONER));
        assertThat(immunization.getProtocolApplied().size(), is(1));
        assertThat(immunization.getProtocolApplied().get(0).getDoseNumberPositiveIntType().getValue(), is(3));
    }
    {
        Immunization immunization = immunizations.get(1);
        Coding coding = immunization.getVaccineCode().getCoding().get(0);
        assertThat(coding.getDisplay(), is("COUGH SYRUP"));
        assertThat(coding.getCode(), is("0cbe2ed3-cd5f-4f46-9459-26127c9265ab"));
        assertThat(immunization.getPatient().getReference(), is("Patient/a7e04421-525f-442f-8138-05b619d16def"));
        assertThat(immunization.getPatient().getType(), is(PATIENT));
        assertThat(immunization.getEncounter().getReference(), is("Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc"));
        assertThat(immunization.getEncounter().getType(), is(ENCOUNTER));
        assertThat(immunization.getOccurrenceDateTimeType().getValue().toString(), is("2020-06-08 20:30:00.0"));
        assertThat(immunization.getManufacturer().getDisplay(), is("Biotech Ltd"));
        assertThat(immunization.getLotNumber(), is("WV654XU"));
        assertThat(immunization.getExpirationDate().toString(), is("2023-01-01 12:00:00.0"));
        assertThat(immunization.getPerformer().size(), is(1));
        assertThat(immunization.getPerformer().get(0).getActor().getReference(), is("Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66"));
        assertThat(immunization.getPerformer().get(0).getActor().getType(), is(PRACTITIONER));
        assertThat(immunization.getProtocolApplied().size(), is(1));
        assertThat(immunization.getProtocolApplied().get(0).getDoseNumberPositiveIntType().getValue(), is(11));
    }
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Coding(org.hl7.fhir.r4.model.Coding) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 38 with Practitioner

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

the class PractitionerSearchQueryTest method searchForPractitioners_shouldSearchForPractitionersByUuid.

@Test
public void searchForPractitioners_shouldSearchForPractitionersByUuid() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PRACTITIONER_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((Practitioner) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(PRACTITIONER_UUID));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 39 with Practitioner

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

the class PractitionerSearchQueryTest method searchForPractitioners_shouldReturnPractitionersByCity.

@Test
public void searchForPractitioners_shouldReturnPractitionersByCity() {
    StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, city);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((Practitioner) resultList.iterator().next()).getAddressFirstRep().getCity(), equalTo(CITY));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 40 with Practitioner

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

the class PractitionerSearchQueryTest method searchForPractitioners_shouldHandleComplexQuery.

@Test
public void searchForPractitioners_shouldHandleComplexQuery() {
    StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(PRACTITIONER_GIVEN_NAME)));
    TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(PRACTITIONER_IDENTIFIER));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name).addParameter(FhirConstants.IDENTIFIER_SEARCH_HANDLER, identifier);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((Practitioner) resultList.iterator().next()).getIdentifierFirstRep().getValue(), equalTo(PRACTITIONER_IDENTIFIER));
    assertThat(resultList.iterator().next().getIdElement().getIdPart(), equalTo(PRACTITIONER_UUID));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)185 Practitioner (org.hl7.fhir.r4.model.Practitioner)139 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)86 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)81 Test (org.junit.jupiter.api.Test)68 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)62 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)59 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)54 StringParam (ca.uhn.fhir.rest.param.StringParam)54 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)52 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 Identifier (org.hl7.fhir.r4.model.Identifier)32 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)30 Resource (org.hl7.fhir.r4.model.Resource)30 ArrayList (java.util.ArrayList)25 Reference (org.hl7.fhir.r4.model.Reference)24 Bundle (org.hl7.fhir.r4.model.Bundle)22 Date (java.util.Date)21 List (java.util.List)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20