import React from 'react'; import { PractitionerRole } from 'fhir/r4'; import { FhirCodeableConceptDisplay } from '../../utils/fhirCodeableConcept'; import { FHIRContactPointDisplay } from '../../utils/fhirContactPoint'; import { FhirIdentifierDisplay } from '../../utils/fhirIdentifier'; import { FhirOperationalHoursDisplay } from '../../utils/fhirOperationalHours'; import { FhirReferenceDisplay } from '../../utils/fhirReference'; import { FhirPeriodDisplay } from '../../utils/fhirPeriod'; import { renderField } from '../../utils/renderField'; import { useAuthServiceContext } from '../../services/AuthService.tsx'; import { LEADERSHIP_DESIGNATION_EXTENSION_URL, PRIMARY_ORGANIZATION_ROLE_EXTENSION_URL, TRAINING_LEVEL_EXTENSION_URL, } from '../../config/staffRoles.ts'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/dialog'; import { Card, CardHeader, CardContent } from '../ui/card'; import { FieldHistoryProvider, FieldHistoryScope } from '../FieldHistory/FieldHistoryProvider'; import { ShowFieldHistoryToggle } from '../FieldHistory/ShowFieldHistoryToggle'; import { RecordEditedMarker } from '../FieldHistory/RecordEditedMarker'; import { FieldGroup, Section } from '../FieldHistory/FieldLayout'; interface FhirPractitionerRoleDisplayProps { practitionerRole: PractitionerRole; isOpen?: boolean; onClose?: () => void; title?: string; asModal?: boolean; } export const FhirPractitionerRoleDisplay: React.FC = ({ practitionerRole, isOpen = true, onClose, title = "Practitioner Role Details", asModal = true }) => { const { getCognitoGroup } = useAuthServiceContext(); const workspaceGroup = getCognitoGroup(practitionerRole); const workspace = workspaceGroup ? workspaceGroup .replace(/s$/, '') .replace(/([a-z0-9])([A-Z])/g, '$1 $2') : ''; const getExtensionConcepts = (url: string) => (practitionerRole.extension ?? []) .filter((extension) => extension.url === url && extension.valueCodeableConcept) .map((extension) => extension.valueCodeableConcept!); const primaryOrganizationRole = getExtensionConcepts(PRIMARY_ORGANIZATION_ROLE_EXTENSION_URL)[0] || practitionerRole.code?.[0]; const leadershipDesignations = getExtensionConcepts( LEADERSHIP_DESIGNATION_EXTENSION_URL, ); const trainingLevel = getExtensionConcepts(TRAINING_LEVEL_EXTENSION_URL)[0]; const renderActiveValue = () => { if (practitionerRole?.active === true) { return 'Yes'; } if (practitionerRole?.active === false) { return 'No'; } return '-'; }; const renderNotAvailable = () => { if (!practitionerRole.notAvailable || practitionerRole.notAvailable.length === 0) { return (

No unavailable periods recorded

); } return (
{practitionerRole.notAvailable.map((notAvailable, index) => (
Unavailable Period {index + 1}
{renderField('Description', notAvailable.description)} {renderField('Period', )}
))}
); }; const renderContent = () => ( <>
{renderField('Practitioner', )} {renderField('Organization', )} {renderField('Workspace', workspace || '-')} {renderField('Primary organization role', )} {renderField('Organization roles', )} {renderField('Leadership designations', )} {renderField('Training level', )} {renderField('Specific specialty of the practitioner', )} {renderField('Active', renderActiveValue(), 'active')} {renderField('Period', )} {renderField('Contact', )} {renderField('Identifiers', )}
{renderField('The location(s) at which this practitioner provides care', )} {renderField('The list of healthcare services that this worker provides for this role\'s Organization/Location(s)', )}
{renderNotAvailable()}
); if (!asModal) { return (
{renderContent()}
); } if (!isOpen) return null; return ( { if (!next) onClose?.(); }} >
{title}
{renderContent()}
); }; export default FhirPractitionerRoleDisplay;