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);
}
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());
}
}
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;
}
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;
}
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;
}
}
Aggregations