generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation for
resolve()
missing from the HapiFhir library (#…
…984) * Update HapiFhirImplementation.java Testing different engine implementation to support resolve * Create HapiFhirCustomEvaluationContext.java adding dummy file * Added resolveReference implementation * Fixed tests * Adding docs * Added tests and method that goes through all fhir files in examples/test * Fixed rules names * Added integration tests * Added comment * Updated comment * Create HapiFhirCustomEvaluationContextTest.groovy * Update HapiFhirCustomEvaluationContext.java Handle reference resolving if the input is provided but not a reference * Moved method based on feedback --------- Co-authored-by: Basilio Bogado <[email protected]>
- Loading branch information
1 parent
0880620
commit d1b2375
Showing
6 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...n/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiFhirCustomEvaluationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.hapi; | ||
|
||
import ca.uhn.fhir.fhirpath.IFhirPathEvaluationContext; | ||
import jakarta.annotation.Nonnull; | ||
import jakarta.annotation.Nullable; | ||
import org.hl7.fhir.instance.model.api.IBase; | ||
import org.hl7.fhir.instance.model.api.IIdType; | ||
import org.hl7.fhir.r4.model.Reference; | ||
|
||
public class HapiFhirCustomEvaluationContext implements IFhirPathEvaluationContext { | ||
|
||
/** | ||
* When a FHIR path includes the "resolve()" method, this function is called to parse that into | ||
* a Resource. | ||
* | ||
* @param theReference Id-based reference to the resource we're attempting to resolve. | ||
* @param theContext Internally converted resource version of theReference. | ||
* @return Reference resource if available, else null. | ||
*/ | ||
@Override | ||
public IBase resolveReference(@Nonnull IIdType theReference, @Nullable IBase theContext) { | ||
if (theContext != null) { | ||
if (theContext.getClass() == Reference.class) { | ||
return ((Reference) theContext).getResource(); | ||
} | ||
return theContext; | ||
} | ||
return IFhirPathEvaluationContext.super.resolveReference(theReference, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../gov/hhs/cdc/trustedintermediary/external/hapi/HapiFhirCustomEvaluationContextTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.hapi | ||
|
||
import ca.uhn.fhir.model.primitive.IdDt | ||
import org.hl7.fhir.r4.model.Organization | ||
import org.hl7.fhir.r4.model.Reference | ||
import spock.lang.Specification | ||
|
||
class HapiFhirCustomEvaluationContextTest extends Specification { | ||
def context = new HapiFhirCustomEvaluationContext() | ||
|
||
def "resolveReference returns null if the context is NOT provided"() { | ||
when: | ||
def result = context.resolveReference(new IdDt(), null) | ||
|
||
then: | ||
result == null | ||
} | ||
|
||
def "resolveReference attempts to get a resource if the context is provided and is a reference"() { | ||
given: | ||
def refId = new IdDt() | ||
def org = new Organization() | ||
def theContext = new Reference(org) | ||
|
||
when: | ||
def result = context.resolveReference(refId, theContext) | ||
|
||
then: | ||
result == org | ||
} | ||
|
||
def "resolveReference returns the given context if it's NOT a reference"() { | ||
given: | ||
def refId = new IdDt() | ||
def org = new Organization() | ||
|
||
when: | ||
def result = context.resolveReference(refId, org) | ||
|
||
then: | ||
result == org | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters