Skip to content

Fix crash when resource.link is undefined in match processing#155

Open
mherman22 wants to merge 1 commit into
intrahealth:masterfrom
mherman22:fix/null-check-resource-link
Open

Fix crash when resource.link is undefined in match processing#155
mherman22 wants to merge 1 commit into
intrahealth:masterfrom
mherman22:fix/null-check-resource-link

Conversation

@mherman22

Copy link
Copy Markdown

Problem

The app crashes with TypeError: Cannot read properties of undefined (reading 'find') when a Patient resource has no link array during match processing.

matchMixin.js:748
const exist = entry.resource.link.find((link) => { ...
                               ^
TypeError: Cannot read properties of undefined (reading 'find')

This happens because resource.link can be undefined when a patient is first submitted, has been unlinked, or when the FHIR store returns a resource without links.

Fix

Add resource.link && guard before .find() at four locations in matchMixin.js:

Line Context Before After
748 Golden record reuse check entry.resource.link.find(...) entry.resource.link && entry.resource.link.find(...)
592 Auto match current link check auto.resource.link.find(...) auto.resource.link && auto.resource.link.find(...)
626 Potential match current link check potential.resource.link.find(...) potential.resource.link && potential.resource.link.find(...)
685 Conflict match current link check conflict.resource.link.find(...) conflict.resource.link && conflict.resource.link.find(...)

This matches the pattern already used at line 928 (currentLink.resource.link && currentLink.resource.link.find(...)) which was the only guarded call.

The addLinks function (lines 515, 530) is safe because lines 512-513 and 527-528 already initialize link to [] if missing.

Fixes #153

Patient resources may not have a link array when they are first
submitted or when they have been unlinked. Four locations in
matchMixin.js called .find() on resource.link without checking
if it exists, causing TypeError: Cannot read properties of
undefined (reading 'find').

Add null checks before .find() on:
- entry.resource.link (line 748) — golden record reuse check
- auto.resource.link (line 592) — auto match current link check
- potential.resource.link (line 626) — potential match check
- conflict.resource.link (line 685) — conflict match check

The addLinks function (lines 515, 530) is safe because it
initializes link to [] on lines 512-513 and 527-528. Line 928
already had the correct guard pattern.

Fixes intrahealth#153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App crashes unexpectedly

1 participant