Search in sources :

Example 11 with MetadataResource

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

the class SHA256NameVersionIdStrategyTest method max_name_version_length___output_meets_fhir_constraints.

@Test
public void max_name_version_length___output_meets_fhir_constraints() throws Exception {
    String name = RandomStringUtils.random(256, /*useLetters=*/
    true, /*useNumbers=*/
    true);
    // There is no defined upper limit here, but we are guessing
    // that three digits for each dotted triplet entry +
    // delimiter + some label stuff isn't much bigger than this
    String version = RandomStringUtils.random(20, /*useLetters=*/
    true, /*useNumbers=*/
    true);
    ;
    MetadataResource resource = new Measure();
    resource.setName(name);
    resource.setVersion(version);
    String generated = strategy.generateId(resource);
    assertTrue(generated.matches("[A-Za-z0-9\\-\\.]{1,64}"));
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) Measure(org.hl7.fhir.r4.model.Measure) Test(org.junit.Test)

Example 12 with MetadataResource

use of org.hl7.fhir.r4.model.MetadataResource in project kindling by HL7.

the class SourceParser method loadResource.

private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
    String folder = n;
    WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
    if (wg == null)
        throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
    File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
    if (isTemplate) {
        File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
        OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        ResourceDefn root;
        try {
            root = sparser.parseResource(isTemplate);
        } catch (Exception e) {
            throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
        }
        root.setAbstract(isAbstract);
        root.setInterface(isInterface);
        errors.addAll(sparser.getErrors());
        setResourceProps(n, wg, root);
        String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
        if (sc != null) {
            root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
        } else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
            throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
        for (EventDefn e : sparser.getEvents()) {
            processEvent(e, root.getRoot());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
            context.getResourceNames().add(root.getName());
        }
        if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
            root.setStatus(StandardsStatus.NORMATIVE);
        }
        if (f.exists()) {
            parseSvgFile(f, root.getLayout(), f.getName());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        return root;
    } else {
        try {
            new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
        } catch (Exception e) {
            System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
        }
        new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
        ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
        if (f.exists()) {
            parseSvgFile(f, rootNew.getLayout(), f.getName());
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
            context.getResourceNames().add(rootNew.getName());
        }
        setResourceProps(n, wg, rootNew);
        if (map != null) {
            map.put(rootNew.getName(), rootNew);
        }
        return rootNew;
    }
}
Also used : SpreadSheetCreator(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetCreator) EventDefn(org.hl7.fhir.definitions.model.EventDefn) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SpreadSheetReloader(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 13 with MetadataResource

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

the class R3ToR4Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r3 = null;
    if (isJson)
        r3 = new JsonParser().parse(stream);
    else
        r3 = new XmlParser().parse(stream);
    org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_30_40.convertResource(r3, advisor);
    Bundle b;
    if (r4 instanceof Bundle)
        b = (Bundle) r4;
    else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
    }
    for (CodeSystem cs : advisor.getCslist()) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU3));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
                for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
                for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) Resource(org.hl7.fhir.dstu3.model.Resource) ArrayList(java.util.ArrayList) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Example 14 with MetadataResource

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

the class R2ToR4Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_10_40.convertResource(r2, advisor);
    Bundle b;
    if (r4 instanceof Bundle) {
        b = (Bundle) r4;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
    }
    // Add any code systems defined as part of processing value sets to the end of the converted Bundle
    advisor.getCslist().forEach(cs -> {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    });
    advisor.getCslist().clear();
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        b.getEntry().stream().filter(be -> be.hasResource() && be.getResource() instanceof StructureDefinition).map(be -> (StructureDefinition) be.getResource()).forEach(sd -> {
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
        });
    }
    return b;
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) StructureDefinitionKind(org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) VersionConvertorFactory_10_40(org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40) IOException(java.io.IOException) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) UUID(java.util.UUID) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) ArrayList(java.util.ArrayList) List(java.util.List) Resource(org.hl7.fhir.dstu2.model.Resource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) UriType(org.hl7.fhir.r4.model.UriType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) InputStream(java.io.InputStream) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.dstu2.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.r4.model.UriType) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 15 with MetadataResource

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

the class R2016MayToR4Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2016may = null;
    if (isJson)
        r2016may = new JsonParser().parse(stream);
    else
        r2016may = new XmlParser().parse(stream);
    org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_14_40.convertResource(r2016may, advisor);
    Bundle b;
    if (r4 instanceof Bundle)
        b = (Bundle) r4;
    else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
    }
    for (CodeSystem cs : advisor.getCslist()) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    for (BundleEntryComponent be : b.getEntry()) {
        if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) be.getResource();
            new ProfileUtilities(null, null, null).setIds(sd, false);
            if (patchUrls) {
                sd.setUrl(sd.getUrl().replace(URL_BASE, "http://hl7.org/fhir/2016May/"));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) Resource(org.hl7.fhir.dstu2016may.model.Resource) ArrayList(java.util.ArrayList) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) JsonParser(org.hl7.fhir.dstu2016may.formats.JsonParser)

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