Search in sources :

Example 1 with QuestionnaireResponse

use of org.hl7.fhir.r4.model.QuestionnaireResponse in project cqf-ruler by DBCG.

the class ExtractProvider method extractObservationFromQuestionnaireResponse.

@Operation(name = "$extract", idempotent = false, type = QuestionnaireResponse.class)
public Bundle extractObservationFromQuestionnaireResponse(@OperationParam(name = "questionnaireResponse") QuestionnaireResponse questionnaireResponse) {
    if (questionnaireResponse == null) {
        throw new IllegalArgumentException("Unable to perform operation $extract.  The QuestionnaireResponse was null");
    }
    Bundle observationsFromQuestionnaireResponse = createObservationBundle(questionnaireResponse);
    sendObservationBundle(observationsFromQuestionnaireResponse);
    return observationsFromQuestionnaireResponse;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 2 with QuestionnaireResponse

use of org.hl7.fhir.r4.model.QuestionnaireResponse in project cqf-ruler by DBCG.

the class ExtractProviderIT method testExtract.

@Test
public void testExtract() throws IOException, URISyntaxException {
    String examplePatient = "example_patient.json";
    String exampleQuestionnaire = "questionnaire_1559.json";
    String exampleQR = "questionnaire_response_1558.json";
    loadResource(examplePatient);
    loadResource(exampleQuestionnaire);
    QuestionnaireResponse questionnaireResponse = (QuestionnaireResponse) loadResource(exampleQR);
    Parameters params = new Parameters();
    params.addParameter().setName("questionnaireResponse").setResource(questionnaireResponse);
    Bundle actual = getClient().operation().onType(QuestionnaireResponse.class).named("$extract").withParameters(params).returnResourceType(Bundle.class).execute();
    assertNotNull(actual);
    // Expecting one observation per item
    assertEquals(5, actual.getEntry().size());
    // Ensure the Observations were saved to the local server
    for (Bundle.BundleEntryComponent bec : actual.getEntry()) {
        assertEquals("201 Created", bec.getResponse().getStatus());
    }
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 3 with QuestionnaireResponse

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

the class TaskPollingService method demoRunQRThroughStructureMap.

/*
  A TEST polling service, implemented during January 2022 Connectathon, that automatically runs questionnaireResponse
  resources through a StructureMap. If any exception occurs - just ignore it.
   */
public void demoRunQRThroughStructureMap() {
    log.info("Looking for TOP 3 Patient QuestionnaireResponse resources without derived Observations...");
    // TODO use repository instead
    Bundle tasksBundle = openEhrClient.search().forResource(QuestionnaireResponse.class).where(new StringClientParam(Constants.PARAM_PROFILE).matches().value(SDOHProfiles.QUESTIONNAIRE_RESPONSE)).revInclude(Observation.INCLUDE_DERIVED_FROM.setRecurse(false)).sort().descending(QuestionnaireResponse.AUTHORED).count(3).returnBundle(Bundle.class).execute();
    List<QuestionnaireResponse> responses = FhirUtil.getFromBundle(tasksBundle, QuestionnaireResponse.class, Bundle.SearchEntryMode.MATCH);
    Set<String> derivedFrom = FhirUtil.getFromBundle(tasksBundle, Observation.class, Bundle.SearchEntryMode.INCLUDE).stream().map(o -> o.getDerivedFromFirstRep().getReferenceElement().getIdPart()).collect(Collectors.toSet());
    if (responses.size() != derivedFrom.size()) {
        log.info("Found " + (responses.size() - derivedFrom.size()) + " QuestionnaireResponse resources without observations.");
        List<QuestionnaireResponse> newResponses = responses.stream().filter(qr -> !derivedFrom.contains(qr.getIdElement().getIdPart())).collect(Collectors.toList());
        for (QuestionnaireResponse nr : newResponses) {
            log.info("Converting QuestionnaireResponse with id: " + nr.getIdElement().getIdPart());
            try {
                // TODO move parser logic within the convert service. Use resources instead
                JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
                Map<String, Object> result = convertService.convert((JSONObject) parser.parse(fhirContext.newJsonParser().encodeResourceToString(nr)));
                Bundle bundle = (Bundle) fhirContext.newJsonParser().parseResource(new JSONObject(result).toJSONString());
                bundle.getEntry().forEach(e -> e.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.POST).setUrl(e.getResource().getClass().getSimpleName())));
                openEhrClient.transaction().withBundle(bundle).execute();
            } catch (Exception exc) {
                // Just ignore this specific resource and go to the next one
                log.warn(exc.getMessage(), exc);
            }
        }
    }
    log.info("QuestionnaireResponse update process finished.");
}
Also used : Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Endpoint(org.hl7.fhir.r4.model.Endpoint) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Set(java.util.Set) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Organization(org.hl7.fhir.r4.model.Organization) Slf4j(lombok.extern.slf4j.Slf4j) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) List(java.util.List) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) JSONObject(net.minidev.json.JSONObject) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) JSONObject(net.minidev.json.JSONObject) Observation(org.hl7.fhir.r4.model.Observation) JSONParser(net.minidev.json.parser.JSONParser) JSONObject(net.minidev.json.JSONObject)

Example 4 with QuestionnaireResponse

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

the class AssessmentInfoToDtoConverter method convert.

@Override
public AssessmentDto convert(AssessmentInfoHolder infoHolder) {
    AssessmentDto assessmentDto = new AssessmentDto();
    QuestionnaireResponse questionnaireResponse = infoHolder.getQuestionnaireResponse();
    assessmentDto.setId(questionnaireResponse.getIdElement().getIdPart());
    if (infoHolder.getQuestionnaire() != null) {
        assessmentDto.setName(infoHolder.getQuestionnaire().getTitle());
    } else {
        assessmentDto.setName(questionnaireResponse.getQuestionnaire());
        assessmentDto.getErrors().add("QuestionnaireResponse references a Questionnaire by the URL which does not exist. Using the URL as a " + "name instead.");
    }
    assessmentDto.setQuestionnaireUrl(questionnaireResponse.getQuestionnaire());
    assessmentDto.setDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
    assessmentDto.setAssessmentResponse(assessmentResponseToDtoConverter.convert(infoHolder));
    assessmentDto.setHealthConcerns(infoHolder.getConditions().stream().map(condition -> new ReferenceDto(condition.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(condition.getCode()))).collect(Collectors.toList()));
    return assessmentDto;
}
Also used : ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) AssessmentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 5 with QuestionnaireResponse

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

the class ConditionBundleToDtoConverterBase method conditionInfoToDto.

protected T conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    T conditionDto = newConditionDtoImpl();
    Condition condition = conditionInfo.getCondition();
    conditionDto.setId(condition.getIdElement().getIdPart());
    conditionDto.setName(codeableConceptToStringConverter.convert(condition.getCode()));
    Coding categoryCoding = FhirUtil.findCoding(condition.getCategory(), SDOHMappings.getInstance().getSystem());
    // TODO remove this in future. Fow now two different categories might be used before discussed.
    if (categoryCoding == null) {
        categoryCoding = FhirUtil.findCoding(condition.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
    }
    if (categoryCoding == null) {
        conditionDto.getErrors().add("SDOH category is not found.");
    } else {
        conditionDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
    }
    Optional<Coding> icdCodeCodingOptional = findCode(condition.getCode(), System.ICD_10);
    if (icdCodeCodingOptional.isPresent()) {
        Coding icdCodeCoding = icdCodeCodingOptional.get();
        conditionDto.setIcdCode(new CodingDto(icdCodeCoding.getCode(), icdCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("ICD-10 code is not found.");
    }
    Optional<Coding> snomedCodeCodingOptional = findCode(condition.getCode(), System.SNOMED);
    if (snomedCodeCodingOptional.isPresent()) {
        Coding snomedCodeCoding = snomedCodeCodingOptional.get();
        conditionDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("SNOMED-CT code is not found.");
    }
    QuestionnaireResponse questionnaireResponse = conditionInfo.getQuestionnaireResponse();
    if (questionnaireResponse != null) {
        conditionDto.setAssessmentDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
        Questionnaire questionnaire = conditionInfo.getQuestionnaire();
        if (questionnaire != null) {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaire.getTitle()));
        } else {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaireResponse.getQuestionnaire()));
            conditionDto.getErrors().add("Based on QuestionnaireResponse doesn't have a matching Questionnaire to get a title from. Using URL " + "instead.");
        }
    } else {
        conditionDto.setBasedOn(new StringTypeDto(condition.getEvidenceFirstRep().getCodeFirstRep().getText()));
        Reference recorder = condition.getRecorder();
        conditionDto.setAuthoredBy(new ReferenceDto(recorder.getReferenceElement().getIdPart(), recorder.getDisplay()));
    }
    // abatement must be available for all resolved condition
    if (ConditionClinicalStatusCodes.RESOLVED.toCode().equals(condition.getClinicalStatus().getCodingFirstRep().getCode())) {
        if (condition.getAbatement() instanceof DateTimeType) {
            conditionDto.setResolutionDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getAbatement()));
        } else {
            conditionDto.getErrors().add("Condition is resolved but an abatement property is missing or not of a DateTimeType type.");
        }
    }
    return conditionDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Aggregations

QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)15 ArrayList (java.util.ArrayList)14 Bundle (org.hl7.fhir.r4.model.Bundle)11 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)8 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)8 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)8 Test (org.junit.jupiter.api.Test)8 Reference (org.hl7.fhir.dstu3.model.Reference)7 Reference (org.hl7.fhir.r4.model.Reference)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 Map (java.util.Map)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)5 Coding (org.hl7.fhir.r4.model.Coding)4 Date (java.util.Date)3 Getter (lombok.Getter)3 Bundle (org.hl7.fhir.dstu3.model.Bundle)3