Search in sources :

Example 1 with MetadataResource

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

the class ExampleInspector method fetch.

@Override
public Element fetch(IResourceValidator validator, Object appContext, String url) throws IOException, FHIRException {
    String[] parts = url.split("\\/");
    if (parts.length == 2 && definitions.hasResource(parts[0])) {
        ResourceDefn r = definitions.getResourceByName(parts[0]);
        for (Example e : r.getExamples()) {
            if (e.getElement() == null && e.hasXml()) {
                e.setElement(new org.hl7.fhir.r5.elementmodel.XmlParser(context).parse(e.getXml()));
                if (e.getElement().getProperty().getStructure().getBaseDefinition().contains("MetadataResource")) {
                    String urle = e.getElement().getChildValue("url");
                    String v = e.getElement().getChildValue("url");
                    if (urle != null && urle.startsWith("http://hl7.org/fhir") && !version.toCode().equals(v)) {
                        e.getElement().setChildValue("version", version.toCode());
                    }
                }
            }
            if (e.getElement() != null) {
                if (e.getElement().fhirType().equals("Bundle")) {
                    for (Base b : e.getElement().listChildrenByName("entry")) {
                        if (b.getChildByName("resource").hasValues()) {
                            Element res = (Element) b.getChildByName("resource").getValues().get(0);
                            if (res.fhirType().equals(parts[0]) && parts[1].equals(res.getChildValue("id"))) {
                                return res;
                            }
                        }
                    }
                } else if (e.getElement().fhirType().equals(parts[0]) && e.getId().equals(parts[1])) {
                    return e.getElement();
                }
            }
        }
        try {
            if (parts[0].equals("StructureDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(StructureDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("OperationDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(OperationDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("SearchParameter"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(SearchParameter.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("ValueSet"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(ValueSet.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("CodeSystem"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(CodeSystem.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
        } catch (Exception e) {
            return null;
        }
        return null;
    } else
        return null;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) Example(org.hl7.fhir.definitions.model.Example) Element(org.hl7.fhir.r5.elementmodel.Element) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Base(org.hl7.fhir.r5.model.Base) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with MetadataResource

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

the class SHA256NameVersionIdStrategyTest method different_versions_same_name___output_different_ids.

@Test
public void different_versions_same_name___output_different_ids() throws Exception {
    String name = "COL-InitialPopulation";
    List<String> versions = Arrays.asList("1.0.0", "1.2.0", "2.1.0");
    Set<String> ids = new HashSet<>();
    for (String version : versions) {
        MetadataResource resource = new Measure();
        resource.setName(name);
        resource.setVersion(version);
        ids.add(strategy.generateId(resource));
    }
    assertEquals(versions.size(), ids.size());
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) Measure(org.hl7.fhir.r4.model.Measure) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with MetadataResource

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

the class SHA256NameVersionIdStrategyTest method same_input_multiple_times___always_same_output.

@Test
public void same_input_multiple_times___always_same_output() throws Exception {
    String name = "COL-Denominator";
    String version = "1.1.0";
    MetadataResource resource = new Measure();
    resource.setName(name);
    resource.setVersion(version);
    Set<String> ids = new HashSet<>();
    for (int i = 0; i < 1000; i++) {
        ids.add(strategy.generateId(resource));
    }
    assertEquals(1, ids.size());
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) Measure(org.hl7.fhir.r4.model.Measure) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with MetadataResource

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

the class R2ToR3Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_10_30.convertResource(r2, advisor_10_30);
    Bundle b;
    if (r3 instanceof Bundle) {
        b = (Bundle) r3;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r3).setFullUrl(r3 instanceof MetadataResource ? ((MetadataResource) r3).getUrl() : null);
    }
    advisor_10_30.getCslist().forEach(cs -> {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    });
    advisor_10_30.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.dstu3.model.MetadataResource) StructureDefinitionKind(org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser) Bundle(org.hl7.fhir.dstu3.model.Bundle) VersionConvertorFactory_10_30(org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) UriType(org.hl7.fhir.dstu3.model.UriType) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) BaseAdvisor_10_30(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30) IOException(java.io.IOException) UUID(java.util.UUID) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) ArrayList(java.util.ArrayList) List(java.util.List) Resource(org.hl7.fhir.dstu2.model.Resource) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) InputStream(java.io.InputStream) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Bundle(org.hl7.fhir.dstu3.model.Bundle) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu2.model.Resource) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.dstu3.model.UriType) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 5 with MetadataResource

use of org.hl7.fhir.r4.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 : MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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