transformation-ui / src /components /ServiceLookupComponent.tsx
Rajavignesh
Updating the UI Code
b366dd7
Raw History Blame Contribute Delete
21.7 kB
import React, { useState, useEffect } from 'react';
export interface Service {
id: string;
name: string;
category: string;
description?: string;
}
export interface ServiceLookupProps {
isOpen: boolean;
onClose: () => void;
onServicesSelected: (services: Service[]) => void;
selectedServices?: Service[];
allowMultiple?: boolean;
title?: string;
}
const ServiceLookupComponent: React.FC<ServiceLookupProps> = ({
isOpen,
onClose,
onServicesSelected,
selectedServices = [],
allowMultiple = true,
title = "Service Lookup"
}) => {
const [searchTerm, setSearchTerm] = useState('');
const [selectedCategory, setSelectedCategory] = useState('All');
const [tempSelectedServices, setTempSelectedServices] = useState<Service[]>(selectedServices);
// Service categories and their services
const serviceCategories = {
"Outpatient": [
{ id: "op_psychotherapy", name: "Outpatient Psychotherapy", category: "Outpatient", description: "Individual therapy sessions" },
{ id: "group_therapy", name: "Group Therapy", category: "Outpatient", description: "Therapeutic group sessions" },
{ id: "family_therapy", name: "Family Therapy", category: "Outpatient", description: "Family counseling sessions" },
{ id: "crisis_psychotherapy", name: "Crisis Psychotherapy", category: "Outpatient", description: "Emergency psychological intervention" },
{ id: "medication_mgt", name: "Medication Management", category: "Outpatient", description: "Psychiatric medication oversight" },
{ id: "evaluations", name: "Evaluations", category: "Outpatient", description: "Psychological assessments" },
{ id: "consultations", name: "Consultations", category: "Outpatient", description: "Professional consultations" },
{ id: "inhome_therapy", name: "In-Home Therapy", category: "Outpatient", description: "Therapy services at home" },
{ id: "psych_testing", name: "Psychological Testing", category: "Outpatient", description: "If copay applies, will be per day" }
],
"Inpatient": [
{ id: "ip_psych", name: "IP Psych", category: "Inpatient", description: "Inpatient psychiatric care" },
{ id: "ip_substance", name: "IP Substance", category: "Inpatient", description: "Inpatient substance abuse treatment" },
{ id: "ip_detox", name: "IP Detox", category: "Inpatient", description: "Inpatient detoxification services" }
],
"Professional Services": [
{ id: "ip_prof_psych", name: "IP Professional Psych", category: "Professional Services", description: "Professional psychiatric services" },
{ id: "ip_prof_sa", name: "IP Professional SA", category: "Professional Services", description: "Professional substance abuse services" },
{ id: "medical_consults_bh", name: "Medical Consults on a BH Floor", category: "Professional Services", description: "Medical consultations on behavioral health floor" },
{ id: "ip_prof_detox", name: "IP Prof Detox", category: "Professional Services", description: "Professional detoxification services" },
{ id: "bh_consults_medical", name: "BH Consults on a Medical Floor", category: "Professional Services", description: "Behavioral health consultations on medical floor" },
{ id: "ip_psych_testing", name: "IP Psych Testing", category: "Professional Services", description: "Inpatient psychological testing" },
{ id: "methadone_maintenance", name: "Methadone Maintenance", category: "Professional Services", description: "Methadone treatment program" },
{ id: "biofeedback", name: "Biofeedback", category: "Professional Services", description: "Biofeedback therapy" },
{ id: "suboxone", name: "Suboxone", category: "Professional Services", description: "Suboxone treatment" },
{ id: "hypnotherapy", name: "Hypnotherapy", category: "Professional Services", description: "Hypnosis therapy" },
{ id: "tms", name: "TMS - Transcranial Magnetic Stimulation", category: "Professional Services", description: "Transcranial magnetic stimulation treatment" }
],
"Alternative Levels of Care": [
{ id: "group_home", name: "Group Home", category: "Alternative Levels of Care", description: "Residential group home care" },
{ id: "halfway_house", name: "Halfway House", category: "Alternative Levels of Care", description: "Transitional residential care" },
{ id: "iop", name: "IOP", category: "Alternative Levels of Care", description: "Intensive outpatient program" },
{ id: "rtc", name: "RTC", category: "Alternative Levels of Care", description: "Residential treatment center" },
{ id: "ambulatory_detox", name: "Ambulatory Detox", category: "Alternative Levels of Care", description: "Outpatient detoxification" },
{ id: "partial_hosp", name: "Partial Hosp", category: "Alternative Levels of Care", description: "Partial hospitalization program" },
{ id: "crisis_intervention", name: "Crisis Intervention", category: "Alternative Levels of Care", description: "Emergency crisis intervention" }
],
"Emergency Services": [
{ id: "er_facility", name: "ER Facility", category: "Emergency Services", description: "Emergency room facility services" },
{ id: "er_professional", name: "ER Professional", category: "Emergency Services", description: "Emergency room professional services" },
{ id: "ect_ip_facility", name: "ECT IP Facility", category: "Emergency Services", description: "Electroconvulsive therapy inpatient facility" },
{ id: "ect_ip_professional", name: "ECT IP Professional", category: "Emergency Services", description: "Electroconvulsive therapy inpatient professional" },
{ id: "ect_ip_anesthesia", name: "ECT IP Anesthesia", category: "Emergency Services", description: "Electroconvulsive therapy inpatient anesthesia" },
{ id: "ect_op_facility", name: "ECT OP Facility", category: "Emergency Services", description: "Electroconvulsive therapy outpatient facility" },
{ id: "ect_op_professional", name: "ECT OP Professional", category: "Emergency Services", description: "Electroconvulsive therapy outpatient professional" },
{ id: "ect_op_anesthesia", name: "ECT OP Anesthesia", category: "Emergency Services", description: "Electroconvulsive therapy outpatient anesthesia" }
],
"Other Services": [
{ id: "op_labs_diagnostic", name: "OP Labs & Diagnostic Testing", category: "Other Services", description: "Outpatient laboratory and diagnostic testing" },
{ id: "ip_labs_diagnostic", name: "IP Labs & Diagnostic Testing", category: "Other Services", description: "Inpatient laboratory and diagnostic testing" },
{ id: "injections", name: "Injections", category: "Other Services", description: "Injectable medications and treatments" },
{ id: "ambulance", name: "Ambulance", category: "Other Services", description: "Ambulance transportation services" }
]
};
// Flatten all services for searching
const allServices = Object.values(serviceCategories).flat();
// Filter services based on search term and category
const filteredServices = allServices.filter(service => {
const matchesSearch = service.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
service.description?.toLowerCase().includes(searchTerm.toLowerCase());
const matchesCategory = selectedCategory === 'All' || service.category === selectedCategory;
return matchesSearch && matchesCategory;
});
// Reset temp selections when modal opens
useEffect(() => {
if (isOpen) {
setTempSelectedServices(selectedServices);
}
}, [isOpen]); // Remove selectedServices from dependency array to prevent infinite loop
const handleServiceToggle = (service: Service) => {
if (allowMultiple) {
setTempSelectedServices(prev => {
const isSelected = prev.some(s => s.id === service.id);
if (isSelected) {
return prev.filter(s => s.id !== service.id);
} else {
return [...prev, service];
}
});
} else {
// For single selection, always set the clicked service as the only selection
setTempSelectedServices([service]);
}
};
const handleConfirm = () => {
onServicesSelected(tempSelectedServices);
onClose();
};
const handleCancel = () => {
setTempSelectedServices(selectedServices);
onClose();
};
const isServiceSelected = (serviceId: string) => {
return tempSelectedServices.some(s => s.id === serviceId);
};
if (!isOpen) return null;
return (
<div style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(0, 0, 0, 0.7)',
backdropFilter: 'blur(5px)',
zIndex: 1000,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '20px'
}}>
<div style={{
background: 'white',
borderRadius: '16px',
width: '100%',
maxWidth: '800px',
maxHeight: '90vh',
display: 'flex',
flexDirection: 'column',
boxShadow: '0 20px 60px rgba(0, 0, 0, 0.3)',
overflow: 'hidden'
}}>
{/* Header */}
<div style={{
padding: '24px 32px',
borderBottom: '1px solid #e2e8f0',
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
color: 'white'
}}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<h2 style={{
margin: 0,
fontSize: '1.5rem',
fontWeight: '700',
display: 'flex',
alignItems: 'center',
gap: '12px'
}}>
πŸ” {title}
</h2>
<button
onClick={handleCancel}
style={{
background: 'rgba(255, 255, 255, 0.2)',
border: 'none',
borderRadius: '8px',
color: 'white',
width: '32px',
height: '32px',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '16px',
fontWeight: 'bold',
transition: 'background-color 0.2s ease'
}}
onMouseEnter={(e) => e.currentTarget.style.background = 'rgba(255, 255, 255, 0.3)'}
onMouseLeave={(e) => e.currentTarget.style.background = 'rgba(255, 255, 255, 0.2)'}
>
βœ•
</button>
</div>
{/* Selection Summary */}
<div style={{
marginTop: '12px',
fontSize: '14px',
opacity: 0.9
}}>
{tempSelectedServices.length === 0 ? (
`No services selected β€’ ${allowMultiple ? 'Select multiple services' : 'Select a service'}`
) : (
`${tempSelectedServices.length} service${tempSelectedServices.length !== 1 ? 's' : ''} selected`
)}
</div>
</div>
{/* Search and Filter Controls */}
<div style={{
padding: '20px 32px',
borderBottom: '1px solid #e2e8f0',
background: '#f8fafc'
}}>
<div style={{ display: 'flex', gap: '16px', marginBottom: '16px' }}>
{/* Search Input */}
<div style={{ flex: 1 }}>
<input
type="text"
placeholder="Search services..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
style={{
width: '100%',
padding: '12px 16px',
border: '2px solid #e2e8f0',
borderRadius: '8px',
fontSize: '14px',
outline: 'none',
transition: 'border-color 0.2s ease'
}}
onFocus={(e) => e.currentTarget.style.borderColor = '#667eea'}
onBlur={(e) => e.currentTarget.style.borderColor = '#e2e8f0'}
/>
</div>
{/* Category Filter */}
<div>
<select
value={selectedCategory}
onChange={(e) => setSelectedCategory(e.target.value)}
style={{
padding: '12px 16px',
border: '2px solid #e2e8f0',
borderRadius: '8px',
fontSize: '14px',
minWidth: '200px',
background: 'white',
outline: 'none'
}}
>
<option value="All">All Categories</option>
{Object.keys(serviceCategories).map(category => (
<option key={category} value={category}>{category}</option>
))}
</select>
</div>
</div>
{/* Quick Stats */}
<div style={{
display: 'flex',
gap: '16px',
fontSize: '12px',
color: '#6b7280'
}}>
<span>πŸ“Š {filteredServices.length} services found</span>
<span>πŸ“‚ {Object.keys(serviceCategories).length} categories</span>
</div>
</div>
{/* Services List */}
<div style={{
flex: 1,
overflow: 'auto',
padding: '20px 32px'
}}>
{filteredServices.length === 0 ? (
<div style={{
textAlign: 'center',
padding: '40px 20px',
color: '#6b7280'
}}>
<div style={{ fontSize: '48px', marginBottom: '16px' }}>πŸ”</div>
<p style={{ fontSize: '16px', fontWeight: '500', marginBottom: '8px' }}>
No services found
</p>
<p style={{ fontSize: '14px' }}>
Try adjusting your search terms or category filter
</p>
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{Object.entries(serviceCategories).map(([categoryName, services]) => {
const categoryServices = services.filter(service =>
filteredServices.some(fs => fs.id === service.id)
);
if (categoryServices.length === 0) return null;
return (
<div key={categoryName}>
{selectedCategory === 'All' && (
<h3 style={{
color: '#374151',
fontSize: '16px',
fontWeight: '600',
margin: '20px 0 12px 0',
padding: '0 0 8px 0',
borderBottom: '2px solid #e2e8f0'
}}>
{categoryName}
</h3>
)}
{categoryServices.map(service => (
<div
key={service.id}
onClick={() => handleServiceToggle(service)}
style={{
padding: '16px',
border: `2px solid ${isServiceSelected(service.id) ? '#667eea' : '#e2e8f0'}`,
borderRadius: '8px',
cursor: 'pointer',
transition: 'all 0.2s ease',
background: isServiceSelected(service.id) ? '#f0f4ff' : 'white',
position: 'relative'
}}
onMouseEnter={(e) => {
if (!isServiceSelected(service.id)) {
e.currentTarget.style.borderColor = '#cbd5e1';
e.currentTarget.style.background = '#f8fafc';
}
}}
onMouseLeave={(e) => {
if (!isServiceSelected(service.id)) {
e.currentTarget.style.borderColor = '#e2e8f0';
e.currentTarget.style.background = 'white';
}
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
{/* Selection Indicator */}
<div style={{
width: '20px',
height: '20px',
borderRadius: allowMultiple ? '4px' : '50%',
border: `2px solid ${isServiceSelected(service.id) ? '#667eea' : '#d1d5db'}`,
background: isServiceSelected(service.id) ? '#667eea' : 'transparent',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '12px',
color: 'white',
fontWeight: 'bold'
}}>
{isServiceSelected(service.id) && (allowMultiple ? 'βœ“' : '●')}
</div>
<div style={{ flex: 1 }}>
<h4 style={{
margin: '0 0 4px 0',
fontSize: '15px',
fontWeight: '600',
color: '#1f2937'
}}>
{service.name}
</h4>
{service.description && (
<p style={{
margin: 0,
fontSize: '13px',
color: '#6b7280',
lineHeight: '1.4'
}}>
{service.description}
</p>
)}
</div>
{/* Category Badge */}
{selectedCategory === 'All' && (
<div style={{
padding: '4px 8px',
background: '#e2e8f0',
borderRadius: '6px',
fontSize: '11px',
fontWeight: '500',
color: '#4b5563'
}}>
{service.category}
</div>
)}
</div>
</div>
))}
</div>
);
})}
</div>
)}
</div>
{/* Footer Actions */}
<div style={{
padding: '20px 32px',
borderTop: '1px solid #e2e8f0',
background: '#f8fafc',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
}}>
{/* Selected Services Count */}
<div style={{ fontSize: '14px', color: '#6b7280' }}>
{tempSelectedServices.length > 0 && (
<span>
<strong>{tempSelectedServices.length}</strong> service{tempSelectedServices.length !== 1 ? 's' : ''} selected
</span>
)}
</div>
{/* Action Buttons */}
<div style={{ display: 'flex', gap: '12px' }}>
<button
onClick={handleCancel}
style={{
padding: '12px 24px',
background: 'transparent',
border: '2px solid #d1d5db',
borderRadius: '8px',
color: '#6b7280',
cursor: 'pointer',
fontSize: '14px',
fontWeight: '600',
transition: 'all 0.2s ease'
}}
onMouseEnter={(e) => {
e.currentTarget.style.borderColor = '#9ca3af';
e.currentTarget.style.color = '#374151';
}}
onMouseLeave={(e) => {
e.currentTarget.style.borderColor = '#d1d5db';
e.currentTarget.style.color = '#6b7280';
}}
>
Cancel
</button>
<button
onClick={handleConfirm}
disabled={tempSelectedServices.length === 0}
style={{
padding: '12px 24px',
background: tempSelectedServices.length === 0 ? '#e5e7eb' : 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
border: 'none',
borderRadius: '8px',
color: 'white',
cursor: tempSelectedServices.length === 0 ? 'not-allowed' : 'pointer',
fontSize: '14px',
fontWeight: '600',
transition: 'all 0.2s ease',
minWidth: '100px'
}}
>
{tempSelectedServices.length === 0 ? 'Select Services' :
allowMultiple ? `Add ${tempSelectedServices.length} Service${tempSelectedServices.length !== 1 ? 's' : ''}` :
'Select Service'}
</button>
</div>
</div>
</div>
</div>
);
};
export default ServiceLookupComponent;