Search in sources :

Example 1 with Function

use of org.hl7.fhir.dstu2016may.model.ExpressionNode.Function in project bunsen by cerner.

the class ConceptMaps method getConceptMap.

/**
 * Returns the concept map with the given uri and version, or null if there is no such map.
 *
 * @param uri the uri of the map to return
 * @param version the version of the map to return
 * @return the specified concept map.
 */
public ConceptMap getConceptMap(String uri, String version) {
    // Load the concept maps, which may contain zero items
    // if the map does not exist.
    // Typecast necessary to placate the Java compiler calling this Scala function.
    ConceptMap[] maps = (ConceptMap[]) this.conceptMaps.filter(functions.col("url").equalTo(lit(uri)).and(functions.col("version").equalTo(lit(version)))).head(1);
    if (maps.length == 0) {
        return null;
    } else {
        ConceptMap map = maps[0];
        Dataset<Mapping> filteredMappings = getMappings(uri, version);
        addToConceptMap(map, filteredMappings);
        return map;
    }
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap)

Example 2 with Function

use of org.hl7.fhir.dstu2016may.model.ExpressionNode.Function in project bunsen by cerner.

the class ValueSets method getValueSet.

/**
 * Returns the value set with the given uri and version, or null if there is no such value set.
 *
 * @param uri the uri of the value set to return
 * @param version the version of the value set to return
 * @return the specified value set.
 */
public ValueSet getValueSet(String uri, String version) {
    // Load the value sets, which may contain zero items if the value set does not exist
    // Typecast necessary to placate the Java compiler calling this Scala function
    ValueSet[] valueSets = (ValueSet[]) this.valueSets.filter(col("url").equalTo(lit(uri)).and(col("version").equalTo(lit(version)))).head(1);
    if (valueSets.length == 0) {
        return null;
    } else {
        ValueSet valueSet = valueSets[0];
        Dataset<Value> filteredValues = getValues(uri, version);
        addToValueSet(valueSet, filteredValues);
        return valueSet;
    }
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 3 with Function

use of org.hl7.fhir.dstu2016may.model.ExpressionNode.Function in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerV2Test method verifyDualResourceExtension.

/**
 * helper function to verify that {@link
 * gov.cms.bfd.server.war.r4.providers.BeneficiaryTransformerV2} correctly handles patient Part D
 * attributee.
 */
private void verifyDualResourceExtension(String dualId) {
    String uri = "https://bluebutton.cms.gov/resources/variables/" + dualId;
    Extension ex = TransformerTestUtilsV2.findExtensionByUrl(uri, patient.getExtension());
    assertNotNull(ex);
    Extension compare = new Extension(uri, new Coding(uri, "**", "Enrolled in Medicare A and/or B, but no Part D enrollment data for the beneficiary. (This status was indicated as 'XX' for 2006-2009)"));
    assertTrue(compare.equalsDeep(ex));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding)

Example 4 with Function

use of org.hl7.fhir.dstu2016may.model.ExpressionNode.Function in project kindling by HL7.

the class Publisher method execute.

/**
 * Entry point to the publisher. This classes Java Main() calls this function
 * to actually produce the specification
 *
 * @param folder
 * @throws IOException
 */
public void execute(String folder) throws IOException {
    tester = new PublisherTestSuites();
    page.log("Publish FHIR in folder " + folder + " @ " + Config.DATE_FORMAT().format(page.getGenDate().getTime()), LogMessageType.Process);
    if (web)
        page.log("Build final copy for HL7 web site", LogMessageType.Process);
    else
        page.log("Build local copy", LogMessageType.Process);
    if (outputdir != null) {
        page.log("Create output in " + outputdir, LogMessageType.Process);
    }
    page.log("Detected Java version: " + System.getProperty("java.version") + " from " + System.getProperty("java.home") + " on " + System.getProperty("os.arch"), LogMessageType.Process);
    try {
        tester.initialTests();
        page.setFolders(new FolderManager(folder, outputdir));
        if (!initialize(folder))
            throw new Exception("Unable to publish as preconditions aren't met");
        cache = new IniFile(page.getFolders().rootDir + "temp" + File.separator + "build.cache");
        loadSuppressedMessages(page.getFolders().rootDir);
        boolean doAny = false;
        for (String n : dates.keySet()) {
            Long d = cache.getLongProperty("dates", n);
            boolean b = d == null || (dates.get(n) > d);
            cache.setLongProperty("dates", n, dates.get(n).longValue(), null);
            buildFlags.put(n.toLowerCase(), b);
            doAny = doAny || b;
        }
        cache.save();
        if (noPartialBuild || !doAny || !(new File(page.getFolders().dstDir + "qa.html").exists()))
            // nothing - build all
            buildFlags.put("all", true);
        if (singlePage != null) {
            for (String n : buildFlags.keySet()) buildFlags.put(n, false);
            buildFlags.put("page-" + singlePage.toLowerCase(), true);
        } else if (singleResource != null) {
            for (String n : buildFlags.keySet()) buildFlags.put(n, false);
            buildFlags.put(singleResource.toLowerCase(), true);
        }
        if (!buildFlags.get("all")) {
            if (!noSound) {
                AudioUtilities.tone(1000, 10);
                AudioUtilities.tone(1400, 10);
                AudioUtilities.tone(1800, 10);
                AudioUtilities.tone(1000, 10);
                AudioUtilities.tone(1400, 10);
                AudioUtilities.tone(1800, 10);
            }
            page.log("Partial Build (if you want a full build, just run the build again)", LogMessageType.Process);
            CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
            for (String n : buildFlags.keySet()) if (buildFlags.get(n))
                b.append(n);
            page.log("  Build: " + b.toString(), LogMessageType.Process);
        } else {
            if (!noSound)
                AudioUtilities.tone(1200, 30);
            page.log("Full Build", LogMessageType.Process);
        }
        if (isGenerate && page.getBuildId() == null)
            page.setBuildId(getGitBuildId());
        page.log("Version " + page.getVersion() + "-" + page.getBuildId(), LogMessageType.Hint);
        Utilities.createDirectory(page.getFolders().dstDir);
        Utilities.deleteTempFiles();
        page.getBreadCrumbManager().parse(page.getFolders().srcDir + "hierarchy.xml");
        page.loadSnomed();
        page.loadLoinc();
        page.loadUcum();
        buildFeedsAndMaps();
        prsr.setExternals(externals);
        prsr.parse(page.getGenDate(), page.getValidationErrors());
        for (String n : page.getDefinitions().sortedResourceNames()) if (!page.getBreadCrumbManager().knowsResource(n))
            page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "hierarchy.xml", "Resource not found: " + n, IssueSeverity.ERROR));
        for (String n : prsr.getErrors()) page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "source spreadsheets", n, IssueSeverity.ERROR));
        if (web) {
            page.log("Clear Directory", LogMessageType.Process);
            Utilities.clearDirectory(page.getFolders().dstDir);
        }
        if (web || (isGenerate && buildFlags.get("all"))) {
            Utilities.createDirectory(page.getFolders().dstDir + "html");
            Utilities.createDirectory(page.getFolders().dstDir + "examples");
        }
        for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) if (!ig.isCore())
            Utilities.createDirectory(page.getFolders().dstDir + ig.getCode());
        if (buildFlags.get("all")) {
            copyStaticContent();
        }
        page.makeRenderingContext();
        loadValueSets1();
        prsr.getRegistry().commit();
        generateSCMaps();
        validate();
        processProfiles();
        checkAllOk();
        if (isGenerate) {
            produceSpecification();
            checkAllOk();
        }
        if (doValidate)
            validationProcess();
        page.saveSnomed();
        page.getWorkerContext().saveCache();
        processWarnings(false);
        if (isGenerate && buildFlags.get("all"))
            produceQA();
        if (!buildFlags.get("all")) {
            page.log("This was a Partial Build", LogMessageType.Process);
            CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
            for (String n : buildFlags.keySet()) if (buildFlags.get(n))
                b.append(n);
            page.log("  Build: " + b.toString(), LogMessageType.Process);
        } else
            page.log("This was a Full Build", LogMessageType.Process);
        if (!noSound) {
            AudioUtilities.tone(800, 10);
            AudioUtilities.tone(1000, 10);
            AudioUtilities.tone(1200, 10);
            AudioUtilities.tone(1000, 10);
            AudioUtilities.tone(800, 10);
        }
        page.log("Finished publishing FHIR @ " + Config.DATE_FORMAT().format(Calendar.getInstance().getTime()), LogMessageType.Process);
    } catch (Exception e) {
        if (!(e instanceof NullPointerException)) {
            // because NullPointerException is unexpected...
            try {
                processWarnings(e instanceof EValidationFailed);
            } catch (Exception e2) {
                page.log("  ERROR: Unable to process warnings: " + e2.getMessage(), LogMessageType.Error);
                e2.printStackTrace();
            }
        }
        if (buildFlags.containsKey("all") && !buildFlags.get("all")) {
            page.log("This was a Partial Build", LogMessageType.Process);
            CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
            for (String n : buildFlags.keySet()) if (buildFlags.get(n))
                b.append(n);
            page.log("  Build: " + b.toString(), LogMessageType.Process);
        } else
            page.log("This was a Full Build", LogMessageType.Process);
        if (!noSound) {
            AudioUtilities.tone(800, 20);
            AudioUtilities.tone(1000, 20);
            AudioUtilities.tone(1200, 20);
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e1) {
        }
        if (!noSound) {
            AudioUtilities.tone(800, 20);
            AudioUtilities.tone(1000, 20);
            AudioUtilities.tone(1200, 20);
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e1) {
        }
        if (!noSound) {
            AudioUtilities.tone(800, 20);
            AudioUtilities.tone(1000, 20);
            AudioUtilities.tone(1200, 20);
        }
        page.log("FHIR build failure @ " + Config.DATE_FORMAT().format(Calendar.getInstance().getTime()), LogMessageType.Process);
        System.out.println("Error: " + e.getMessage());
        e.printStackTrace();
        TextFile.stringToFile(StringUtils.defaultString(e.getMessage()), Utilities.path(folder, "publish", "simple-error.txt"));
        System.exit(1);
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) IniFile(org.hl7.fhir.utilities.IniFile) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EValidationFailed(org.hl7.fhir.tools.publisher.ExampleInspector.EValidationFailed) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Example 5 with Function

use of org.hl7.fhir.dstu2016may.model.ExpressionNode.Function in project kindling by HL7.

the class PageProcessor method produceStructureDefinitionExamples.

private String produceStructureDefinitionExamples(ResourceDefn resource) throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<div id=\"tabs\">\r\n");
    s.append("<ul>\r\n");
    s.append("  <li><a href=\"#tabs-1\">Base Types</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-2\">Resources</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-3\">Constraints</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-4\">Extensions</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-5\">Examples</a></li>\r\n");
    s.append("</ul>\r\n");
    s.append("<div id=\"tabs-1\">\r\n");
    // base types
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Abstract Types", "3");
    genStructureExample(s, definitions.getElementLink(), "element.profile", "element", "Element");
    genStructureExample(s, definitions.getBackboneLink(), "backboneelement.profile", "backboneelement", "BackBoneElement");
    genStructureExample(s, "resource.html", "resource.profile", "resource", "Resource");
    genStructureExample(s, "domainresource.html", "domainresource.profile", "domainresource", "DomainResource");
    genStructureExampleCategory(s, "Primitive Types", "3");
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getPrimitives().keySet());
    Collections.sort(names);
    for (String n : names) {
        DefinedCode dc = definitions.getPrimitives().get(n);
        genStructureExample(s, "datatypes.html#" + dc.getCode(), dc.getCode().toLowerCase() + ".profile", dc.getCode().toLowerCase(), dc.getCode());
    }
    genStructureExampleCategory(s, "Data Types", "3");
    names.clear();
    names.addAll(definitions.getTypes().keySet());
    names.addAll(definitions.getInfrastructure().keySet());
    Collections.sort(names);
    for (String n : names) {
        org.hl7.fhir.definitions.model.TypeDefn t = definitions.getTypes().get(n);
        if (t == null)
            t = definitions.getInfrastructure().get(n);
        genStructureExample(s, getLinkFor("", t.getName()), t.getName().toLowerCase() + ".profile", t.getName().toLowerCase(), t.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-2\">\r\n");
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Resources", "3");
    for (String n : definitions.sortedResourceNames()) {
        ResourceDefn r = definitions.getResources().get(n);
        genStructureExample(s, r.getName().toLowerCase() + ".html", r.getName().toLowerCase() + ".profile", r.getName().toLowerCase(), r.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-3\">\r\n");
    s.append("<table class=\"list\">\r\n");
    Map<String, ConstraintStructure> constraints = new HashMap<String, ConstraintStructure>();
    for (Profile pp : definitions.getPackList()) {
        for (ConstraintStructure p : pp.getProfiles()) constraints.put(p.getId(), p);
    }
    for (String rn : definitions.sortedResourceNames()) for (Profile ap : definitions.getResourceByName(rn).getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) constraints.put(p.getId(), p);
    names.clear();
    names.addAll(constraints.keySet());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            ConstraintStructure p = constraints.get(n);
            if (ig == p.getUsage()) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + p.getId().toLowerCase() + ".html", prefix + p.getId().toLowerCase() + ".profile", p.getId().toLowerCase(), p.getTitle());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-4\">\r\n");
    s.append("<table class=\"list\">\r\n");
    names.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
            if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + "extension-" + ed.getId().toLowerCase() + ".html", prefix + "extension-" + ed.getId().toLowerCase(), ed.getId().toLowerCase(), ed.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") ? ed.getUrl().substring(40) : ed.getUrl(), ed.getName());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-5\">\r\n");
    s.append("<table class=\"list\">\r\n");
    for (Example e : resource.getExamples()) {
        if (e.isRegistered() && Utilities.noString(e.getIg()))
            produceExampleListEntry(s, e, null, null);
    }
    for (Profile p : resource.getConformancePackages()) {
        for (Example e : p.getExamples()) {
            produceExampleListEntry(s, e, p, null);
        }
    }
    for (Profile p : definitions.getPackList()) {
        ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
        for (Example e : p.getExamples()) {
            String rn = e.getResourceName();
            if (Utilities.noString(rn))
                rn = e.getXml().getDocumentElement().getNodeName();
            if (rn.equals(resource.getName()))
                produceExampleListEntry(s, e, p, ig);
        }
    }
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        if (ig.getIg() != null) {
            for (ImplementationGuideDefinitionResourceComponent res : ig.getIg().getDefinition().getResource()) {
                Example e = (Example) res.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (res.hasExample() && e != null && e.getResourceName().equals(resource.getName()))
                    produceExampleListEntry(s, res, ig);
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("</div>\r\n");
    s.append("\r\n");
    s.append("<script src=\"external/jquery/jquery.js\"> </script>\r\n");
    s.append("<script src=\"jquery-ui.min.js\"> </script>\r\n");
    s.append("<script>\r\n");
    s.append("try {\r\n");
    s.append("  var currentTabIndex = sessionStorage.getItem('fhir-sdelist-tab-index');\r\n");
    s.append("}\r\n");
    s.append("catch(exception){\r\n");
    s.append("}\r\n");
    s.append("\r\n");
    s.append("if (!currentTabIndex)\r\n");
    s.append("  currentTabIndex = '0';\r\n");
    s.append("  \r\n");
    s.append("$( '#tabs' ).tabs({\r\n");
    s.append("         active: currentTabIndex,\r\n");
    s.append("         activate: function( event, ui ) {\r\n");
    s.append("             var active = $('.selector').tabs('option', 'active');\r\n");
    s.append("             currentTabIndex = ui.newTab.index();\r\n");
    s.append("             document.activeElement.blur();\r\n");
    s.append("             try {\r\n");
    s.append("               sessionStorage.setItem('fhir-sdelist-tab-index', currentTabIndex);\r\n");
    s.append("             }\r\n");
    s.append("             catch(exception){\r\n");
    s.append("             }\r\n");
    s.append("         }\r\n");
    s.append("     });\r\n");
    s.append("</script>\r\n");
    s.append("\r\n");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Aggregations

Test (org.junit.jupiter.api.Test)17 List (java.util.List)8 FhirPath (au.csiro.pathling.fhirpath.FhirPath)7 Reference (org.hl7.fhir.r4.model.Reference)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 URI (java.net.URI)6 Row (org.apache.spark.sql.Row)6 Session (org.eclipse.jetty.websocket.api.Session)6 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)6 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)6 IIdType (org.hl7.fhir.instance.model.api.IIdType)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 FhirReference (org.openmrs.module.fhir2.model.FhirReference)6 FhirTask (org.openmrs.module.fhir2.model.FhirTask)6 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)5 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)5 ArrayList (java.util.ArrayList)5