Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

'Add Related Person' search field crashes if a matched patient is returned that has no DoB #2195

Closed
JDarke opened this issue Jul 1, 2020 · 2 comments · Fixed by #2214
Closed
Assignees
Labels
🐛bug issue/pull request that documents/fixes a bug in progress indicates that issue/pull request is currently being worked on patients issue/pull request that interacts with patients module
Milestone

Comments

@JDarke
Copy link
Contributor

JDarke commented Jul 1, 2020

🐛 Bug Report

When searching for an existing patient to add as a Related Person (Patients > View Patient > Related Persons tab), if any matching names are found that are of a patient with no date of birth on record, an error is thrown.

To Reproduce

Steps to reproduce the behavior:

  1. Ensure your patient list has a patient record with no DoB set.

  2. Navigate to a different patient's record, then go to the Related Persons tab.

  3. Click 'Add Related Person' and type in the first few characters of the name of the record with no date of birth.

  4. The program attempts to display the DoB alongside the matching name, but crashes on fail.

Paste your code here:

RangeError: Invalid time value
format
C:/Users/UnitA/Projects/hospitalrun-frontend/node_modules/date-fns/esm/format/index.js:371
  368 | var originalDate = toDate(dirtyDate);
  369 | 
  370 | if (!isValid(originalDate)) {
> 371 |   throw new RangeError('Invalid time value');
      | ^  372 | } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
  373 | // This ensures that when UTC functions will be implemented, locales will be compatible with them.
  374 | // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376

View compiled

renderMenuItemChildren
C:/Users/UnitA/Projects/hospitalrun-frontend/src/patients/related-persons/AddRelatedPersonPanel.tsx:64
  61 | isInvalid={!!relatedPersonError?.relatedPerson}
  62 | onSearch={onSearch}
  63 | renderMenuItemChildren={(p: Patient) => (
> 64 |   <div>
     | ^  65 |     {`${p.fullName} - ${format(new Date(p.dateOfBirth), 'yyyy-MM-dd')} (${p.code})`}
  66 |   </div>
  67 | )}

View compiled

▶ 19 stack frames were collapsed.
(anonymous function)
C:/Users/UnitA/Projects/src/components/Typeahead/Typeahead.tsx:53
  50 | const search = async (query: string) => {
  51 |   setIsLoading(true)
  52 |   const results = await onSearch(query)
> 53 |   setOptions(results)
     | ^  54 |   setIsLoading(false)
  55 | }
  56 | 
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.  Click the 'X' or hit ESC to dismiss this message.

Expected behavior

The crash should not happen.

Error catching should be in place.

DoB field should either be mandatory, or have a safe default value assigned when not known.

@blestab
Copy link
Contributor

blestab commented Jul 3, 2020

You may assign this to me to resolve the crash in the date-fns/format function by conditionally calling it, i.e. only if the DoB has a value, like we do in the patient listing.

In terms of preventing the issue from even happening, making DoB or estimated age mandatory sounds like a great idea.

@jackcmeyer
Copy link
Member

@blestab I've assigned this to you. I agree, I thin making the DoB/estimated age field required sounds like the right solution.

@jackcmeyer jackcmeyer added in progress indicates that issue/pull request is currently being worked on patients issue/pull request that interacts with patients module 🐛bug issue/pull request that documents/fixes a bug labels Jul 7, 2020
@jackcmeyer jackcmeyer added this to the v2.0 milestone Jul 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛bug issue/pull request that documents/fixes a bug in progress indicates that issue/pull request is currently being worked on patients issue/pull request that interacts with patients module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants