Search in sources :

Example 6 with MetadataResource

use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpansionCache method loadCache.

private void loadCache() throws FHIRFormatError, IOException {
    File[] files = new File(cacheFolder).listFiles();
    for (File f : files) {
        if (f.getName().endsWith(".xml")) {
            final FileInputStream is = new FileInputStream(f);
            try {
                Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
                if (r instanceof OperationOutcome) {
                    OperationOutcome oo = (OperationOutcome) r;
                    expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
                } else if (r instanceof ValueSet) {
                    ValueSet vs = (ValueSet) r;
                    if (vs.hasExpansion())
                        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
                    else {
                        canonicals.put(vs.getUrl(), vs);
                        if (vs.hasVersion())
                            canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
                    }
                } else if (r instanceof MetadataResource) {
                    MetadataResource md = (MetadataResource) r;
                    canonicals.put(md.getUrl(), md);
                    if (md.hasVersion())
                        canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.r4.model.ValueSet) FileInputStream(java.io.FileInputStream)

Example 7 with MetadataResource

use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.

the class R3R4ConversionTests method loadLib.

private void loadLib(String dir) throws FileNotFoundException, IOException {
    StructureMapUtilities smu = new StructureMapUtilities(contextR4);
    for (String s : new File(dir).list()) {
        String map = TextFile.fileToString(Utilities.path(dir, s));
        try {
            StructureMap sm = smu.parse(map, s);
            contextR3.cacheResource(sm);
            contextR4.cacheResource(sm);
            for (Resource r : sm.getContained()) {
                if (r instanceof MetadataResource) {
                    MetadataResource mr = (MetadataResource) r.copy();
                    mr.setUrl(sm.getUrl() + "#" + r.getId());
                    contextR3.cacheResource(mr);
                    contextR4.cacheResource(mr);
                }
            }
        } catch (FHIRException e) {
            System.out.println("Unable to load " + Utilities.path(dir, s) + ": " + e.getMessage());
            loadErrors.put(s, e);
        // e.printStackTrace();
        }
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) StructureMap(org.hl7.fhir.r4.model.StructureMap) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapUtilities(org.hl7.fhir.r4.utils.StructureMapUtilities)

Example 8 with MetadataResource

use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method loadFromFile.

public void loadFromFile(InputStream stream, String name, IContextResourceLoader loader) throws IOException, FHIRException {
    Resource f;
    try {
        if (loader != null)
            f = loader.loadBundle(stream, false);
        else {
            XmlParser xml = new XmlParser();
            f = xml.parse(stream);
        }
    } catch (DataFormatException e1) {
        throw new org.hl7.fhir.exceptions.FHIRFormatError("Error parsing " + name + ":" + e1.getMessage(), e1);
    } catch (Exception e1) {
        throw new org.hl7.fhir.exceptions.FHIRFormatError("Error parsing " + name + ":" + e1.getMessage(), e1);
    }
    if (f instanceof Bundle) {
        Bundle bnd = (Bundle) f;
        for (BundleEntryComponent e : bnd.getEntry()) {
            if (e.getFullUrl() == null) {
                logger.logDebugMessage(LogCategory.CONTEXT, "unidentified resource in " + name + " (no fullUrl)");
            }
            cacheResource(e.getResource());
        }
    } else if (f instanceof MetadataResource) {
        MetadataResource m = (MetadataResource) f;
        cacheResource(m);
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) XmlParser(org.hl7.fhir.r4.formats.XmlParser) DataFormatException(ca.uhn.fhir.parser.DataFormatException) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 9 with MetadataResource

use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method AddVsRef.

private void AddVsRef(ResourceContext rcontext, String value, XhtmlNode li) {
    Resource res = rcontext == null ? null : rcontext.resolve(value);
    if (res != null && !(res instanceof MetadataResource)) {
        li.addText(value);
        return;
    }
    MetadataResource vs = (MetadataResource) res;
    if (vs == null)
        vs = context.fetchResource(ValueSet.class, value);
    if (vs == null)
        vs = context.fetchResource(StructureDefinition.class, value);
    // vs = context.fetchResource(DataElement.class, value);
    if (vs == null)
        vs = context.fetchResource(Questionnaire.class, value);
    if (vs != null) {
        String ref = (String) vs.getUserData("path");
        ref = adjustForPath(ref);
        XhtmlNode a = li.ah(ref == null ? "??" : ref.replace("\\", "/"));
        a.addText(value);
    } else {
        CodeSystem cs = context.fetchCodeSystem(value);
        if (cs != null) {
            String ref = (String) cs.getUserData("path");
            ref = adjustForPath(ref);
            XhtmlNode a = li.ah(ref == null ? "??" : ref.replace("\\", "/"));
            a.addText(value);
        } else if (value.equals("http://snomed.info/sct") || value.equals("http://snomed.info/id")) {
            XhtmlNode a = li.ah(value);
            a.tx("SNOMED-CT");
        } else {
            if (value.startsWith("http://hl7.org") && !Utilities.existsInList(value, "http://hl7.org/fhir/sid/icd-10-us"))
                System.out.println("Unable to resolve value set " + value);
            li.addText(value);
        }
    }
}
Also used : CodeSystem(org.hl7.fhir.r4.model.CodeSystem) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 10 with MetadataResource

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

the class MeasureImporter method convertToBundle.

/**
 * Given a ZIP artifact convert the contents into a FHIR bundle
 *
 * @param is InputStream containing artifacts to import
 * @return FHIR bundle
 * @throws Exception any error
 */
public Bundle convertToBundle(InputStream is) throws Exception {
    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry entry;
    Bundle bundle = new Bundle();
    bundle.setType(Bundle.BundleType.TRANSACTION);
    while ((entry = zis.getNextEntry()) != null) {
        if (isDeployable(entry)) {
            IBaseResource resource = parser.parseResource(zis);
            if (resource instanceof MetadataResource) {
                MetadataResource metadataResource = (MetadataResource) resource;
                if (metadataResource.hasName() && metadataResource.hasUrl() && metadataResource.hasVersion()) {
                    if (!metadataResource.hasId()) {
                        metadataResource.setId(idStrategy.generateId(metadataResource));
                    }
                    String url = metadataResource.fhirType() + "/" + metadataResource.getId();
                    bundle.addEntry().setFullUrl(url).setResource(metadataResource).getRequest().setUrl(url).setMethod(Bundle.HTTPVerb.PUT);
                } else {
                    throw new IllegalArgumentException("Knowledge resources must specify at least name, version, and url");
                }
            }
        }
    }
    return bundle;
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) ZipInputStream(java.util.zip.ZipInputStream) Bundle(org.hl7.fhir.r4.model.Bundle) ZipEntry(java.util.zip.ZipEntry) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Aggregations

MetadataResource (org.hl7.fhir.r4.model.MetadataResource)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 IOException (java.io.IOException)6 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)4 URISyntaxException (java.net.URISyntaxException)3 Resource (org.hl7.fhir.dstu3.model.Resource)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 Resource (org.hl7.fhir.r4.model.Resource)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2 UUID (java.util.UUID)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2