use of org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy 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.context.BaseWorkerContext.ResourceProxy 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));
}
}
use of org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy 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