use of org.hl7.fhir.r4b.model.NamingSystem in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeNamingSystemNamingSystemUniqueIdComponent.
protected void composeNamingSystemNamingSystemUniqueIdComponent(Complex parent, String parentType, String name, NamingSystem.NamingSystemUniqueIdComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "uniqueId", name, element, index);
if (element.hasTypeElement())
composeEnum(t, "NamingSystem", "type", element.getTypeElement(), -1);
if (element.hasValueElement())
composeString(t, "NamingSystem", "value", element.getValueElement(), -1);
if (element.hasPreferredElement())
composeBoolean(t, "NamingSystem", "preferred", element.getPreferredElement(), -1);
if (element.hasCommentElement())
composeString(t, "NamingSystem", "comment", element.getCommentElement(), -1);
if (element.hasPeriod())
composePeriod(t, "NamingSystem", "period", element.getPeriod(), -1);
}
use of org.hl7.fhir.r4b.model.NamingSystem in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method cacheResourceFromPackage.
public void cacheResourceFromPackage(Resource r, PackageVersion packageInfo) throws FHIRException {
synchronized (lock) {
Map<String, ResourceProxy> map = allResourcesById.get(r.fhirType());
if (map == null) {
map = new HashMap<String, ResourceProxy>();
allResourcesById.put(r.fhirType(), map);
}
if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
map.put(r.getId(), new ResourceProxy(r));
} else {
System.out.println("Ignore " + r.fhirType() + "/" + r.getId() + " from package " + packageInfo.toString());
}
if (r instanceof CodeSystem || r instanceof NamingSystem) {
oidCache.clear();
}
if (r instanceof CanonicalResource) {
CanonicalResource m = (CanonicalResource) r;
String url = m.getUrl();
if (!allowLoadingDuplicates && hasResource(r.getClass(), url)) {
// spcial workaround for known problems with existing packages
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
}
if (r instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) m;
if ("1.4.0".equals(version)) {
fixOldSD(sd);
}
structures.see(sd, packageInfo);
} else if (r instanceof ValueSet) {
valueSets.see((ValueSet) m, packageInfo);
} else if (r instanceof CodeSystem) {
CodeSystemUtilities.crossLinkCodeSystem((CodeSystem) r);
codeSystems.see((CodeSystem) m, packageInfo);
} else if (r instanceof ImplementationGuide) {
guides.see((ImplementationGuide) m, packageInfo);
} else if (r instanceof CapabilityStatement) {
capstmts.see((CapabilityStatement) m, packageInfo);
} else if (r instanceof Measure) {
measures.see((Measure) m, packageInfo);
} else if (r instanceof Library) {
libraries.see((Library) m, packageInfo);
} else if (r instanceof SearchParameter) {
searchParameters.see((SearchParameter) m, packageInfo);
} else if (r instanceof PlanDefinition) {
plans.see((PlanDefinition) m, packageInfo);
} else if (r instanceof OperationDefinition) {
operations.see((OperationDefinition) m, packageInfo);
} else if (r instanceof Questionnaire) {
questionnaires.see((Questionnaire) m, packageInfo);
} else if (r instanceof ConceptMap) {
maps.see((ConceptMap) m, packageInfo);
} else if (r instanceof StructureMap) {
transforms.see((StructureMap) m, packageInfo);
} else if (r instanceof NamingSystem) {
systems.see((NamingSystem) m, packageInfo);
}
}
}
}
use of org.hl7.fhir.r4b.model.NamingSystem in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method oid2Uri.
@Override
public String oid2Uri(String oid) {
synchronized (lock) {
if (oid != null && oid.startsWith("urn:oid:")) {
oid = oid.substring(8);
}
if (oidCache.containsKey(oid)) {
return oidCache.get(oid);
}
String uri = OIDUtils.getUriForOid(oid);
if (uri != null) {
oidCache.put(oid, uri);
return uri;
}
CodeSystem cs = fetchCodeSystem("http://terminology.hl7.org/CodeSystem/v2-tables");
if (cs != null) {
for (ConceptDefinitionComponent cc : cs.getConcept()) {
for (ConceptPropertyComponent cp : cc.getProperty()) {
if (Utilities.existsInList(cp.getCode(), "v2-table-oid", "v2-cs-oid") && oid.equals(cp.getValue().primitiveValue())) {
for (ConceptPropertyComponent cp2 : cc.getProperty()) {
if ("v2-cs-uri".equals(cp2.getCode())) {
oidCache.put(oid, cp2.getValue().primitiveValue());
return cp2.getValue().primitiveValue();
}
}
}
}
}
}
for (CodeSystem css : codeSystems.getList()) {
if (("urn:oid:" + oid).equals(css.getUrl())) {
oidCache.put(oid, css.getUrl());
return css.getUrl();
}
for (Identifier id : css.getIdentifier()) {
if ("urn:ietf:rfc:3986".equals(id.getSystem()) && ("urn:oid:" + oid).equals(id.getValue())) {
oidCache.put(oid, css.getUrl());
return css.getUrl();
}
}
}
for (NamingSystem ns : systems.getList()) {
if (hasOid(ns, oid)) {
uri = getUri(ns);
if (uri != null) {
oidCache.put(oid, null);
return null;
}
}
}
}
oidCache.put(oid, null);
return null;
}
use of org.hl7.fhir.r4b.model.NamingSystem in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method registerResourceFromPackage.
public void registerResourceFromPackage(CanonicalResourceProxy r, PackageVersion packageInfo) throws FHIRException {
synchronized (lock) {
Map<String, ResourceProxy> map = allResourcesById.get(r.getType());
if (map == null) {
map = new HashMap<String, ResourceProxy>();
allResourcesById.put(r.getType(), map);
}
if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
map.put(r.getId(), new ResourceProxy(r));
}
String url = r.getUrl();
if (!allowLoadingDuplicates && hasResource(r.getType(), url)) {
// spcial workaround for known problems with existing packages
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
}
switch(r.getType()) {
case "StructureDefinition":
if ("1.4.0".equals(version)) {
StructureDefinition sd = (StructureDefinition) r.getResource();
fixOldSD(sd);
}
structures.register(r, packageInfo);
break;
case "ValueSet":
valueSets.register(r, packageInfo);
break;
case "CodeSystem":
codeSystems.register(r, packageInfo);
break;
case "ImplementationGuide":
guides.register(r, packageInfo);
break;
case "CapabilityStatement":
capstmts.register(r, packageInfo);
break;
case "Measure":
measures.register(r, packageInfo);
break;
case "Library":
libraries.register(r, packageInfo);
break;
case "SearchParameter":
searchParameters.register(r, packageInfo);
break;
case "PlanDefinition":
plans.register(r, packageInfo);
break;
case "OperationDefinition":
operations.register(r, packageInfo);
break;
case "Questionnaire":
questionnaires.register(r, packageInfo);
break;
case "ConceptMap":
maps.register(r, packageInfo);
break;
case "StructureMap":
transforms.register(r, packageInfo);
break;
case "NamingSystem":
systems.register(r, packageInfo);
break;
}
}
}
use of org.hl7.fhir.r4b.model.NamingSystem in project org.hl7.fhir.core by hapifhir.
the class ComparisonTests method test.
@ParameterizedTest(name = "{index}: id {0}")
@MethodSource("data")
public void test(String name, JsonObject content) throws Exception {
this.content = content;
if (content.has("use-test") && !content.get("use-test").getAsBoolean())
return;
if (context == null) {
System.out.println("---- Load R5 ----------------------------------------------------------------");
context = TestingUtilities.getSharedWorkerContext();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
BaseWorkerContext bc = (BaseWorkerContext) context;
boolean dupl = bc.isAllowLoadingDuplicates();
bc.setAllowLoadingDuplicates(true);
context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" }, new NullLoaderKnowledgeProviderR5(), context.getVersion()));
bc.setAllowLoadingDuplicates(dupl);
}
if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
System.out.println("---- Set up Output ----------------------------------------------------------");
Utilities.createDirectory(Utilities.path("[tmp]", "comparison"));
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
for (String f : npm.list("other")) {
TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f));
}
}
System.out.println("---- " + name + " ----------------------------------------------------------------");
CanonicalResource left = load("left");
CanonicalResource right = load("right");
ComparisonSession session = new ComparisonSession(context, context, "Comparison Tests", null);
if (left instanceof CodeSystem && right instanceof CodeSystem) {
CodeSystemComparer cs = new CodeSystemComparer(session);
CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
Assertions.assertTrue(csc.getUnion().getConcept().size() > csc.getIntersection().getConcept().size());
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
String xml2 = new XhtmlComposer(true).compose(cs.renderConcepts(csc, "", ""));
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Concepts") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
checkOutcomes(csc.getMessages(), content);
} else if (left instanceof ValueSet && right instanceof ValueSet) {
ValueSetComparer cs = new ValueSetComparer(session);
ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
String xml2 = new XhtmlComposer(true).compose(cs.renderCompose(csc, "", ""));
String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Definition") + xml2 + BREAK + hd("Expansion") + xml3 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
checkOutcomes(csc.getMessages(), content);
} else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
ProfileUtilities utils = new ProfileUtilities(context, null, null);
genSnapshot(utils, (StructureDefinition) left);
genSnapshot(utils, (StructureDefinition) right);
ProfileComparer pc = new ProfileComparer(session, utils, utils);
ProfileComparison csc = pc.compare((StructureDefinition) left, (StructureDefinition) right);
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
String xml2 = new XhtmlComposer(true).compose(pc.renderStructure(csc, "", "", "http://hl7.org/fhir"));
// String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
checkOutcomes(csc.getMessages(), content);
} else if (left instanceof CapabilityStatement && right instanceof CapabilityStatement) {
CapabilityStatementComparer pc = new CapabilityStatementComparer(session);
CapabilityStatementComparison csc = pc.compare((CapabilityStatement) left, (CapabilityStatement) right);
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
String xml2 = new XhtmlComposer(true).compose(pc.renderStatements(csc, "", ""));
// String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
checkOutcomes(csc.getMessages(), content);
} else {
throw new FHIRException("Can't compare " + left.fhirType() + " to " + right.fhirType());
}
}
Aggregations