Search in sources :

Example 1 with PatientTaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskInfoBundleExtractor.PatientTaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskInfoHolderToDtoConverter method convert.

@Override
public PatientTaskDto convert(PatientTaskInfoHolder taskInfoHolder) {
    Task task = taskInfoHolder.getTask();
    PatientTaskDto taskDto = (PatientTaskDto) super.convert(taskInfoHolder);
    taskDto.setCreatedAt(FhirUtil.toLocalDateTime(task.getAuthoredOnElement()));
    taskDto.setComments(task.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
    taskDto.setOccurrence(new OccurrenceResponseDto(FhirUtil.toLocalDateTime(task.getExecutionPeriod().getStartElement()), FhirUtil.toLocalDateTime(task.getExecutionPeriod().getEndElement())));
    if (taskInfoHolder.getQuestionnaireResponse() != null) {
        taskDto.setAnswers(taskInfoHolder.getQuestionnaireResponse().getItem().stream().collect(Collectors.toMap(qr -> qr.getText(), qr -> {
            Type itemAnswer = qr.getAnswerFirstRep().getValue();
            if (itemAnswer instanceof StringType) {
                return ((StringType) itemAnswer).getValue();
            } else if (itemAnswer instanceof Coding) {
                return ((Coding) itemAnswer).getDisplay();
            } else {
                taskDto.getErrors().add(String.format("Answer cannot be resolved. %s type is not expected.", itemAnswer.getClass().getSimpleName()));
                return "Answer cannot be parsed.";
            }
        }, (existing, replacement) -> {
            taskDto.getErrors().add(String.format("Duplicating questions detected. Value '%s' overwrites the value '%s'", replacement, existing));
            return replacement;
        }, LinkedHashMap::new)));
    }
    return taskDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Type(org.hl7.fhir.r4.model.Type) StringType(org.hl7.fhir.r4.model.StringType) StringType(org.hl7.fhir.r4.model.StringType) Coding(org.hl7.fhir.r4.model.Coding) OccurrenceResponseDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.OccurrenceResponseDto) PatientTaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with PatientTaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskInfoBundleExtractor.PatientTaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskInfoBundleExtractor method extract.

@Override
public List<PatientTaskInfoHolder> extract(Bundle bundle) {
    List<PatientTaskItemInfoHolder> patientTaskItemInfoHolders = patientTaskItemInfoBundleExtractor.extract(bundle);
    Map<String, QuestionnaireResponse> questionnaireResponsesMap = FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().collect(Collectors.toMap(qr -> qr.getIdElement().getIdPart(), Function.identity()));
    return patientTaskItemInfoHolders.stream().map(infoHolder -> {
        Task.TaskOutputComponent outputComponent = infoHolder.getTask().getOutput().stream().filter(o -> FhirUtil.findCoding(Lists.newArrayList(o.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode()) != null).findAny().orElse(null);
        String questionnaireResponseId = null;
        if (outputComponent != null) {
            questionnaireResponseId = ((Reference) outputComponent.getValue()).getReferenceElement().getIdPart();
        }
        return new PatientTaskInfoHolder(infoHolder, questionnaireResponsesMap.get(questionnaireResponseId));
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Reference(org.hl7.fhir.r4.model.Reference) PatientTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskInfoBundleExtractor.PatientTaskInfoHolder) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SDCTemporaryCode(org.hl7.gravity.refimpl.sdohexchange.codes.SDCTemporaryCode) BundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.BundleExtractor) PatientTaskItemInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskItemInfoBundleExtractor.PatientTaskItemInfoHolder) Task(org.hl7.fhir.r4.model.Task) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) Bundle(org.hl7.fhir.r4.model.Bundle) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) PatientTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskInfoBundleExtractor.PatientTaskInfoHolder) PatientTaskItemInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskItemInfoBundleExtractor.PatientTaskItemInfoHolder) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Aggregations

Task (org.hl7.fhir.r4.model.Task)2 Lists (com.google.common.collect.Lists)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)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 Coding (org.hl7.fhir.r4.model.Coding)1 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)1 Reference (org.hl7.fhir.r4.model.Reference)1 StringType (org.hl7.fhir.r4.model.StringType)1 Type (org.hl7.fhir.r4.model.Type)1 SDCTemporaryCode (org.hl7.gravity.refimpl.sdohexchange.codes.SDCTemporaryCode)1 OccurrenceResponseDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.OccurrenceResponseDto)1 PatientTaskDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto)1 BundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.BundleExtractor)1 PatientTaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskInfoBundleExtractor.PatientTaskInfoHolder)1 PatientTaskItemInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientTaskItemInfoBundleExtractor.PatientTaskItemInfoHolder)1