Search in sources :

Example 6 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationWithoutSomeOptionalMembersAsXML.

@Test
public void shouldCreateNewImmunizationWithoutSomeOptionalMembersAsXML() throws Exception {
    // read XML record
    String xmlImmunization;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_PARTIAL_IMMUNIZATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create IMMUNIZATION
    MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.XML).xmlContent(xmlImmunization).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Immunization immunization = readResponse(response);
    assertThat(immunization, notNullValue());
    assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
    assertThat(immunization.getStatus().toCode(), equalTo("completed"));
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
    assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
    assertThat(immunization.hasManufacturer(), is(true));
    assertThat(immunization.getManufacturer().getDisplay(), equalTo("Pfizer"));
    assertThat(immunization.getLotNumber(), equalTo("22"));
    assertThat(immunization.getExpirationDate(), sameDay(LocalDate.parse("2021-07-28")));
    assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
    assertThat(immunization, validResource());
    // try to get new immunization
    response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Immunization newImmunization = readResponse(response);
    assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationAsJson.

@Test
public void shouldCreateNewImmunizationAsJson() throws Exception {
    // read JSON record
    String jsonImmunization;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_IMMUNIZATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create IMMUNIZATION
    MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.JSON).jsonContent(jsonImmunization).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Immunization immunization = readResponse(response);
    assertThat(immunization, notNullValue());
    assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
    assertThat(immunization.getStatus().toCode(), equalTo("completed"));
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
    assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
    assertThat(immunization.hasManufacturer(), is(true));
    assertThat(immunization.getManufacturer().getDisplay(), equalTo("ACME"));
    assertThat(immunization.getLotNumber(), equalTo("FOO1234"));
    assertThat(immunization.getExpirationDate(), sameDay(Date.from(ZonedDateTime.parse("2022-07-31T18:30:00.000Z").toInstant())));
    assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
    assertThat(immunization, validResource());
    // try to get new immunization
    response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Immunization newImmunization = readResponse(response);
    assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 8 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationAsXML.

@Test
public void shouldCreateNewImmunizationAsXML() throws Exception {
    // read XML record
    String xmlImmunization;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_IMMUNIZATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create IMMUNIZATION
    MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.XML).xmlContent(xmlImmunization).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Immunization immunization = readResponse(response);
    assertThat(immunization, notNullValue());
    assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
    assertThat(immunization.getStatus().toCode(), equalTo("completed"));
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
    assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
    assertThat(immunization.hasManufacturer(), is(true));
    assertThat(immunization.getManufacturer().getDisplay(), equalTo("ACME"));
    assertThat(immunization.getLotNumber(), equalTo("FOO1234"));
    assertThat(immunization.getExpirationDate(), sameDay(Date.from(ZonedDateTime.parse("2022-07-31T18:30:00.000Z").toInstant())));
    assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
    assertThat(immunization, validResource());
    // try to get new IMMUNIZATION
    response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Immunization newImmunization = readResponse(response);
    assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 9 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project Gravity-SDOH-Exchange-RI by FHIR.

the class GoalBundleToDtoConverter method convert.

@Override
public List<GoalDto> convert(Bundle bundle) {
    List<GoalDto> result = FhirUtil.getFromBundle(bundle, Goal.class).stream().map(goal -> {
        GoalDto goalDto = new GoalDto();
        goalDto.setId(goal.getIdElement().getIdPart());
        if (goal.hasDescription() && goal.getDescription().hasText()) {
            goalDto.setName(goal.getDescription().getText());
        } else {
            goalDto.getErrors().add("Goal description.text not found. Name cannot be set.");
        }
        if (goal.hasAchievementStatus()) {
            goalDto.setAchievementStatus(GoalAchievement.fromCode(goal.getAchievementStatus().getCodingFirstRep().getCode()));
        } else {
            goalDto.getErrors().add("No achievement status available.");
        }
        // TODO reused from HealthConcernBundleToDtoConverter class. Refactor!
        Coding categoryCoding = FhirUtil.findCoding(goal.getCategory(), SDOHMappings.getInstance().getSystem());
        // TODO remove this in future. Fow now two different categories might be used before discussed.
        if (categoryCoding == null) {
            categoryCoding = FhirUtil.findCoding(goal.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
        }
        if (categoryCoding == null) {
            goalDto.getErrors().add("SDOH category is not found.");
        } else {
            goalDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
        }
        Optional<Coding> snomedCodeCodingOptional = findCode(goal.getDescription(), System.SNOMED);
        if (snomedCodeCodingOptional.isPresent()) {
            Coding snomedCodeCoding = snomedCodeCodingOptional.get();
            goalDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
        } else {
            goalDto.getErrors().add("SNOMED-CT code is not found.");
        }
        if (goal.hasExpressedBy()) {
            Reference expressedBy = goal.getExpressedBy();
            goalDto.setAddedBy(new ReferenceDto(expressedBy.getReferenceElement().getIdPart(), expressedBy.getDisplay()));
        } else {
            goalDto.getErrors().add("Goal expressedBy property is missing. addedBy will be null.");
        }
        goalDto.setStartDate(FhirUtil.toLocalDate(goal.getStartDateType()));
        // TODO this is invalid. To clarify!
        if (goal.getLifecycleStatus() == Goal.GoalLifecycleStatus.COMPLETED) {
            if (goal.hasStatusDate()) {
                goalDto.setEndDate(FhirUtil.toLocalDate(goal.getStatusDateElement()));
            } else {
                goalDto.getErrors().add("Goal statusDate must be set when the lifecycleStatus is COMPLETED. endDate will be null.");
            }
        }
        goalDto.setComments(goal.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
        goalDto.setProblems(goal.getAddresses().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType())).map(ref -> (Condition) ref.getResource()).map(cond -> new ConditionDto(cond.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(cond.getCode()))).collect(Collectors.toList()));
        return goalDto;
    }).collect(Collectors.toList());
    // TODO refactor. method too long.
    // TODO refactor. Almost the same fragmen exists in a ProblemInfoBundleExtractor
    Map<String, GoalDto> idToDtoMap = result.stream().collect(Collectors.toMap(g -> g.getId(), Function.identity()));
    for (Task task : FhirUtil.getFromBundle(bundle, Task.class)) {
        if (!task.hasFocus() || !(task.getFocus().getResource() instanceof ServiceRequest)) {
            continue;
        }
        ServiceRequest sr = (ServiceRequest) task.getFocus().getResource();
        sr.getSupportingInfo().stream().filter(ref -> Goal.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToDtoMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> idToDtoMap.get(ref.getReferenceElement().getIdPart()).getTasks().add(new TaskInfoDto(task.getIdElement().getIdPart(), task.getDescription(), task.getStatus())));
    }
    return result;
}
Also used : Converter(org.springframework.core.convert.converter.Converter) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) Goal(org.hl7.fhir.r4.model.Goal) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Task(org.hl7.fhir.r4.model.Task) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) List(java.util.List) GoalAchievement(org.hl7.fhir.r4.model.codesystems.GoalAchievement) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) Coding(org.hl7.fhir.r4.model.Coding) Map(java.util.Map) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto) System(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System) SDOHMappings(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.SDOHMappings) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Task(org.hl7.fhir.r4.model.Task) Optional(java.util.Optional) Reference(org.hl7.fhir.r4.model.Reference) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Goal(org.hl7.fhir.r4.model.Goal) Coding(org.hl7.fhir.r4.model.Coding) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto)

Example 10 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project integration-adaptor-111 by nhsconnect.

the class CarePlanMapper method createCarePlanFromSection.

public CarePlan createCarePlanFromSection(POCDMT000002UK01Section cpSection, Encounter encounter, Condition condition) {
    CarePlan carePlan = new CarePlan();
    carePlan.setIdElement(resourceUtil.newRandomUuid());
    carePlan.setIntent(PLAN).setSubject(encounter.getSubject()).setSubjectTarget(encounter.getSubjectTarget()).setStatus(COMPLETED).setContextTarget(encounter).setContext(resourceUtil.createReference(encounter)).setPeriod(encounter.getPeriod()).addAddresses(resourceUtil.createReference(condition));
    if (cpSection.isSetLanguageCode()) {
        carePlan.setLanguage(nodeUtil.getNodeValueString(cpSection.getLanguageCode()));
    }
    if (cpSection.isSetTitle()) {
        carePlan.setTitle(nodeUtil.getNodeValueString(cpSection.getTitle()));
    }
    if (cpSection.getText().sizeOfContentArray() > 0) {
        String cpTextContent = nodeUtil.getNodeValueString(cpSection.getText().getContentArray(0));
        carePlan.setDescription(cpTextContent);
    }
    if (encounter.hasLocation()) {
        List<Reference> authorList = new ArrayList<>();
        for (Encounter.EncounterLocationComponent author : encounter.getLocation()) {
            if (author.hasLocation()) {
                Location location = (Location) author.getLocation().getResource();
                if (location.hasManagingOrganization()) {
                    authorList.add(location.getManagingOrganization());
                }
            }
        }
        carePlan.setAuthor(authorList);
    }
    return carePlan;
}
Also used : CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.dstu3.model.Encounter) Location(org.hl7.fhir.dstu3.model.Location)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)13 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Reference (org.hl7.fhir.dstu3.model.Reference)7 Test (org.junit.jupiter.api.Test)7 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Collectors (java.util.stream.Collectors)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)5 Reference (org.hl7.fhir.r4.model.Reference)5 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)5 FhirContext (ca.uhn.fhir.context.FhirContext)4 Search (ca.uhn.fhir.rest.annotation.Search)4 Trace (com.newrelic.api.agent.Trace)4 File (java.io.File)4 List (java.util.List)4 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Bundle (org.hl7.fhir.r4.model.Bundle)4 CodeType (org.hl7.fhir.r4.model.CodeType)4