Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Util suggestion: findResourceById #4397

Open
Swizec opened this issue Apr 18, 2024 · 0 comments
Open

Util suggestion: findResourceById #4397

Swizec opened this issue Apr 18, 2024 · 0 comments
Assignees
Milestone

Comments

@Swizec
Copy link
Contributor

Swizec commented Apr 18, 2024

Hi,

while building with the Medplum SDK we've developed a few helper methods to help us work with the API. It would be fantastic if some version of these could be added to the official SDK. Making separate issues for more focused discussion :)

We often find ourselves searching a Bundle for a specific resource by ID.

function findResourceById<T extends Resource = Resource>(
    bundle: Bundle<T>,
    id: string
): T | undefined {
    return bundle.entry?.find(
        ({ resource }) => `${resource?.resourceType}/${resource?.id}` === id
    )?.resource as T | undefined
}
@codyebberson codyebberson added this to the May 31st, 2024 milestone Apr 30, 2024
@reshmakh reshmakh modified the milestones: May 31st, 2024, June 30, 2024 Jun 2, 2024
@codyebberson codyebberson self-assigned this Jun 25, 2024
@reshmakh reshmakh modified the milestones: June 30, 2024, July 31, 2024 Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants