Search in sources :

Example 1 with CpTaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class CpTaskInfoBundleExtractor method extract.

@Override
public List<CpTaskInfoHolder> extract(Bundle bundle) {
    List<TaskInfoHolder> taskInfoHolders = taskInfoBundleExtractor.extract(bundle);
    Map<String, Task> taskIdToOurTaskMap = FhirUtil.getFromBundle(bundle, Task.class).stream().filter(t -> t.getIntent() == Task.TaskIntent.FILLERORDER).collect(Collectors.toMap(ourTask -> ourTask.getBasedOn().get(0).getResource().getIdElement().getIdPart(), Function.identity()));
    return taskInfoHolders.stream().filter(t -> t.getTask().getIntent() == Task.TaskIntent.ORDER).map(taskInfoHolder -> {
        Task ourTask = taskIdToOurTaskMap.get(taskInfoHolder.getTask().getIdElement().getIdPart());
        Organization performer = null;
        if (!Objects.isNull(ourTask)) {
            if (!(ourTask.getOwner().getResource() instanceof Organization)) {
                String reason = String.format("Our task resource with id '%s' does not contain owner of type Organization.", ourTask.getIdElement().getIdPart());
                throw new CpTaskInfoBundleExtractorException(reason);
            }
            performer = (Organization) ourTask.getOwner().getResource();
        }
        return new CpTaskInfoHolder(taskInfoHolder, ourTask, performer);
    }).collect(Collectors.toList());
}
Also used : TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder) Objects(java.util.Objects) Organization(org.hl7.fhir.r4.model.Organization) Task(org.hl7.fhir.r4.model.Task) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) List(java.util.List) Getter(lombok.Getter) Map(java.util.Map) Bundle(org.hl7.fhir.r4.model.Bundle) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Task(org.hl7.fhir.r4.model.Task) Organization(org.hl7.fhir.r4.model.Organization) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Getter (lombok.Getter)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 Organization (org.hl7.fhir.r4.model.Organization)1 Task (org.hl7.fhir.r4.model.Task)1 CpTaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder)1 TaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder)1 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)1