Skip to content

Commit

Permalink
Start removing dependency from FhirVersionEnum to FhirContext (hapifh…
Browse files Browse the repository at this point in the history
…ir#6512)

Deprecate path from FhirVersionEnum to FhirContext and replace usages.
  • Loading branch information
michaelabuckley authored Nov 26, 2024
1 parent 77fa7f7 commit 3b85691
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,15 @@ public static FhirContext forR5() {
* @since 5.1.0
*/
public static FhirContext forCached(FhirVersionEnum theFhirVersionEnum) {
return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, v -> new FhirContext(v));
return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, FhirContext::forVersion);
}

/**
* An uncached version of forCached()
* @return a new FhirContext for theFhirVersionEnum
*/
public static FhirContext forVersion(FhirVersionEnum theFhirVersionEnum) {
return new FhirContext(theFhirVersionEnum);
}

private static Collection<Class<? extends IBaseResource>> toCollection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,19 @@ public boolean isRi() {

/**
* Creates a new FhirContext for this FHIR version
* @deprecated since 7.7. Use {@link FhirContext#forVersion(FhirVersionEnum)} instead
*/
@Deprecated(forRemoval = true, since = "7.7")
public FhirContext newContext() {
return new FhirContext(this);
return FhirContext.forVersion(this);
}

/**
* Creates a new FhirContext for this FHIR version, or returns a previously created one if one exists. This
* method uses {@link FhirContext#forCached(FhirVersionEnum)} to return a cached instance.
* @deprecated since 7.7. Use {@link FhirContext#forCached(FhirVersionEnum)} instead
*/
@Deprecated(forRemoval = true, since = "7.7")
public FhirContext newContextCached() {
return FhirContext.forCached(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ca.uhn.fhir.narrative2;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.util.BundleUtil;
import org.apache.commons.lang3.tuple.Pair;
import org.hl7.fhir.instance.model.api.IBaseBundle;
Expand All @@ -42,7 +43,8 @@ public class NarrativeGeneratorTemplateUtils {
* Given a Bundle as input, are any entries present with a given resource type
*/
public boolean bundleHasEntriesWithResourceType(IBaseBundle theBaseBundle, String theResourceType) {
FhirContext ctx = theBaseBundle.getStructureFhirVersionEnum().newContextCached();
FhirVersionEnum fhirVersionEnum = theBaseBundle.getStructureFhirVersionEnum();
FhirContext ctx = FhirContext.forCached(fhirVersionEnum);
List<Pair<String, IBaseResource>> entryResources =
BundleUtil.getBundleEntryUrlsAndResources(ctx, theBaseBundle);
return entryResources.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ protected FhirVersionEnum parseFhirVersion(CommandLine theCommandLine) throws Pa

protected void parseFhirContext(CommandLine theCommandLine) throws ParseException {
FhirVersionEnum versionEnum = parseFhirVersion(theCommandLine);
myFhirCtx = versionEnum.newContext();
myFhirCtx = FhirContext.forVersion(versionEnum);
}

public abstract void run(CommandLine theCommandLine) throws ParseException, ExecutionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class VersionCanonicalizer {
private final FhirContext myContext;

public VersionCanonicalizer(FhirVersionEnum theTargetVersion) {
this(theTargetVersion.newContextCached());
this(FhirContext.forCached(theTargetVersion));
}

public VersionCanonicalizer(FhirContext theTargetContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: remove
issue: 6512
title: "The methods on FhirVersionEnum which produces a FhirContext (newContext() ,and newContextCached()) have been deprecated, and will be removed."
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private static FhirContext getContextForVersion(FhirContext theContext, FhirVers
if (context.getVersion().getVersion() != theForVersion) {
context = myFhirContextMap.get(theForVersion);
if (context == null) {
context = theForVersion.newContext();
context = FhirContext.forVersion(theForVersion);
myFhirContextMap.put(theForVersion, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected VersionCanonicalizer getVersionCanonicalizer(HomeRequest theRequest) {
FhirVersionEnum version = theRequest.getFhirVersion(myConfig);
VersionCanonicalizer retVal = myCanonicalizers.get(version);
if (retVal == null) {
retVal = new VersionCanonicalizer(version.newContext());
retVal = new VersionCanonicalizer(FhirContext.forVersion(version));
myCanonicalizers.put(version, retVal);
}
return retVal;
Expand Down

0 comments on commit 3b85691

Please sign in to comment.