/** @module @category UI */ import React, { useMemo } from 'react'; import classNames from 'classnames'; import { InlineLoading } from '@carbon/react'; import { type CoreTranslationKey, getCoreTranslation } from '@openmrs/esm-translations'; import { ConfigurableLink, usePatient } from '@openmrs/esm-react-utils'; import { parseDate } from '@openmrs/esm-utils'; import { usePatientContactAttributes } from './usePatientAttributes'; import { usePatientListsForPatient } from './usePatientListsForPatient'; import { useRelationships } from './useRelationships'; import styles from './patient-banner-contact-details.module.scss'; interface ContactDetailsProps { patientId: string; deceased: boolean; } const PatientLists: React.FC<{ patientUuid: string }> = ({ patientUuid }) => { const { cohorts = [], isLoading } = usePatientListsForPatient(patientUuid); return ( <>

{getCoreTranslation('patientLists', 'Patient Lists')} ({cohorts?.length ?? 0})

{isLoading ? ( ) : ( )} ); }; const Address: React.FC<{ patientId: string }> = ({ patientId }) => { const { patient, isLoading } = usePatient(patientId); const address = patient?.address?.find((a) => a.use === 'home'); const getAddressKey = (url: string) => url.split('#')[1]; if (isLoading) { return ; } return ( <>

{getCoreTranslation('address', 'Address')}

); }; const Contact: React.FC<{ patientUuid: string; deceased?: boolean }> = ({ patientUuid }) => { const { isLoading: isLoadingAttributes, contactAttributes } = usePatientContactAttributes(patientUuid); const contacts = useMemo( () => contactAttributes ? [ ...contactAttributes?.map((contact) => [ contact.attributeType.display ? getCoreTranslation( /** TODO: We should probably add translation strings for some of these */ contact.attributeType.display as CoreTranslationKey, contact.attributeType.display, ) : '', contact.value, ]), ] : [], [contactAttributes], ); return ( <>

{getCoreTranslation('contactDetails', 'Contact Details')}

{isLoadingAttributes ? ( ) : (
    {contacts.length ? ( contacts.map(([label, value], index) => (
  • {label}: {value}
  • )) ) : (
  • --
  • )}
)} ); }; const Relationships: React.FC<{ patientId: string }> = ({ patientId }) => { const { data: relationships, isLoading } = useRelationships(patientId); return ( <>

{getCoreTranslation('relationships', 'Relationships')}

{isLoading ? ( ) : (
    {relationships && relationships.length > 0 ? ( <> {relationships.map((r) => (
  • {r.display}
    {r.relationshipType}
    {`${r.relativeAge ? r.relativeAge : '--'} ${ r.relativeAge ? r.relativeAge === 1 ? getCoreTranslation('yearAbbreviation', 'yr') : getCoreTranslation('yearsAbbreviation', 'yrs') : '' }`}
  • ))} ) : (
  • --
  • )}
)} ); }; export function PatientBannerContactDetails({ patientId, deceased }: ContactDetailsProps) { return (
); }