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());
}
Aggregations