Search in sources :

Example 61 with Questionnaire

use of org.hl7.fhir.r5.model.Questionnaire in project fhir-bridge by ehrbase.

the class FindQuestionnaireResponseTransactionIT method findQuestionnaireResponseSearch.

@Test
void findQuestionnaireResponseSearch() throws IOException {
    for (int i = 0; i < 3; i++) {
        create("QuestionnaireResponse/transactions/find-questionnaire-response-search.json");
    }
    Bundle bundle = search("QuestionnaireResponse?patient.identifier=" + PATIENT_ID + "&status=entered-in-error");
    Assertions.assertEquals(3, bundle.getTotal());
    bundle.getEntry().forEach(entry -> {
        var questionnaireResponse = (QuestionnaireResponse) entry.getResource();
        Assertions.assertEquals(PATIENT_ID, questionnaireResponse.getSubject().getIdentifier().getValue());
        Assertions.assertEquals(QuestionnaireResponse.QuestionnaireResponseStatus.ENTEREDINERROR, questionnaireResponse.getStatus());
    });
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Test(org.junit.jupiter.api.Test)

Example 62 with Questionnaire

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

the class PatientTaskItemInfoHolderToItemDtoConverter method convert.

@Override
public PatientTaskItemDto convert(T taskInfoHolder) {
    Task task = taskInfoHolder.getTask();
    Questionnaire questionnaire = taskInfoHolder.getQuestionnaire();
    PatientTaskItemDto taskDto = createDto();
    taskDto.setId(task.getIdElement().getIdPart());
    taskDto.setName(task.getDescription());
    taskDto.setPriority(task.getPriority().getDisplay());
    taskDto.setLastModified(FhirUtil.toLocalDateTime(task.getLastModifiedElement()));
    taskDto.setStatus(task.getStatus().getDisplay());
    taskDto.setStatusReason(task.getStatusReason().getText());
    setReferralTask(task, taskDto);
    List<Coding> codings = task.getCode().getCoding();
    PatientTaskCode code = getCode(taskDto, codings);
    if (code != null) {
        Coding coding = code.toCoding();
        taskDto.setCode(new CodingDto(coding.getCode(), coding.getDisplay()));
    }
    setTaskType(task, taskDto, code);
    if (questionnaire != null) {
        taskDto.setAssessment(new ReferenceDto(questionnaire.getIdElement().getIdPart(), questionnaire.getTitle()));
    }
    for (TaskOutputComponent outputComponent : task.getOutput()) {
        Type componentValue = outputComponent.getValue();
        Coding coding = FhirUtil.findCoding(Lists.newArrayList(outputComponent.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
        if (coding != null) {
            Reference qrRef = (Reference) componentValue;
            if (QuestionnaireResponse.class.getSimpleName().equals(qrRef.getReferenceElement().getResourceType())) {
                taskDto.setAssessmentResponse(new ReferenceDto(qrRef.getReferenceElement().getIdPart(), coding.getDisplay()));
            }
        }
        if (componentValue instanceof CodeableConcept) {
            CodeableConcept outcome = (CodeableConcept) componentValue;
            taskDto.setOutcome(outcome.getText());
        }
    }
    return taskDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) PatientTaskItemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskItemDto) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Type(org.hl7.fhir.r4.model.Type) PatientTaskType(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.PatientTaskType) Coding(org.hl7.fhir.r4.model.Coding) PatientTaskCode(org.hl7.gravity.refimpl.sdohexchange.codes.PatientTaskCode) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 63 with Questionnaire

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

the class QuestionnaireRepository method findByCanonnicalUri.

public Optional<Questionnaire> findByCanonnicalUri(String uri) {
    Assert.notNull(uri, "CannonnicalUri should be specified");
    Bundle bundle = getClient().search().forResource(Questionnaire.class).where(Questionnaire.URL.matches().value(uri)).returnBundle(Bundle.class).execute();
    return Optional.ofNullable(FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().findFirst().orElse(null));
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) Bundle(org.hl7.fhir.r4.model.Bundle)

Example 64 with Questionnaire

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

the class AseessmentInfoBundleExtractor method extract.

@Override
public List<AssessmentInfoHolder> extract(Bundle bundle) {
    Map<String, Questionnaire> questionnaires = new HashMap<>();
    FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().forEach(q -> questionnaires.put(q.getUrl(), q));
    return FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().map(questionnaireResponse -> {
        List<Observation> observations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsQuestionnaireReference(observation, questionnaireResponse.getIdElement().getIdPart())).collect(Collectors.toList());
        // Observations might be derived not only from the Questionnaire, but also from other Observations.
        // If we do not include these "intermediate" observations - the link between the QuestionnaireResponse and
        // Condition will not be found.
        List<Observation> derivedObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsObservationReference(observation, observations)).collect(Collectors.toList());
        observations.addAll(derivedObservations);
        List<Condition> conditions = FhirUtil.getFromBundle(bundle, Condition.class).stream().filter(condition -> containsObservationReference(condition, observations)).collect(Collectors.toList());
        Questionnaire questionnaire = questionnaires.get(questionnaireResponse.getQuestionnaire());
        return new AssessmentInfoHolder(questionnaireResponse, questionnaire, observations, conditions);
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Collection(java.util.Collection) Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Map(java.util.Map) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) AllArgsConstructor(lombok.AllArgsConstructor) AssessmentInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder) Observation(org.hl7.fhir.r4.model.Observation) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) AssessmentInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) HashMap(java.util.HashMap) List(java.util.List) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 65 with Questionnaire

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

the class ConditionInfoBundleExtractor method extract.

@Override
public List<? extends ConditionInfoHolder> extract(Bundle bundle) {
    Map<String, Observation> allObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().collect(Collectors.toMap(observation -> observation.getIdElement().getIdPart(), Function.identity()));
    Map<String, QuestionnaireResponse> allQuestionnaireResponses = FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().collect(Collectors.toMap(qr -> qr.getIdElement().getIdPart(), Function.identity()));
    Map<String, Questionnaire> allQuestionnaires = FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().collect(Collectors.toMap(q -> q.getUrl(), Function.identity()));
    return FhirUtil.getFromBundle(bundle, Condition.class).stream().map(condition -> {
        Reference evidenceReference = condition.getEvidence().stream().map(ConditionEvidenceComponent::getDetail).flatMap(Collection::stream).findFirst().orElse(null);
        QuestionnaireResponse questionnaireResponse = null;
        Questionnaire questionnaire = null;
        List<Observation> observations = new ArrayList<>();
        if (evidenceReference != null) {
            Observation evidenceObservation = allObservations.remove(evidenceReference.getReferenceElement().getIdPart());
            observations.add(evidenceObservation);
            questionnaireResponse = allQuestionnaireResponses.get(findQuestionnaireResponseId(evidenceObservation));
            String questionnaireResponseId = questionnaireResponse.getIdElement().getIdPart();
            Iterator<Entry<String, Observation>> iterator = allObservations.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Observation> observationEntry = iterator.next();
                Observation value = observationEntry.getValue();
                if (containsQuestionnaireReference(value, questionnaireResponseId)) {
                    observations.add(value);
                    iterator.remove();
                }
            }
            questionnaire = allQuestionnaires.get(questionnaireResponse.getQuestionnaire());
        }
        return new ConditionInfoHolder(condition, questionnaire, questionnaireResponse, observations);
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Iterator(java.util.Iterator) Collection(java.util.Collection) Condition(org.hl7.fhir.r4.model.Condition) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) AllArgsConstructor(lombok.AllArgsConstructor) Observation(org.hl7.fhir.r4.model.Observation) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Entry(java.util.Map.Entry) Observation(org.hl7.fhir.r4.model.Observation) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)18 ArrayList (java.util.ArrayList)15 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)12 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)11 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)11 File (java.io.File)10 TextFile (org.hl7.fhir.utilities.TextFile)10 Test (org.junit.jupiter.api.Test)10 FileOutputStream (java.io.FileOutputStream)9 Questionnaire (org.hl7.fhir.dstu3.model.Questionnaire)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 QuestionnaireItemComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)8 IOException (java.io.IOException)7 Bundle (org.hl7.fhir.r4.model.Bundle)7 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 FileNotFoundException (java.io.FileNotFoundException)6 Extension (org.hl7.fhir.r4.model.Extension)6