Skip to content

Commit

Permalink
Add resolveReference helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Nov 25, 2024
1 parent 27b9674 commit 442835f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/reference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reference } from 'fhir/r4b';
import { Bundle, Reference, Resource } from 'fhir/r4b';

export function getFHIRReferenceData(reference?: Reference) {
const splittedReference = reference?.reference?.split('/');
Expand All @@ -15,3 +15,8 @@ export function getFHIRReferenceResourceType(reference?: Reference) {
export function getFHIRReferenceResourceId(reference?: Reference) {
return getFHIRReferenceData(reference).id;
}

export function resolveReference<R extends Resource = never>(bundle: Bundle, reference: Reference): R | undefined {
return bundle.entry?.find((entry) => reference.reference && entry.fullUrl?.endsWith(reference.reference))
?.resource as R | undefined;
}

0 comments on commit 442835f

Please sign in to comment.