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: mapByIdentifier #4398

Closed
Swizec opened this issue Apr 18, 2024 · 3 comments · Fixed by #4635 or #4704
Closed

Util suggestion: mapByIdentifier #4398

Swizec opened this issue Apr 18, 2024 · 3 comments · Fixed by #4635 or #4704
Labels
good first issue Good for newcomers
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 turning a bundle into a Map for fast lookup. For example when merging data from Medplum and other APIs. This way we can have an O(n+m) algorithm instead of O(n*m).

function mapByIdentifier<T extends Resource = Resource>(
    resourceBundle: Bundle<T>,
    identifierSystem: IdentifierSystem
) {
    const resourceMap = new Map<string, T>(
        resourceBundle.entry
            ?.filter(p => !!p.resource)
            .map(p => [
                getIdentifier(p.resource!, identifierSystem.system) as string,
                p.resource!
            ])
    )
    return resourceMap
}
@codyebberson
Copy link
Member

Yep, good suggestion.

It would make sense to add this near getIdentifier() in packages/core/src/utils.ts

@codyebberson codyebberson added the good first issue Good for newcomers label Apr 20, 2024
@Swizec
Copy link
Contributor Author

Swizec commented Apr 23, 2024

Happy to hear you like it @codyebberson. Is the best next step to make a pull request?

@rahul1
Copy link
Member

rahul1 commented Apr 23, 2024

@Swizec Yep that would be appreciated

@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
medplumbot added a commit that referenced this issue Jun 21, 2024
## What's Changed

fix(ci): fix `\n` missing due to reversal, use `git log --reverse` (#4649)
Allow chained search in _filter (#4647)
Polish eligibility demo (#4637)
cleanup(core): remove stray `console.log` (#4653)
Update sidebar.ts (#4652)
Feat: Configure refresh token expiry (#4525)
Dependency upgrades 2024-06-10 (#4650)
cleanup(chart-demo): rm ignored `example-bots.json` (#4656)
 Adding instructions to the example app READMEs on how to build bots (#4660)
Update useSearch.ts (#4663)
Export QuestionnaireFormContext and QuestionnairePageSequence from QuestionnaireForm (#4664)
Add `expo-polyfills` to README packages list (#4666)
revert(react): remove export of `QuestionnairePageSequence` (#4669)
Fix wrong pipe character in README (#4671)
Document Terminology Service operation endpoints (#4665)
Dependency upgrades 2024-06-17 (#4673)
Gracefully handle no major dep upgrades (#4675)
SQL on FHIR ViewDefinition types (#4674)
fix(build) Update deprecated import assertion into import attribute (#4682)
Fixes #4398 - add mapByIdentifier util function (#4635)
Fixes #4600 - Add Auto Confirmation Parameter for Headless Deployment (#4625)
fix(react-hooks): make `loading` track `MedplumClient#isLoading()` (#4677)
Implements FHIRPath string join (stu) (#4683)
SQL-on-FHIR processResource (#4678)
feat(useSubscription): add `subscriptionProps` as optional param (#4180)
Resolve conditional references (#4633)
feat(subscriptions): add `unbind-from-token` message for WebSocket subscriptions (#4672)
Document remaining Terminology Service operations (#4680)
feat(agent): add `keepAlive` setting to `Agent` (#4657)
Update README.md (#4687)
Fix all copyright dates (#4689)
Fixes subject input on PlanDefinitionApplyForm (#4699)
Deprecate non-strict mode (#4651)
Validate certain references with systemRepo (#4700)
docs(useSubscription): clean up examples, add JSDoc comment (#4692)
cleanup(repo): `handleMaybeCacheOnly` -> `handleStorage` (#4696)
Minor fixes to Eligibility Demo (#4703)

**Full Changelog**: v3.1.8...v3.1.9
github-merge-queue bot pushed a commit that referenced this issue Jun 22, 2024
## What's Changed

fix(ci): fix `\n` missing due to reversal, use `git log --reverse` (#4649)
Allow chained search in _filter (#4647)
Polish eligibility demo (#4637)
cleanup(core): remove stray `console.log` (#4653)
Update sidebar.ts (#4652)
Feat: Configure refresh token expiry (#4525)
Dependency upgrades 2024-06-10 (#4650)
cleanup(chart-demo): rm ignored `example-bots.json` (#4656)
 Adding instructions to the example app READMEs on how to build bots (#4660)
Update useSearch.ts (#4663)
Export QuestionnaireFormContext and QuestionnairePageSequence from QuestionnaireForm (#4664)
Add `expo-polyfills` to README packages list (#4666)
revert(react): remove export of `QuestionnairePageSequence` (#4669)
Fix wrong pipe character in README (#4671)
Document Terminology Service operation endpoints (#4665)
Dependency upgrades 2024-06-17 (#4673)
Gracefully handle no major dep upgrades (#4675)
SQL on FHIR ViewDefinition types (#4674)
fix(build) Update deprecated import assertion into import attribute (#4682)
Fixes #4398 - add mapByIdentifier util function (#4635)
Fixes #4600 - Add Auto Confirmation Parameter for Headless Deployment (#4625)
fix(react-hooks): make `loading` track `MedplumClient#isLoading()` (#4677)
Implements FHIRPath string join (stu) (#4683)
SQL-on-FHIR processResource (#4678)
feat(useSubscription): add `subscriptionProps` as optional param (#4180)
Resolve conditional references (#4633)
feat(subscriptions): add `unbind-from-token` message for WebSocket subscriptions (#4672)
Document remaining Terminology Service operations (#4680)
feat(agent): add `keepAlive` setting to `Agent` (#4657)
Update README.md (#4687)
Fix all copyright dates (#4689)
Fixes subject input on PlanDefinitionApplyForm (#4699)
Deprecate non-strict mode (#4651)
Validate certain references with systemRepo (#4700)
docs(useSubscription): clean up examples, add JSDoc comment (#4692)
cleanup(repo): `handleMaybeCacheOnly` -> `handleStorage` (#4696)
Minor fixes to Eligibility Demo (#4703)

**Full Changelog**: v3.1.8...v3.1.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: ✅ Done
4 participants