Search in sources :

Example 66 with Questionnaire

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

the class ConvertService method convert.

public Map<String, Object> convert(JSONObject questionnaireResponse) throws IOException {
    QuestionnaireResponse qs = (QuestionnaireResponse) fhirContext.newJsonParser().parseResource(questionnaireResponse.toString());
    if (qs.getQuestionnaire() == null) {
        throw new IllegalStateException(String.format("QuestionnaireResponse '%s' does not contain a link to a Questionnaire.", qs.getIdElement().getIdPart()));
    }
    Optional<Questionnaire> foundQuestionnaire = questionnaireRepository.findByCanonnicalUri(qs.getQuestionnaire());
    if (!foundQuestionnaire.isPresent()) {
        throw new ResourceNotFoundException(String.format("Questionnaire was not found by URL '%s'.", qs.getQuestionnaire()));
    }
    Questionnaire questionnaire = foundQuestionnaire.get();
    String mapUri = ((CanonicalType) questionnaire.getExtensionByUrl(MAP_EXTENSION).getValue()).getValueAsString();
    boolean mapExists = validationEngine.getContext().listTransforms().stream().anyMatch(map -> map.getUrl().equals(mapUri));
    if (!mapExists) {
        loadMapIg(mapUri);
    }
    return new ObjectMapper().readValue(convertToBundle(questionnaireResponse, mapUri), Map.class);
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 67 with Questionnaire

use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.

the class QuestionnaireMapperTest method shouldMapQuestionnairePublisherName.

@Test
public void shouldMapQuestionnairePublisherName() {
    var userName = "John";
    when(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser().getName()).thenReturn(userName);
    Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
    assertThat(questionnaire.getPublisher()).isEqualTo(String.format("User name: '%s' ", userName));
}
Also used : Questionnaire(org.hl7.fhir.dstu3.model.Questionnaire) Test(org.junit.jupiter.api.Test)

Example 68 with Questionnaire

use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.

the class QuestionnaireMapperTest method shouldMapQuestionnairePublisherId.

@Test
public void shouldMapQuestionnairePublisherId() {
    var userId = "123456";
    when(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser().getId()).thenReturn(userId);
    Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
    assertThat(questionnaire.getPublisher()).isEqualTo(String.format("User ID: '%s' ", userId));
}
Also used : Questionnaire(org.hl7.fhir.dstu3.model.Questionnaire) Test(org.junit.jupiter.api.Test)

Example 69 with Questionnaire

use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.

the class QuestionnaireResponseMapper method mapQuestionnaireResponse.

public QuestionnaireResponse mapQuestionnaireResponse(PathwaysCase pathwaysCase, Reference patient, Reference encounter, TriageLine triageLine) {
    QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
    Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
    questionnaireResponse.setIdElement(resourceUtil.newRandomUuid());
    questionnaireResponse.setQuestionnaire(resourceUtil.createReference(questionnaire)).setQuestionnaireTarget(questionnaire).setStatus(QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED).setSubject(patient).setContext(encounter);
    if (pathwaysCase.getCaseDetails() != null) {
        if (pathwaysCase.getCaseDetails().isSetCaseId()) {
            questionnaireResponse.setIdentifier(new Identifier().setValue(pathwaysCase.getCaseDetails().getCaseId()));
        }
    }
    if (pathwaysCase.isSetCaseReceiveEnd()) {
        questionnaireResponse.setAuthored(DateUtil.parsePathwaysDate(pathwaysCase.getCaseReceiveEnd().toString()));
    }
    if (triageLine.getQuestion() != null) {
        questionnaireResponse.addItem(getItem(triageLine.getQuestion()));
    }
    return questionnaireResponse;
}
Also used : Questionnaire(org.hl7.fhir.dstu3.model.Questionnaire) Identifier(org.hl7.fhir.dstu3.model.Identifier) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse)

Example 70 with Questionnaire

use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.

the class QuestionnaireMapper method mapQuestionnaire.

public Questionnaire mapQuestionnaire(PathwaysCase pathwaysCase, TriageLine triageLine) {
    Questionnaire questionnaire = new Questionnaire();
    String publisher = getPublisher(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser());
    Date latestDate = getLatestDate(pathwaysCase);
    questionnaire.setIdElement(resourceUtil.newRandomUuid());
    questionnaire.addIdentifier(new Identifier().setValue(getCaseID(pathwaysCase))).setVersion(toIsoDateTimeString(latestDate)).setStatus(Enumerations.PublicationStatus.ACTIVE).setExperimental(false).addSubjectType("Patient").setDate(latestDate).setPublisher(publisher).setLastReviewDate(latestDate).setJurisdiction(Collections.singletonList(new CodeableConcept().setText(getCountry(pathwaysCase)))).addItem(getItem(triageLine.getQuestion(), getCaseID(pathwaysCase)));
    setContact(pathwaysCase, questionnaire);
    return questionnaire;
}
Also used : Questionnaire(org.hl7.fhir.dstu3.model.Questionnaire) Identifier(org.hl7.fhir.dstu3.model.Identifier) IsoDateTimeFormatter.toIsoDateTimeString(uk.nhs.adaptors.oneoneone.cda.report.util.IsoDateTimeFormatter.toIsoDateTimeString) Date(java.util.Date) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

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