Search in sources :

Example 6 with QuestionnaireResponse

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

the class ConvertService method convertToBundle.

private String convertToBundle(JSONObject questionnaireResponse, String mapUri) {
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        Element element = validationEngine.transform(questionnaireResponse.toString().getBytes(), Manager.FhirFormat.JSON, mapUri);
        new JsonParser(validationEngine.getContext()).compose(element, byteArrayOutputStream, org.hl7.fhir.r5.formats.IParser.OutputStyle.PRETTY, null);
        return byteArrayOutputStream.toString();
    } catch (IOException e) {
        throw new IllegalStateException("QuestionnaireResponse with id cannot be parsed.", e.getCause());
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonParser(org.hl7.fhir.r5.elementmodel.JsonParser)

Example 7 with QuestionnaireResponse

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

the class PatientTaskService method addQuestionnaireResponsesToTaskBundle.

private void addQuestionnaireResponsesToTaskBundle(Bundle responseBundle) {
    FhirUtil.getFromBundle(responseBundle, Task.class, Bundle.SearchEntryMode.MATCH).stream().filter(Task::hasOutput).flatMap(t -> t.getOutput().stream()).forEach(c -> {
        Coding coding = FhirUtil.findCoding(Lists.newArrayList(c.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
        if (coding != null) {
            String questionnaireResponseId = ((Reference) c.getValue()).getReferenceElement().getIdPart();
            Bundle questionnaireResponse = ehrClient.search().forResource(QuestionnaireResponse.class).where(BaseResource.RES_ID.exactly().codes(questionnaireResponseId)).returnBundle(Bundle.class).execute();
            FhirUtil.mergeBundles(ehrClient.getFhirContext(), responseBundle, questionnaireResponse);
        }
    });
}
Also used : PatientSocialRiskTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientSocialRiskTaskPrepareBundleFactory) PatientTaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.PatientTaskBundleToDtoConverter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) PatientTaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.PatientTaskUpdateBundleFactory) PatientSocialRiskTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientSocialRiskTaskBundleFactory) Reference(org.hl7.fhir.r4.model.Reference) BaseResource(org.hl7.fhir.r4.model.BaseResource) SDCTemporaryCode(org.hl7.gravity.refimpl.sdohexchange.codes.SDCTemporaryCode) PatientTaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto) Task(org.hl7.fhir.r4.model.Task) UpdateTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto) PatientTaskQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.PatientTaskQueryFactory) Lists(com.google.common.collect.Lists) PatientSocialRiskTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientSocialRiskTaskPrepareBundleExtractor) Service(org.springframework.stereotype.Service) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) PatientTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientTaskBundleFactory) PatientMakeContactTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskPrepareBundleFactory) UserDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) NewFeedbackTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewFeedbackTaskRequestDto) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) NewSocialRiskTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewSocialRiskTaskRequestDto) PatientFeedbackTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientFeedbackTaskBundleFactory) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) PatientMakeContactTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskBundleFactory) Objects(java.util.Objects) NewMakeContactTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewMakeContactTaskRequestDto) NewPatientTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewPatientTaskRequestDto) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) PatientFeedbackTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientFeedbackTaskPrepareBundleExtractor) PatientFeedbackTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientFeedbackTaskPrepareBundleFactory) List(java.util.List) Coding(org.hl7.fhir.r4.model.Coding) PatientTaskBundleToItemDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.PatientTaskBundleToItemDtoConverter) SmartOnFhirContext(com.healthlx.smartonfhir.core.SmartOnFhirContext) Bundle(org.hl7.fhir.r4.model.Bundle) PatientTaskItemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskItemDto) PatientMakeContactTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientMakeContactTaskPrepareBundleExtractor) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Assert(org.springframework.util.Assert) Task(org.hl7.fhir.r4.model.Task) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 8 with QuestionnaireResponse

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

the class AssessmentService method search.

public AssessmentDto search(String questionnaireUrl) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    Bundle responseBundle = searchAssessmentQuery().where(QuestionnaireResponse.QUESTIONNAIRE.hasId(questionnaireUrl)).returnBundle(Bundle.class).execute();
    responseBundle = addQuestionnairesToAssessmentBundle(responseBundle);
    return new AssessmentBundleToDtoConverter().convert(responseBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(String.format("Resource of type QuestionnaireResponse with " + "questionnaire url '%s' is not known", questionnaireUrl)));
}
Also used : AssessmentBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.AssessmentBundleToDtoConverter) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Example 9 with QuestionnaireResponse

use of org.hl7.fhir.dstu2.model.QuestionnaireResponse in project integration-adaptor-111 by nhsconnect.

the class CompositionMapper method mapComposition.

public Composition mapComposition(POCDMT000002UK01ClinicalDocument1 clinicalDocument, Encounter encounter, List<CarePlan> carePlans, List<QuestionnaireResponse> questionnaireResponseList, ReferralRequest referralRequest, List<PractitionerRole> practitionerRoles) {
    Composition composition = new Composition();
    composition.setIdElement(resourceUtil.newRandomUuid());
    Identifier docIdentifier = new Identifier();
    docIdentifier.setUse(USUAL);
    docIdentifier.setValue(clinicalDocument.getSetId().getRoot());
    composition.setTitle(COMPOSITION_TITLE).setType(createCodeableConcept()).setStatus(FINAL).setEncounter(resourceUtil.createReference(encounter)).setSubject(encounter.getSubject()).setDateElement(DateUtil.parse(clinicalDocument.getEffectiveTime().getValue())).setIdentifier(docIdentifier);
    if (clinicalDocument.getConfidentialityCode().isSetCode()) {
        composition.setConfidentiality(Composition.DocumentConfidentiality.valueOf(clinicalDocument.getConfidentialityCode().getCode()));
    }
    if (isNotEmpty(clinicalDocument.getRelatedDocumentArray()) && clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).isSetRoot()) {
        Identifier relatedDocIdentifier = new Identifier();
        relatedDocIdentifier.setUse(USUAL);
        relatedDocIdentifier.setValue(clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).getRoot());
        composition.addRelatesTo().setCode(Composition.DocumentRelationshipType.REPLACES).setTarget(relatedDocIdentifier);
    }
    practitionerRoles.stream().forEach(it -> composition.addAuthor(it.getPractitioner()));
    if (clinicalDocument.getComponent().isSetStructuredBody()) {
        for (POCDMT000002UK01Component3 component3 : clinicalDocument.getComponent().getStructuredBody().getComponentArray()) {
            SectionComponent sectionComponent = new SectionComponent();
            addSectionChildren(sectionComponent, component3.getSection());
            composition.addSection(sectionComponent);
        }
    }
    for (CarePlan carePlan : carePlans) {
        composition.addSection(buildSectionComponentFromResource(carePlan));
    }
    if (!referralRequest.isEmpty()) {
        composition.addSection(buildSectionComponentFromResource(referralRequest));
    }
    if (questionnaireResponseList != null) {
        addPathwaysToSection(composition, questionnaireResponseList);
    }
    return composition;
}
Also used : Composition(org.hl7.fhir.dstu3.model.Composition) CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Identifier(org.hl7.fhir.dstu3.model.Identifier) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) SectionComponent(org.hl7.fhir.dstu3.model.Composition.SectionComponent)

Example 10 with QuestionnaireResponse

use of org.hl7.fhir.dstu2.model.QuestionnaireResponse in project integration-adaptor-111 by nhsconnect.

the class CompositionMapperTest method setUp.

@BeforeEach
public void setUp() {
    effectiveTime.setValue(EFFECTIVE_DATE);
    questionnaireResponseList = new ArrayList<>();
    questionnaireResponseList.add(questionnaireResponse);
    POCDMT000002UK01RelatedDocument1[] relatedDocsArray = { mock(POCDMT000002UK01RelatedDocument1.class) };
    when(clinicalDocument.getRelatedDocumentArray()).thenReturn(relatedDocsArray);
    when(clinicalDocument.getRelatedDocumentArray(0)).thenReturn(relatedDocument1);
    when(relatedDocument1.getParentDocument()).thenReturn(parentDocument1);
    when(parentDocument1.getIdArray(0)).thenReturn(ii);
    when(clinicalDocument.getSetId()).thenReturn(ii);
    when(clinicalDocument.getEffectiveTime()).thenReturn(effectiveTime);
    when(ii.getRoot()).thenReturn("411910CF-1A76-4330-98FE-C345DDEE5553");
    when(clinicalDocument.getConfidentialityCode()).thenReturn(ce);
    when(ce.getCode()).thenReturn("V");
    when(ce.isSetCode()).thenReturn(true);
    when(ii.isSetRoot()).thenReturn(true);
    when(referralRequest.fhirType()).thenReturn("ReferralRequest");
    when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
    when(resourceUtil.createReference(encounter)).thenReturn(new Reference(encounter));
    when(resourceUtil.createReference(questionnaireResponse)).thenReturn(new Reference(questionnaireResponse));
    when(resourceUtil.createReference(carePlan)).thenReturn(new Reference(carePlan));
    when(resourceUtil.createReference(referralRequest)).thenReturn(new Reference(referralRequest));
    mockStructuredBody();
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) POCDMT000002UK01RelatedDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01RelatedDocument1) IdType(org.hl7.fhir.dstu3.model.IdType) BeforeEach(org.junit.jupiter.api.BeforeEach)

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