diff --git a/src/views/Patient/PatientView.tsx b/src/views/Patient/PatientView.tsx index 465217a..07d11df 100644 --- a/src/views/Patient/PatientView.tsx +++ b/src/views/Patient/PatientView.tsx @@ -27,6 +27,7 @@ interface PatientViewProps { client: Client; tabCallback: (n: ReactElement, m: string, o: string) => void; } +type InfoRow = { header: string; data: string }[]; export interface MedicationBundle { data: MedicationRequest[]; @@ -182,19 +183,58 @@ function PatientView(props: PatientViewProps) { client.patient.read().then((patient: any) => setPatient(patient)); }, [client.patient, client]); - const rows: { header: string; data: string }[] = [ - { header: 'ID', data: patient?.['id'] || '' }, + function getAge(dateString: string) { + const today = new Date(); + const birthDate = new Date(dateString); + let age = today.getFullYear() - birthDate.getFullYear(); + const m = today.getMonth() - birthDate.getMonth(); + if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { + age--; + } + return age; + } + const renderRows = (rows: InfoRow) => { + return rows.map(({ header, data }, i) => { + let backgroundColor = '#fdfdfd'; + if (i % 2 === 0) { + // is even + backgroundColor = '#dcdcdc'; + } + return ( + + + {header} + + + {data} + + + ); + }); + }; + let birthday = patient?.birthDate; + let age; + if (birthday) { + age = getAge(birthday); + birthday = `${birthday} (${age} years old)`; + } + const patientName = `${patient?.name?.[0]?.given?.[0]} ${patient?.name?.[0]?.family}`; + const patientFullName = `${patient?.name?.[0]?.given?.join(' ')} ${patient?.name?.[0]?.family}`; + const rows: InfoRow = [ { header: 'Full Name', - data: `${patient?.name?.[0]?.given?.[0]} ${patient?.name?.[0]?.family}` + data: patientFullName + }, + { + header: 'Gender', + data: patient?.['gender'] + ? patient.gender.charAt(0).toUpperCase() + patient.gender.slice(1) + : '' }, - { header: 'Gender', data: patient?.['gender'] || '' }, - { header: 'Date of Birth', data: patient?.['birthDate'] || '' }, + { header: 'Date of Birth', data: birthday || '' }, { header: 'Address', - data: `${(patient?.address?.[0].line, patient?.address?.[0]['city'])}\n${ - patient?.address?.[0]?.state - }, ${patient?.address?.[0]?.postalCode}` + data: `${patient?.address?.[0].line?.[0]}\n${patient?.address?.[0].city}\n${patient?.address?.[0]?.state}, ${patient?.address?.[0]?.postalCode}` } ]; @@ -206,12 +246,12 @@ function PatientView(props: PatientViewProps) { - + - Patient information loaded from patient context + Patient: - + submitToREMS(cdsHook, setHooksCards)} @@ -220,19 +260,16 @@ function PatientView(props: PatientViewProps) { + +
+ {patientName}{' '} + {`(ID: ${patient.id})`} +
+
- - {rows.map(({ header, data }) => ( - - - {header} - - {data} - - ))} - + {renderRows(rows)}