Search in sources :

Example 56 with Questionnaire

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

the class ExtractProvider method createObservationBundle.

private Bundle createObservationBundle(QuestionnaireResponse questionnaireResponse) {
    Bundle newBundle = new Bundle();
    Date authored = questionnaireResponse.getAuthored();
    Identifier bundleId = new Identifier();
    bundleId.setValue("QuestionnaireResponse/" + questionnaireResponse.getIdElement().getIdPart());
    newBundle.setType(Bundle.BundleType.TRANSACTION);
    newBundle.setIdentifier(bundleId);
    String questionnaireCanonical = questionnaireResponse.getQuestionnaire();
    if (questionnaireCanonical == null || questionnaireCanonical.isEmpty()) {
        throw new IllegalArgumentException("The QuestionnaireResponse must have the source Questionnaire specified to do extraction");
    }
    Map<String, Coding> questionnaireCodeMap = getQuestionnaireCodeMap(questionnaireCanonical);
    questionnaireResponse.getItem().stream().forEach(item -> {
        processItems(item, authored, questionnaireResponse, newBundle, questionnaireCodeMap);
    });
    return newBundle;
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Date(java.util.Date)

Example 57 with Questionnaire

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

the class ExtractProvider method getQuestionnaireCodeMap.

private Map<String, Coding> getQuestionnaireCodeMap(String questionnaireUrl) {
    String url = mySdcProperties.getExtract().getEndpoint();
    if (null == url || url.length() < 1) {
        throw new IllegalArgumentException("Unable to GET Questionnaire.  No observation.endpoint defined in sdc properties.");
    }
    String user = mySdcProperties.getExtract().getUsername();
    String password = mySdcProperties.getExtract().getPassword();
    IGenericClient client = Clients.forUrl(myFhirContext, url);
    Clients.registerBasicAuth(client, user, password);
    Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl(questionnaireUrl).execute();
    if (questionnaire == null) {
        throw new IllegalArgumentException("Unable to find resource by URL " + questionnaireUrl);
    }
    return createCodeMap(questionnaire);
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient)

Example 58 with Questionnaire

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

the class ExtractProviderIT method testExtract_noQuestionnaireReference_throwsException.

@Test
public void testExtract_noQuestionnaireReference_throwsException() throws IOException {
    QuestionnaireResponse test = (QuestionnaireResponse) getFhirContext().newJsonParser().parseResource(stringFromResource("mypain-questionnaire-response-no-url.json"));
    Parameters params = new Parameters();
    params.addParameter().setName("questionnaireResponse").setResource(test);
    assertThrows(InternalErrorException.class, () -> {
        getClient().operation().onType(QuestionnaireResponse.class).named("$extract").withParameters(params).returnResourceType(Bundle.class).execute();
    });
}
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 59 with Questionnaire

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

the class CanonicalsTest method partialCanonicalType.

@Test
public void partialCanonicalType() {
    CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example");
    assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl));
    assertEquals("Questionnaire", Canonicals.getResourceType(testUrl));
    assertEquals("example", Canonicals.getIdPart(testUrl));
    assertNull(Canonicals.getVersion(testUrl));
    assertNull(Canonicals.getFragment(testUrl));
}
Also used : CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test)

Example 60 with Questionnaire

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

the class CanonicalsTest method fullCanonicalType.

@Test
public void fullCanonicalType() {
    CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example|1.0#vs1");
    assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl));
    assertEquals("example", Canonicals.getIdPart(testUrl));
    assertEquals("1.0", Canonicals.getVersion(testUrl));
    assertEquals("vs1", Canonicals.getFragment(testUrl));
}
Also used : CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test)

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