Search in sources :

Example 1 with PatientTaskDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskService method read.

public PatientTaskDto read(String id) {
    Bundle taskBundle = new PatientTaskQueryFactory().query(ehrClient, SmartOnFhirContext.get().getPatient()).include(Task.INCLUDE_PART_OF).where(Task.RES_ID.exactly().code(id)).where(new TokenClientParam("owner:Patient").exactly().code(SmartOnFhirContext.get().getPatient())).returnBundle(Bundle.class).execute();
    addQuestionnairesToTaskBundle(taskBundle);
    addQuestionnaireResponsesToTaskBundle(taskBundle);
    return new PatientTaskBundleToDtoConverter().convert(taskBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
}
Also used : Task(org.hl7.fhir.r4.model.Task) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Bundle(org.hl7.fhir.r4.model.Bundle) PatientTaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.PatientTaskBundleToDtoConverter) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) PatientTaskQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.PatientTaskQueryFactory) IdType(org.hl7.fhir.r4.model.IdType)

Example 2 with PatientTaskDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto 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)

Aggregations

Task (org.hl7.fhir.r4.model.Task)2 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)1 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 LinkedHashMap (java.util.LinkedHashMap)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 Coding (org.hl7.fhir.r4.model.Coding)1 IdType (org.hl7.fhir.r4.model.IdType)1 StringType (org.hl7.fhir.r4.model.StringType)1 Type (org.hl7.fhir.r4.model.Type)1 PatientTaskBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.PatientTaskBundleToDtoConverter)1 OccurrenceResponseDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.OccurrenceResponseDto)1 PatientTaskDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto)1 PatientTaskQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.PatientTaskQueryFactory)1