use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method context.
public static IWorkerContext context(String version) {
if ("4.5.0".equals(version)) {
// temporary work around
version = "4.4.0";
}
String v = VersionUtilities.getMajMin(version);
if (fcontexts == null) {
fcontexts = new HashMap<>();
}
if (!fcontexts.containsKey(v)) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
// ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
fcontexts.put(v, fcontext);
} catch (Exception e) {
e.printStackTrace();
throw new Error(e);
}
}
return fcontexts.get(v);
}
use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeExtensionForVersionedURL.
public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
String epath = url.substring(54);
if (!epath.contains("."))
return null;
String type = epath.substring(0, epath.indexOf("."));
StructureDefinition sd = context.fetchTypeDefinition(type);
if (sd == null)
return null;
ElementDefinition ed = null;
for (ElementDefinition t : sd.getSnapshot().getElement()) {
if (t.getPath().equals(epath)) {
ed = t;
break;
}
}
if (ed == null)
return null;
if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
return null;
} else {
StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
StructureDefinition ext = template.copy();
ext.setUrl(url);
ext.setId("extension-" + epath);
ext.setName("Extension-" + epath);
ext.setTitle("Extension for r4 " + epath);
ext.setStatus(sd.getStatus());
ext.setDate(sd.getDate());
ext.getContact().clear();
ext.getContact().addAll(sd.getContact());
ext.setFhirVersion(sd.getFhirVersion());
ext.setDescription(ed.getDefinition());
ext.getContext().clear();
ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
ext.getDifferential().getElement().clear();
ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
ext.getSnapshot().getElement().set(4, ed.copy());
ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
return ext;
}
}
use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method checkAddTypeUnion.
private void checkAddTypeUnion(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, List<TypeRefComponent> results, TypeRefComponent nw, IWorkerContext ctxt) throws DefinitionException, IOException, FHIRFormatError {
boolean pfound = false;
boolean tfound = false;
nw = nw.copy();
if (nw.hasAggregation())
throw new DefinitionException("Aggregation not supported: " + path);
for (TypeRefComponent ex : results) {
if (Utilities.equals(ex.getWorkingCode(), nw.getWorkingCode())) {
if (!ex.hasProfile() && !nw.hasProfile())
pfound = true;
else if (!ex.hasProfile()) {
pfound = true;
} else if (!nw.hasProfile()) {
pfound = true;
ex.setProfile(null);
} else {
// both have profiles. Is one derived from the other?
StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getProfile().get(0).getValue());
StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getProfile().get(0).getValue());
if (sdex != null && sdnw != null) {
if (sdex.getUrl().equals(sdnw.getUrl())) {
pfound = true;
} else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
ex.setProfile(nw.getProfile());
pfound = true;
} else if (derivesFrom(sdnw, sdex, ctxt)) {
pfound = true;
} else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
if (compP != null && compP.getUnion() != null) {
// might be null if circular
pfound = true;
ex.addProfile("#" + compP.getId());
}
}
}
}
if (!ex.hasTargetProfile() && !nw.hasTargetProfile())
tfound = true;
else if (!ex.hasTargetProfile()) {
tfound = true;
} else if (!nw.hasTargetProfile()) {
tfound = true;
ex.setTargetProfile(null);
} else {
// both have profiles. Is one derived from the other?
StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getTargetProfile().get(0).getValue());
StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getTargetProfile().get(0).getValue());
if (sdex != null && sdnw != null) {
if (matches(sdex, sdnw)) {
tfound = true;
} else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
ex.setTargetProfile(nw.getTargetProfile());
tfound = true;
} else if (derivesFrom(sdnw, sdex, ctxt)) {
tfound = true;
} else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
if (compP.getUnion() != null) {
tfound = true;
ex.addTargetProfile("#" + compP.getId());
}
}
}
}
}
}
if (!tfound || !pfound) {
nw.setUserData("ctxt", ctxt);
results.add(nw);
}
}
use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeExtensionForVersionedURL.
public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
String epath = url.substring(54);
if (!epath.contains("."))
return null;
String type = epath.substring(0, epath.indexOf("."));
StructureDefinition sd = context.fetchTypeDefinition(type);
if (sd == null)
return null;
ElementDefinition ed = null;
for (ElementDefinition t : sd.getSnapshot().getElement()) {
if (t.getPath().equals(epath)) {
ed = t;
break;
}
}
if (ed == null)
return null;
if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
return null;
} else {
StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
StructureDefinition ext = template.copy();
ext.setUrl(url);
ext.setId("extension-" + epath);
ext.setName("Extension-" + epath);
ext.setTitle("Extension for r4 " + epath);
ext.setStatus(sd.getStatus());
ext.setDate(sd.getDate());
ext.getContact().clear();
ext.getContact().addAll(sd.getContact());
ext.setFhirVersion(sd.getFhirVersion());
ext.setDescription(ed.getDefinition());
ext.getContext().clear();
ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
ext.getDifferential().getElement().clear();
ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
ext.getSnapshot().getElement().set(4, ed.copy());
ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
return ext;
}
}
use of org.hl7.fhir.dstu2016may.utils.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method checkAddTypeUnion.
private void checkAddTypeUnion(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, List<TypeRefComponent> results, TypeRefComponent nw, IWorkerContext ctxt) throws DefinitionException, IOException, FHIRFormatError {
boolean pfound = false;
boolean tfound = false;
nw = nw.copy();
if (nw.hasAggregation())
throw new DefinitionException("Aggregation not supported: " + path);
for (TypeRefComponent ex : results) {
if (Utilities.equals(ex.getWorkingCode(), nw.getWorkingCode())) {
if (!ex.hasProfile() && !nw.hasProfile())
pfound = true;
else if (!ex.hasProfile()) {
pfound = true;
} else if (!nw.hasProfile()) {
pfound = true;
ex.setProfile(null);
} else {
// both have profiles. Is one derived from the other?
StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getProfile().get(0).getValue());
StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getProfile().get(0).getValue());
if (sdex != null && sdnw != null) {
if (sdex.getUrl().equals(sdnw.getUrl())) {
pfound = true;
} else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
ex.setProfile(nw.getProfile());
pfound = true;
} else if (derivesFrom(sdnw, sdex, ctxt)) {
pfound = true;
} else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
if (compP != null && compP.getUnion() != null) {
// might be null if circular
pfound = true;
ex.addProfile("#" + compP.getId());
}
}
}
}
if (!ex.hasTargetProfile() && !nw.hasTargetProfile())
tfound = true;
else if (!ex.hasTargetProfile()) {
tfound = true;
} else if (!nw.hasTargetProfile()) {
tfound = true;
ex.setTargetProfile(null);
} else {
// both have profiles. Is one derived from the other?
StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getTargetProfile().get(0).getValue());
StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getTargetProfile().get(0).getValue());
if (sdex != null && sdnw != null) {
if (matches(sdex, sdnw)) {
tfound = true;
} else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
ex.setTargetProfile(nw.getTargetProfile());
tfound = true;
} else if (derivesFrom(sdnw, sdex, ctxt)) {
tfound = true;
} else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
if (compP.getUnion() != null) {
tfound = true;
ex.addTargetProfile("#" + compP.getId());
}
}
}
}
}
}
if (!tfound || !pfound) {
nw.setUserData("ctxt", ctxt);
results.add(nw);
}
}
Aggregations