use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class CanonicalResourceComparer method renderMetadata.
public XhtmlNode renderMetadata(CanonicalResourceComparison<? extends CanonicalResource> comparison, String id, String prefix) throws FHIRException, IOException {
// columns: code, display (left|right), properties (left|right)
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "compare"), false);
TableModel model = gen.new TableModel(id, true);
model.setAlternating(true);
model.getTitles().add(gen.new Title(null, null, "Name", "Property Name", null, 100));
model.getTitles().add(gen.new Title(null, null, "Value", "The value of the property", null, 200, 2));
model.getTitles().add(gen.new Title(null, null, "Comments", "Additional information about the comparison", null, 200));
for (String n : sorted(comparison.getMetadata().keySet())) {
StructuralMatch<String> t = comparison.getMetadata().get(n);
addRow(gen, model.getRows(), n, t);
}
return gen.generate(model, prefix, 0, null);
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class ComparisonService method doLeftRightComparison.
public static void doLeftRightComparison(String[] args, String dest, ValidationEngine validator) throws IOException, FHIRException, EOperationOutcome {
// ok now set up the comparison
String left = Params.getParam(args, Params.LEFT);
String right = Params.getParam(args, Params.RIGHT);
Resource resLeft = validator.getContext().fetchResource(Resource.class, left);
Resource resRight = validator.getContext().fetchResource(Resource.class, right);
if (resLeft == null) {
System.out.println("Unable to locate left resource " + left);
}
if (resRight == null) {
System.out.println("Unable to locate right resource " + right);
}
if (resLeft != null && resRight != null) {
if (resLeft instanceof StructureDefinition && resRight instanceof StructureDefinition) {
ComparisonService.compareStructureDefinitions(dest, validator, left, right, (StructureDefinition) resLeft, (StructureDefinition) resRight);
} else if (resLeft instanceof CapabilityStatement && resRight instanceof CapabilityStatement) {
ComparisonService.compareCapabilityStatements(args, dest, validator, left, right, (CanonicalResource) resLeft, (CanonicalResource) resRight);
} else
System.out.println("Unable to compare left resource " + left + " (" + resLeft.fhirType() + ") with right resource " + right + " (" + resRight.fhirType() + ")");
}
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class StandAloneValidatorFetcher method fetchCanonicalResource.
@Override
public CanonicalResource fetchCanonicalResource(IResourceValidator validator, String url) throws URISyntaxException {
String[] p = url.split("\\/");
String root = getRoot(p, url);
if (root != null) {
TerminologyClient c;
c = TerminologyClientFactory.makeClient(root, "fhir/validator", context.getVersion());
return c.read(p[p.length - 2], p[p.length - 1]);
} else {
throw new FHIRException("The URL '" + url + "' is not known to the FHIR validator, and has not been provided as part of the setup / parameters");
}
}
use of org.hl7.fhir.r4b.model.CanonicalResource 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.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method fetchResourceWithException.
@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, CanonicalResource source) throws FHIRException {
if (uri == null) {
return null;
}
if (class_ == StructureDefinition.class) {
uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
}
synchronized (lock) {
if (uri.contains("|")) {
version = uri.substring(uri.lastIndexOf("|") + 1);
uri = uri.substring(0, uri.lastIndexOf("|"));
}
if (uri.contains("#")) {
uri = uri.substring(0, uri.indexOf("#"));
}
if (class_ == Resource.class || class_ == null) {
if (structures.has(uri)) {
return (T) structures.get(uri, version);
}
if (guides.has(uri)) {
return (T) guides.get(uri, version);
}
if (capstmts.has(uri)) {
return (T) capstmts.get(uri, version);
}
if (measures.has(uri)) {
return (T) measures.get(uri, version);
}
if (libraries.has(uri)) {
return (T) libraries.get(uri, version);
}
if (valueSets.has(uri)) {
return (T) valueSets.get(uri, version);
}
if (codeSystems.has(uri)) {
return (T) codeSystems.get(uri, version);
}
if (operations.has(uri)) {
return (T) operations.get(uri, version);
}
if (searchParameters.has(uri)) {
return (T) searchParameters.get(uri, version);
}
if (plans.has(uri)) {
return (T) plans.get(uri, version);
}
if (maps.has(uri)) {
return (T) maps.get(uri, version);
}
if (transforms.has(uri)) {
return (T) transforms.get(uri, version);
}
if (questionnaires.has(uri)) {
return (T) questionnaires.get(uri, version);
}
if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
return null;
}
// it might be a special URL.
if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
// findTxValueSet(uri);
Resource res = null;
if (res != null) {
return (T) res;
}
}
for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
for (ResourceProxy r : rt.values()) {
if (uri.equals(r.getUrl())) {
if (version == null || version == r.getResource().getMeta().getVersionId()) {
return (T) r.getResource();
}
}
}
}
return null;
} else if (class_ == ImplementationGuide.class) {
return (T) guides.get(uri, version);
} else if (class_ == CapabilityStatement.class) {
return (T) capstmts.get(uri, version);
} else if (class_ == Measure.class) {
return (T) measures.get(uri, version);
} else if (class_ == Library.class) {
return (T) libraries.get(uri, version);
} else if (class_ == StructureDefinition.class) {
return (T) structures.get(uri, version);
} else if (class_ == StructureMap.class) {
return (T) transforms.get(uri, version);
} else if (class_ == ValueSet.class) {
return (T) valueSets.get(uri, version);
} else if (class_ == CodeSystem.class) {
return (T) codeSystems.get(uri, version);
} else if (class_ == ConceptMap.class) {
return (T) maps.get(uri, version);
} else if (class_ == PlanDefinition.class) {
return (T) plans.get(uri, version);
} else if (class_ == OperationDefinition.class) {
OperationDefinition od = operations.get(uri, version);
return (T) od;
} else if (class_ == Questionnaire.class) {
return (T) questionnaires.get(uri, version);
} else if (class_ == SearchParameter.class) {
SearchParameter res = searchParameters.get(uri, version);
return (T) res;
}
if (class_ == CodeSystem.class && codeSystems.has(uri)) {
return (T) codeSystems.get(uri, version);
}
if (class_ == ValueSet.class && valueSets.has(uri)) {
return (T) valueSets.get(uri, version);
}
if (class_ == Questionnaire.class) {
return (T) questionnaires.get(uri, version);
}
if (supportedCodeSystems.contains(uri)) {
return null;
}
throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
}
}
Aggregations