Spaces:
Runtime error
Runtime error
File size: 21,656 Bytes
b366dd7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | 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; |