import React, { useState, useEffect } from 'react'; import { TextareaControl } from "../ui/textarea-control"; import { Card, CardHeader, CardBody, CardDivider } from '../ui/wp-card'; import { Elevation } from '../ui/elevation'; import { InputControl } from '../ui/input-control'; import { Divider } from '../ui/divider'; import { DismissibleAlert } from '../ui/dismissible-alert'; import { Heading } from '../ui/heading'; import { Flex, FlexItem } from '../ui/flex'; import { Spacer } from '../ui/spacer'; import { TabPanel } from '../ui/tab-panel'; import { useFormContext, Controller, useFieldArray } from 'react-hook-form'; import { IValueSet, useValueSetServiceContext } from '../../services'; import { FhirCodeableConcept, FhirContactPoint, FhirIdentifier, FhirOperationalHours, FhirOperationalHoursNotAvailable, FhirReference, PhotoAttachment } from '../../components'; import { useFhirHealthcareServiceBroadcast, useFhirHealthcareServices, useFhirLocations } from '../../hooks'; import { Attachment } from 'fhir/r4'; import { Plus, Trash2 } from 'lucide-react'; import { onlySites } from '../../utils/roomLocation'; // - WordPress's ToggleControl, swapped for the ui/* adapter. Same props, same JSX; // only `__nextHasNoMarginBottom` is dropped, which means nothing outside WordPress. import { ToggleControl } from '../ui/toggle-control'; import { ServiceTypeField } from '../ServiceTypeSearch/ServiceTypeField'; interface FhirHealthcareServiceProps { elevated?: boolean; disabled?: boolean; photo: Attachment | undefined; onPhotoChange: (photo: Attachment | undefined) => void; enableInlineActions?: boolean; } export const FhirHealthcareService: React.FC = ({ photo, onPhotoChange, elevated = true, disabled = false, enableInlineActions = true }) => { const { control } = useFormContext(); const { fetchValueSet, valueSetUrls } = useValueSetServiceContext(); const [loading, setLoading] = useState(false); // value sets const [serviceCategory, setServiceCategory] = useState([]); const [practiceCodes, setPracticeCodes] = useState([]); const [serviceProvisionConditions, setServiceProvisionConditions] = useState([]); const [program, setProgram] = useState([]); const [languages, setLanguages] = useState([]); const [serviceReferralMethod, setServiceReferralMethod] = useState([]); const spacerMargin = '24px'; useFhirHealthcareServices(); useFhirHealthcareServiceBroadcast(); const { locationsList } = useFhirLocations(); const hoursOfOperationFieldArray = useFieldArray({ control: control, name: 'availableTime' }); const notAvailableFieldArray = useFieldArray({ control: control, name: 'notAvailable' }); const telecomFieldArray = useFieldArray({ control: control, name: 'telecom' }); const identifierFieldArray = useFieldArray({ control: control, name: 'identifier' }); const eligibilityFieldArray = useFieldArray({ control, name: 'eligibility' }); const endpointFieldArray = useFieldArray({ control, name: 'endpoint' }); useEffect(() => { const loadValueSets = async () => { setLoading(true); try { const [ serviceCategoryValueSet, practiceCodesValueSet, serviceProvisionConditionsValueSet, programValueSet, languagesValueSet, serviceReferralMethodValueSet ] = await Promise.all([ fetchValueSet(valueSetUrls.serviceCategory), fetchValueSet(valueSetUrls.practiceCodes), fetchValueSet(valueSetUrls.serviceProvisionConditions), fetchValueSet(valueSetUrls.program), fetchValueSet(valueSetUrls.languages), fetchValueSet(valueSetUrls.serviceReferralMethod) ]); setServiceCategory(serviceCategoryValueSet); setPracticeCodes(practiceCodesValueSet); setServiceProvisionConditions(serviceProvisionConditionsValueSet); setProgram(programValueSet); setLanguages(languagesValueSet); setServiceReferralMethod(serviceReferralMethodValueSet); } catch (err) { console.error('Error loading value sets:', err); } finally { setLoading(false); } }; loadValueSets(); }, [fetchValueSet, valueSetUrls]); const addEligibility = () => { eligibilityFieldArray.append({ code: null, comment: '' }); }; const removeEligibility = (index: number) => { eligibilityFieldArray.remove(index); }; return ( {elevated && } Healthcare Service Information {/* Photo */} {/* name */} ( <> {fieldState.error && ( Healthcare Service name is required )} )}/> {/* active */} ( )}/> {/* comment */} ( )}/> {/* extraDetails */} ( )}/> {/* appointmentRequired */} ( )}/> {(tab) => { // categories if (tab.name === 'categories') { return (
{/* category */} {/* type: a SNOMED concept from the scoped search, which booking routes by; the HL7 service-type list is not one the server accepts */} {/* specialty */} {/* serviceProvisionCode */} {/* program */}
); } // locations tab if (tab.name === 'locations') { return (
{/* location */} {/* coverageArea */}
); } // eligibility if (tab.name === 'eligibility') { return (
Eligibility {eligibilityFieldArray.fields.length === 0 && ( No eligibility criteria specified. )} {eligibilityFieldArray.fields.map((field, index) => ( Eligibility Criteria {index + 1} {/* eligibility code */} {/* eligibility comment */} ( )}/> ))}
); } // characteristics if (tab.name === 'characteristics') { return (
Characteristics {/* characteristic */} {/**/} {/**/} {/* communication */} {/* referralMethod */}
); } // availability if (tab.name === 'availability') { return (
{/* availableTime */} {/* notAvailable */}
); } // contact if (tab.name === 'contact') { return (
{/* telecom */} {/* Endpoints */} {/**/} {/* */} {/* Endpoints*/} {/* */} {/* */} {/* */} {/* */} {/**/} {/**/} {/**/} {/*{endpointFieldArray.fields.length === 0 && (*/} {/* */} {/* No endpoints specified.*/} {/* */} {/*)}*/} {/*{endpointFieldArray.fields.map((field, index) => (*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/*
); } // identifiers if (tab.name === 'identifiers') { return (
{/* identifier */}
); } }}
); }; export default FhirHealthcareService;