use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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());
}
}
use of org.hl7.fhir.r4b.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.");
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
Aggregations