import { RowStatus } from "../../../../components/ui/row-meta"; import { HealthcareService } from "fhir/r4"; import { formatFhirCodeableConcept } from "../../../../utils/fhirCodeableConcept.tsx"; import { FhirHealthcareServiceDisplay } from "../../../../components"; import { useFhirHealthcareServiceBroadcast, useFhirHealthcareServices, useFhirHealthcareServiceTargetedBroadcast, } from "../../../../hooks"; import { useAuthServiceContext, useStaffPermissionServiceContext, } from "../../../../services"; import React, { useState } from "react"; import { ChevronRight, Pencil, Plus, Stethoscope } from 'lucide-react'; import { Sheet, SheetContent, SheetTitle } from "../../../../components/ui/sheet"; import { Skeleton } from "../../../../components/ui/skeleton.tsx"; import EditHealthcareServicePage from "./HealthcareServicePage/HealthcareServicePage"; const HealthcareServicesPage = () => { const { userRole, USER_ROLES } = useAuthServiceContext(); const { canManage } = useStaffPermissionServiceContext(); const { loading, error, healthcareServicesList, loadHealthcareServices, } = useFhirHealthcareServices(); const [selectedHealthcareService, setSelectedHealthcareService] = useState(null); const [healthcareServiceEditor, setHealthcareServiceEditor] = useState<{ resourceId: string; healthcareService?: HealthcareService | null; } | null>(null); const isPatient = [USER_ROLES.PATIENT, USER_ROLES.RELATED_PERSON].includes( userRole as string, ); useFhirHealthcareServiceBroadcast(); useFhirHealthcareServiceTargetedBroadcast({ healthcareService: selectedHealthcareService || undefined, isOpen: !!selectedHealthcareService, onUpdate: (updatedHealthcareService) => { setSelectedHealthcareService(updatedHealthcareService); }, onDelete: () => { setSelectedHealthcareService(null); }, }); const openHealthcareServiceEditor = ( healthcareService?: HealthcareService | null, ) => { setHealthcareServiceEditor({ resourceId: healthcareService?.id || "new", healthcareService, }); }; const viewHealthcareService = (healthcareService: HealthcareService) => { if (isAuthorizedToEdit()) { openHealthcareServiceEditor(healthcareService); return; } setSelectedHealthcareService(healthcareService); }; const editHealthcareService = ( event: React.MouseEvent, healthcareService: HealthcareService, ) => { event.stopPropagation(); openHealthcareServiceEditor(healthcareService); }; const addHealthcareService = () => { openHealthcareServiceEditor(null); }; const handleHealthcareServiceEditorComplete = () => { setHealthcareServiceEditor(null); void loadHealthcareServices(); }; const isAuthorizedToEdit = () => canManage("organization"); const getServiceCategory = (healthcareService: HealthcareService): string => { if ( !healthcareService.category || healthcareService.category.length === 0 ) { return ""; } return formatFhirCodeableConcept(healthcareService.category[0]); }; const getServiceType = (healthcareService: HealthcareService): string => { if (!healthcareService.type || healthcareService.type.length === 0) { return ""; } return formatFhirCodeableConcept(healthcareService.type[0]); }; const getSpecialties = (healthcareService: HealthcareService): string => { if ( !healthcareService.specialty || healthcareService.specialty.length === 0 ) { return ""; } const specialties = healthcareService.specialty.map((s) => formatFhirCodeableConcept(s), ); return specialties.join(", "); }; return (

Services

Browse the healthcare services offered and explore their details.

{!isPatient && isAuthorizedToEdit() && ( )}
{loading ? (
{[...Array(5)].map((_, i) => (
))}
) : error ? (

Could not load services

Try again later.

{/* Was a hand-rolled Tailwind primary (bg-primary + own padding/hover). `btn btn-blue` is the house treatment — same call as LocationsPage's identical Retry button in batch 28. */}
) : !loading && healthcareServicesList.length === 0 ? (

No services found

No healthcare services are currently available

) : ( healthcareServicesList.length !== 0 && (
{healthcareServicesList.map( (healthcareService: HealthcareService) => { const category = getServiceCategory(healthcareService); const serviceType = getServiceType(healthcareService); const specialties = getSpecialties(healthcareService); return (
viewHealthcareService(healthcareService)} onKeyDown={(event: React.KeyboardEvent) => { if (event.key !== 'Enter' && event.key !== ' ') return; event.preventDefault(); viewHealthcareService(healthcareService); }} className="group rounded hover:bg-muted focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 flex gap-3 items-center justify-between p-2 cursor-pointer" >

{healthcareService?.name} {healthcareService?.active === true ? "Active" : "Inactive"}

{category && ( {category} )} {serviceType && ( · {serviceType} )} {specialties && ( · {specialties} )} {healthcareService.active === false && ( Inactive )}
{isAuthorizedToEdit() && (
)}
); }, )}
) )}
{healthcareServiceEditor && ( setHealthcareServiceEditor(null)} onSaved={handleHealthcareServiceEditorComplete} onDeleted={handleHealthcareServiceEditorComplete} /> )} {selectedHealthcareService && isPatient && ( { if (!open) setSelectedHealthcareService(null); }} > Healthcare service details setSelectedHealthcareService(null)} asModal={false} /> )} {/* For non-patient users, show the existing modal */} {selectedHealthcareService && !isPatient && ( { setSelectedHealthcareService(null); }} /> )}
); }; export default HealthcareServicesPage; // import { useNavigate } from 'react-router-dom'; // import { HealthcareService } from 'fhir/r4'; // import { formatFhirCodeableConcept } from '../../../../utils/fhirCodeableConcept.tsx'; // import { AppSpinner, FhirHealthcareServiceDisplay, ScrollableTab } from '../../../../components'; // import { // useFhirHealthcareServiceBroadcast, // useFhirHealthcareServices, // useFhirHealthcareServiceTargetedBroadcast // } from '../../../../hooks'; // import { useAuthServiceContext, useHealthcareServiceServiceContext } from '../../../../services'; // import React from 'react'; // const HealthcareServicesPage = () => { // // const { userRole, USER_ROLES } = useAuthServiceContext(); // const { getHealthcareServiceDisplay } = useHealthcareServiceServiceContext(); // const { loading, error, clearError, healthcareServicesList } = useFhirHealthcareServices(); // const [isGuideOpen, setIsGuideOpen] = useState(false); // const [selectedHealthcareService, setSelectedHealthcareService] = useState(null); // const [showDisplayModal, setShowDisplayModal] = useState(false); // const isPatient = [USER_ROLES.PATIENT, USER_ROLES.RELATED_PERSON].includes(userRole as string); // const spacerMargin = '24px'; // useFhirHealthcareServiceBroadcast(); // useFhirHealthcareServiceTargetedBroadcast({ // healthcareService: selectedHealthcareService || undefined, // isOpen: showDisplayModal, // onUpdate: (updatedHealthcareService) => { // setSelectedHealthcareService(updatedHealthcareService); // }, // onDelete: () => { // setShowDisplayModal(false); // setSelectedHealthcareService(null); // } // }); // const viewHealthcareService = (healthcareService: HealthcareService) => { // setSelectedHealthcareService(healthcareService); // setShowDisplayModal(true); // }; // const editHealthcareService = (event: React.MouseEvent, healthcareService: HealthcareService) => { // event.stopPropagation(); // navigate(healthcareService.id as string, { // relative: 'route', // state: { // healthcareService: healthcareService // } // }); // }; // const addHealthcareService = () => { // navigate('new', { // relative: 'route', // state: { // healthcareService: null // } // }); // }; // const isAuthorizedToEdit = () => { // return userRole && [USER_ROLES.ADMIN].includes(userRole as string); // }; // const getServiceCategory = (healthcareService: HealthcareService): string => { // if (!healthcareService.category || healthcareService.category.length === 0) { // return ''; // } // return formatFhirCodeableConcept(healthcareService.category[0]); // }; // const getServiceType = (healthcareService: HealthcareService): string => { // if (!healthcareService.type || healthcareService.type.length === 0) { // return ''; // } // return formatFhirCodeableConcept(healthcareService.type[0]); // }; // const getSpecialties = (healthcareService: HealthcareService): string => { // if (!healthcareService.specialty || healthcareService.specialty.length === 0) { // return ''; // } // const specialties = healthcareService.specialty.map(s => formatFhirCodeableConcept(s)); // return specialties.join(', '); // }; // const getStatusDisplay = (healthcareService: HealthcareService): { text: string, color?: string } => { // const isActive = healthcareService.active !== false; // return isActive // ? { text: 'Active', color: '#00a32a' } //: { text: 'Inactive', color: '#cc1818' }; // }; // return ( //
// {!isPatient && ( // <> // setIsGuideOpen(false)} // resourceType="HealthcareService"/> // // // // // // // {isAuthorizedToEdit() && ( // // // // )} // // // // )} // {error && ( // <> // // {error} // // // // )} // {!loading && healthcareServicesList.length === 0 && ( // <> // // No healthcare services found. // // // // )} // <> // {loading ? ( // // ): ( // // {healthcareServicesList.length !== 0 && ( // // {healthcareServicesList.map((healthcareService: HealthcareService) => { // const displayTitle = getHealthcareServiceDisplay(healthcareService); // const { text: statusText, color: statusColor } = getStatusDisplay(healthcareService); // const category = getServiceCategory(healthcareService); // const serviceType = getServiceType(healthcareService); // const specialties = getSpecialties(healthcareService); // return ( // viewHealthcareService(healthcareService)}> // // // // // // // // // {displayTitle} // // {category && ( // // Category: {category} // // )} // {serviceType && ( // // Type: {serviceType} // // )} // {specialties && ( // // Specialties: {specialties} // // )} // // {isAuthorizedToEdit() && ( // // // // )} // // // // // ); // })} // // )} // // )} // // {selectedHealthcareService && ( // { // setShowDisplayModal(false); // setSelectedHealthcareService(null); // }}/> // )} //
// ); // }; // export default HealthcareServicesPage;