Search in sources :

Example 6 with Property

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

the class FhirObservationDaoImpl method getSearchResultUuids.

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
    if (!theParams.getParameters(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER).isEmpty()) {
        Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(typeToken.getRawType());
        setupSearchParams(criteria, theParams);
        criteria.setProjection(Projections.projectionList().add(property("uuid")).add(property("concept")).add(property("obsDatetime")));
        @SuppressWarnings("unchecked") List<LastnResult> results = ((List<Object[]>) criteria.list()).stream().map(objects -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("concept", objects[1]);
            return new LastnResult(objects[0], objects[2], attributes);
        }).collect(Collectors.toList());
        return getLastnUuids(handleGrouping(results), getMaxParameter(theParams)).stream().distinct().collect(Collectors.toList());
    }
    if (!theParams.getParameters(FhirConstants.LASTN_ENCOUNTERS_SEARCH_HANDLER).isEmpty()) {
        ReferenceAndListParam encountersReferences = new ReferenceAndListParam();
        ReferenceOrListParam referenceOrListParam = new ReferenceOrListParam();
        List<String> encounters = encounterDao.getSearchResultUuids(theParams);
        encounters.forEach(encounter -> referenceOrListParam.addOr(new ReferenceParam().setValue(encounter)));
        encountersReferences.addAnd(referenceOrListParam);
        theParams.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encountersReferences);
    }
    return super.getSearchResultUuids(theParams);
}
Also used : Criteria(org.hibernate.Criteria) QuantityAndListParam(ca.uhn.fhir.rest.param.QuantityAndListParam) Projections.property(org.hibernate.criterion.Projections.property) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) FhirObservationDao(org.openmrs.module.fhir2.api.dao.FhirObservationDao) Map(java.util.Map) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Obs(org.openmrs.Obs) Nonnull(javax.annotation.Nonnull) Observation(org.hl7.fhir.r4.model.Observation) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Criterion(org.hibernate.criterion.Criterion) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) LastnResult(org.openmrs.module.fhir2.api.util.LastnResult) ObservationCategoryMap(org.openmrs.module.fhir2.api.mappings.ObservationCategoryMap) LastnOperationUtils.getTopNRankedUuids(org.openmrs.module.fhir2.api.util.LastnOperationUtils.getTopNRankedUuids) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Projections(org.hibernate.criterion.Projections) Collectors(java.util.stream.Collectors) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Restrictions.eq(org.hibernate.criterion.Restrictions.eq) List(java.util.List) Component(org.springframework.stereotype.Component) Concept(org.openmrs.Concept) Optional(java.util.Optional) FhirEncounterDao(org.openmrs.module.fhir2.api.dao.FhirEncounterDao) NumberParam(ca.uhn.fhir.rest.param.NumberParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Subqueries(org.hibernate.criterion.Subqueries) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) LastnResult(org.openmrs.module.fhir2.api.util.LastnResult) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Criteria(org.hibernate.Criteria) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) ObservationCategoryMap(org.openmrs.module.fhir2.api.mappings.ObservationCategoryMap)

Example 7 with Property

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

the class TaskPollingService method handleFinishedTask.

protected void handleFinishedTask(Bundle resultBundle, Task ehrTask, ServiceRequest ehrServiceRequest, Task cpTask, Endpoint endpoint) {
    if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus())) {
        ehrServiceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
        resultBundle.addEntry(FhirUtil.createPutEntry(ehrServiceRequest));
    }
    // property.
    if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus()) || Task.TaskStatus.CANCELLED.equals(cpTask.getStatus())) {
        // Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
        // Procedure - copy output changing a Procedure reference to a local one.
        List<TaskOutputComponent> cpOutputs = cpTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
        if (cpOutputs.size() == 0) {
            log.warn("Not output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}' at '{}'. " + "Expecting a reference to a Procedure resource.", cpTask.getIdElement().getIdPart(), endpoint.getAddress());
        }
        Map<String, Procedure> cpProcedureMap = getCpProcedures(cpOutputs, endpoint);
        for (Task.TaskOutputComponent cpOutput : cpOutputs) {
            Task.TaskOutputComponent ehrTaskOutput = cpOutput.copy();
            if (cpOutput.getValue() instanceof Reference) {
                Reference cpProcedureReference = (Reference) cpOutput.getValue();
                String cpProcedureId = cpProcedureReference.getReferenceElement().getIdPart();
                Procedure cpProcedure = cpProcedureMap.get(cpProcedureId);
                // All Procedures have the same reason reference as ServiceRequest
                Procedure resultProcedure = copyProcedure(cpProcedure, ehrTask.getFor(), ehrTask.getFocus(), ehrServiceRequest.getReasonReference());
                resultProcedure.setId(IdType.newRandomUuid());
                resultProcedure.addIdentifier().setSystem(endpoint.getAddress()).setValue(cpProcedureId);
                // Add Procedure to result bundle
                resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
                ehrTaskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), cpProcedureReference.getDisplay()));
            }
            ehrTask.addOutput(ehrTaskOutput);
        }
    }
}
Also used : Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Endpoint(org.hl7.fhir.r4.model.Endpoint) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Set(java.util.Set) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Organization(org.hl7.fhir.r4.model.Organization) Slf4j(lombok.extern.slf4j.Slf4j) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) List(java.util.List) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) JSONObject(net.minidev.json.JSONObject) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Task(org.hl7.fhir.r4.model.Task) Reference(org.hl7.fhir.r4.model.Reference) Procedure(org.hl7.fhir.r4.model.Procedure) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent)

Example 8 with Property

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

the class OurTaskPollingService method handleFinishedTask.

protected void handleFinishedTask(Bundle resultBundle, Task task, ServiceRequest serviceRequest, Task ourTask) {
    boolean isFinished = false;
    if (TaskStatus.COMPLETED.equals(ourTask.getStatus())) {
        serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
        resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
        isFinished = true;
    } else if (TaskStatus.CANCELLED.equals(ourTask.getStatus()) || TaskStatus.REJECTED.equals(ourTask.getStatus()) || TaskStatus.FAILED.equals(ourTask.getStatus())) {
        serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.REVOKED);
        resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
        isFinished = true;
    }
    // property.
    if (isFinished) {
        // Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
        // Procedure - copy output changing a Procedure reference to a local one.
        List<TaskOutputComponent> ourTaskOutputs = ourTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
        if (ourTaskOutputs.size() == 0) {
            log.warn("No output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}'. " + "Expecting a reference to a Procedure resource.", ourTask.getIdElement().getIdPart());
        }
        Map<String, Procedure> ourProcedureMap = getOurTaskProcedures(ourTaskOutputs);
        for (TaskOutputComponent ourTaskOutput : ourTaskOutputs) {
            TaskOutputComponent taskOutput = ourTaskOutput.copy();
            if (ourTaskOutput.getValue() instanceof Reference) {
                Reference ourProcedureReference = (Reference) ourTaskOutput.getValue();
                String ourProcedureId = ourProcedureReference.getReferenceElement().getIdPart();
                Procedure ourProcedure = ourProcedureMap.get(ourProcedureId);
                // All Procedures have the same reason reference as ServiceRequest
                Procedure resultProcedure = copyProcedure(ourProcedure, task.getFor(), task.getFocus(), serviceRequest.getReasonReference());
                resultProcedure.setId(IdType.newRandomUuid());
                // TODO add identifier
                // resultProcedure.addIdentifier()
                // .setSystem(SERVER_BASE)
                // .setValue(ourProcedureId);
                // Add Procedure to result bundle
                resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
                taskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), ourProcedureReference.getDisplay()));
            }
            task.addOutput(taskOutput);
        }
    }
}
Also used : OurTaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor.OurTaskPollingUpdateException) OurTasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor.OurTasksPollingInfo) Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) OurTasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor) Bundle(org.hl7.fhir.r4.model.Bundle) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Reference(org.hl7.fhir.r4.model.Reference) Procedure(org.hl7.fhir.r4.model.Procedure) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 9 with Property

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

the class ConditionBundleToDtoConverterBase method conditionInfoToDto.

protected T conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    T conditionDto = newConditionDtoImpl();
    Condition condition = conditionInfo.getCondition();
    conditionDto.setId(condition.getIdElement().getIdPart());
    conditionDto.setName(codeableConceptToStringConverter.convert(condition.getCode()));
    Coding categoryCoding = FhirUtil.findCoding(condition.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(condition.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
    }
    if (categoryCoding == null) {
        conditionDto.getErrors().add("SDOH category is not found.");
    } else {
        conditionDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
    }
    Optional<Coding> icdCodeCodingOptional = findCode(condition.getCode(), System.ICD_10);
    if (icdCodeCodingOptional.isPresent()) {
        Coding icdCodeCoding = icdCodeCodingOptional.get();
        conditionDto.setIcdCode(new CodingDto(icdCodeCoding.getCode(), icdCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("ICD-10 code is not found.");
    }
    Optional<Coding> snomedCodeCodingOptional = findCode(condition.getCode(), System.SNOMED);
    if (snomedCodeCodingOptional.isPresent()) {
        Coding snomedCodeCoding = snomedCodeCodingOptional.get();
        conditionDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("SNOMED-CT code is not found.");
    }
    QuestionnaireResponse questionnaireResponse = conditionInfo.getQuestionnaireResponse();
    if (questionnaireResponse != null) {
        conditionDto.setAssessmentDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
        Questionnaire questionnaire = conditionInfo.getQuestionnaire();
        if (questionnaire != null) {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaire.getTitle()));
        } else {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaireResponse.getQuestionnaire()));
            conditionDto.getErrors().add("Based on QuestionnaireResponse doesn't have a matching Questionnaire to get a title from. Using URL " + "instead.");
        }
    } else {
        conditionDto.setBasedOn(new StringTypeDto(condition.getEvidenceFirstRep().getCodeFirstRep().getText()));
        Reference recorder = condition.getRecorder();
        conditionDto.setAuthoredBy(new ReferenceDto(recorder.getReferenceElement().getIdPart(), recorder.getDisplay()));
    }
    // abatement must be available for all resolved condition
    if (ConditionClinicalStatusCodes.RESOLVED.toCode().equals(condition.getClinicalStatus().getCodingFirstRep().getCode())) {
        if (condition.getAbatement() instanceof DateTimeType) {
            conditionDto.setResolutionDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getAbatement()));
        } else {
            conditionDto.getErrors().add("Condition is resolved but an abatement property is missing or not of a DateTimeType type.");
        }
    }
    return conditionDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 10 with Property

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

Aggregations

ArrayList (java.util.ArrayList)36 FHIRException (org.hl7.fhir.exceptions.FHIRException)35 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)30 JsonElement (com.google.gson.JsonElement)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)21 List (java.util.List)15 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)14 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 Test (org.junit.jupiter.api.Test)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 Map (java.util.Map)10 Property (com.adobe.target.delivery.v1.model.Property)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9 Context (com.adobe.target.delivery.v1.model.Context)8