Search in sources :

Example 71 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.

the class Publisher method getSnapShotForProfile.

public StructureDefinition getSnapShotForProfile(String base) throws Exception {
    String[] parts = base.split("#");
    if (parts[0].startsWith("http://hl7.org/fhir/StructureDefinition/") && parts.length == 1) {
        String name = base.substring(40);
        if (page.getDefinitions().hasResource(name))
            return page.getDefinitions().getSnapShotForType(name);
        else if (page.getDefinitions().hasType(name)) {
            TypeDefn t = page.getDefinitions().getElementDefn(name);
            if (t.getProfile().hasSnapshot())
                return t.getProfile();
            throw new Exception("unable to find snapshot for " + name);
        }
    // else
    // throw new Exception("unable to find base definition for "+name);
    }
    StructureDefinition p = new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).getProfile(null, parts[0]);
    if (p == null)
        throw new Exception("unable to find base definition for " + base);
    if (parts.length == 1) {
        if (p.getSnapshot() == null)
            // or else we could fill it in?
            throw new Exception("StructureDefinition " + base + " has no snapshot");
        return p;
    }
    for (Resource r : p.getContained()) {
        if (r instanceof StructureDefinition && r.getId().equals(parts[1])) {
            StructureDefinition pc = (StructureDefinition) r;
            if (pc.getSnapshot() == null) {
                StructureDefinition ps = getSnapShotForProfile(pc.getBaseDefinition());
                processProfile(pc);
            }
            return pc;
        }
    }
    throw new Exception("Unable to find snapshot for " + base);
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 72 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.

the class Publisher method processProfile.

private void processProfile(StructureDefinition ae) throws Exception {
    if (ae.getDate() == null)
        ae.setDate(page.getGenDate().getTime());
    if (ae.hasBaseDefinition() && ae.hasSnapshot()) {
        // cause it probably doesn't, coming from the profile directly
        StructureDefinition base = getIgProfile(ae.getBaseDefinition());
        if (base == null)
            base = new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).getProfile(null, ae.getBaseDefinition());
        new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSnapshot(base, ae, ae.getBaseDefinition().split("#")[0], "http://hl7.org/fhir", ae.getName());
        if (page.getProfiles().has(ae.getUrl()))
            throw new Exception("Duplicate Profile URL " + ae.getUrl());
        page.getProfiles().see(ae, page.packageInfo());
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 73 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.

the class R2016MayToR5Loader 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.r5.model.Resource r5 = VersionConvertorFactory_14_50.convertResource(r2016may, advisor);
    Bundle b;
    if (r5 instanceof Bundle)
        b = (Bundle) r5;
    else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).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, URL_DSTU2016MAY));
                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.r5.model.Bundle.BundleEntryComponent) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) JsonParser(org.hl7.fhir.dstu2016may.formats.JsonParser)

Example 74 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities 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)

Example 75 with ProfileUtilities

use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method generateSnapshot.

public void generateSnapshot(StructureDefinition p) throws DefinitionException, FHIRException {
    if (!p.hasSnapshot() && p.getKind() != StructureDefinitionKind.LOGICAL) {
        if (!p.hasBaseDefinition())
            throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") has no base and no snapshot");
        StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
        if (sd == null)
            throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") base " + p.getBaseDefinition() + " could not be resolved");
        List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
        List<String> errors = new ArrayList<String>();
        ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
        pu.setThrowException(false);
        pu.sortDifferential(sd, p, p.getUrl(), errors);
        for (String err : errors) msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: " + err, ValidationMessage.IssueSeverity.ERROR));
        pu.generateSnapshot(sd, p, p.getUrl(), Utilities.extractBaseUrl(sd.getUserString("path")), p.getName());
        for (ValidationMessage msg : msgs) {
            if ((!ignoreProfileErrors && msg.getLevel() == ValidationMessage.IssueSeverity.ERROR) || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
                throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot: " + msg.getMessage());
        }
        if (!p.hasSnapshot())
            throw new FHIRException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot");
        pu = null;
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ArrayList (java.util.ArrayList)74 FHIRException (org.hl7.fhir.exceptions.FHIRException)59 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)52 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)48 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)20 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)16 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 FileOutputStream (java.io.FileOutputStream)15 ProfileUtilities (org.hl7.fhir.r4b.conformance.ProfileUtilities)14 IOException (java.io.IOException)13 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 ProfileUtilities (org.hl7.fhir.r4.conformance.ProfileUtilities)12 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)12 Test (org.junit.jupiter.api.Test)12 FileNotFoundException (java.io.FileNotFoundException)11