Search in sources :

Example 16 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProviderIT method testActivityDefinitionApply.

@Test
public void testActivityDefinitionApply() throws Exception {
    DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request");
    // Patient First
    Map<String, IBaseResource> resources = uploadTests("test/activitydefinition/Patient");
    IBaseResource patient = resources.get("ExamplePatient");
    Resource applyResult = activityDefinitionApplyProvider.apply(new SystemRequestDetails(), activityDefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
    assertTrue(applyResult instanceof ProcedureRequest);
    assertEquals("454281000124100", ((ProcedureRequest) applyResult).getCode().getCoding().get(0).getCode());
}
Also used : DomainResource(org.hl7.fhir.dstu3.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Resource(org.hl7.fhir.dstu3.model.Resource) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 17 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testDefinesOnMeasureReport.

@Test
public void testDefinesOnMeasureReport() {
    MeasureReport report = new MeasureReport();
    Map<VersionedIdentifier, Map<String, Object>> expectedResults = setupTestExpectedResultsContext();
    CDMContext defineContext = setupTestDefineContext(expectedResults);
    CDMMeasureEvaluation.addDefineEvaluationToReport(report, defineContext, DefineReturnOptions.ALL);
    assertEquals(5, report.getExtension().size());
    int index = 0;
    for (Entry<VersionedIdentifier, Map<String, Object>> expectedLibraryResults : expectedResults.entrySet()) {
        for (Entry<String, Object> defineResult : expectedLibraryResults.getValue().entrySet()) {
            Extension extension = report.getExtension().get(index++);
            assertEquals(MeasureEvidenceHelper.createEvidenceKey(expectedLibraryResults.getKey(), defineResult.getKey()), extension.getExtensionByUrl(CDMConstants.EVIDENCE_TEXT_URL).getValue().primitiveValue());
            // hack because Type does not return equals for 2 identical objects :(
            Type returnType = extension.getExtensionByUrl(CDMConstants.EVIDENCE_VALUE_URL).getValue();
            if (defineResult.getValue() instanceof Boolean) {
                assertTrue(returnType.isBooleanPrimitive());
                assertEquals(defineResult.getValue(), ((BooleanType) returnType).booleanValue());
            } else if (defineResult.getValue() instanceof String) {
                assertTrue(returnType.isPrimitive());
                assertEquals(defineResult.getValue(), returnType.primitiveValue());
            } else if (defineResult.getValue() instanceof DomainResource) {
                assertTrue(returnType instanceof Reference);
            }
        }
    }
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) Reference(org.hl7.fhir.r4.model.Reference) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Extension(org.hl7.fhir.r4.model.Extension) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Type(org.hl7.fhir.r4.model.Type) BooleanType(org.hl7.fhir.r4.model.BooleanType) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) Test(org.junit.Test)

Example 18 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method addReference.

protected String addReference(DomainResource r, String title, String id) throws Exception {
    if (r.getText() == null)
        r.setText(new Narrative());
    if (r.getText().getDiv() == null) {
        r.getText().setStatus(NarrativeStatus.GENERATED);
        new NarrativeGenerator("", "", context).generate(r);
    }
    r.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
    r.setId(id);
    feed.getEntry().add(new BundleEntryComponent().setResource(r));
    return id;
}
Also used : NarrativeGenerator(org.hl7.fhir.dstu3.utils.NarrativeGenerator) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)

Example 19 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method saveResource.

private void saveResource(Resource resource, String extraType) throws Exception {
    if (!WANT_SAVE)
        return;
    DomainResource dr = null;
    if (resource instanceof DomainResource) {
        dr = (DomainResource) resource;
        if (!dr.hasText()) {
            NarrativeGenerator generator = new NarrativeGenerator("", "", context);
            generator.generate(dr);
        }
    }
    XmlParser xparser = new XmlParser();
    xparser.setOutputStyle(OutputStyle.PRETTY);
    JsonParser jparser = new JsonParser();
    jparser.setOutputStyle(OutputStyle.PRETTY);
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    xparser.compose(ba, resource);
    ba.close();
    byte[] srcX = ba.toByteArray();
    ba = new ByteArrayOutputStream();
    jparser.compose(ba, resource);
    ba.close();
    byte[] srcJ = ba.toByteArray();
    String rn = resource.getResourceType().toString();
    if (extraType != null)
        rn = rn + extraType;
    zipX.addBytes(resource.getId() + ".xml", srcX, false);
    zipJ.addBytes(resource.getId() + ".json", srcJ, false);
    if (!zipsX.containsKey(rn)) {
        zipsX.put(rn, new ZipGenerator(Utilities.path(destFolder, "xml/type", rn + ".xml.zip")));
        zipsJ.put(rn, new ZipGenerator(Utilities.path(destFolder, "json/type", rn + ".json.zip")));
        stats.put(rn, new Stats());
    }
    zipsJ.get(rn).addBytes(resource.getId() + ".json", srcJ, false);
    zipsX.get(rn).addBytes(resource.getId() + ".xml", srcX, false);
    Stats ss = stats.get(rn);
    ss.setInstances(ss.getInstances() + 1);
    String profile = resource.getUserString("profile");
    validate(srcX, profile, resource, ss);
}
Also used : NarrativeGenerator(org.hl7.fhir.dstu3.utils.NarrativeGenerator) XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Example 20 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateDocumentNarrative.

public XhtmlNode generateDocumentNarrative(Bundle feed) {
    /*
     When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
     * The Composition resource
     * The Subject resource
     * Resources referenced in the section.content
     */
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    Composition comp = (Composition) feed.getEntry().get(0).getResource();
    root.getChildNodes().add(comp.getText().getDiv());
    Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
    if (subject != null && subject instanceof DomainResource) {
        root.addTag("hr");
        root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
    }
    List<SectionComponent> sections = comp.getSection();
    renderSections(feed, root, sections, 1);
    return root;
}
Also used : Composition(org.hl7.fhir.dstu2.model.Composition) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) SectionComponent(org.hl7.fhir.dstu2.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 DomainResource (org.hl7.fhir.r4.model.DomainResource)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 IOException (java.io.IOException)15 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)15 FileOutputStream (java.io.FileOutputStream)12 ArrayList (java.util.ArrayList)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Test (org.junit.jupiter.api.Test)11 Resource (org.hl7.fhir.r4.model.Resource)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 FileNotFoundException (java.io.FileNotFoundException)8 List (java.util.List)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)7 File (java.io.File)7 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)7