@@ -30,6 +30,9 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
3030 // eslint-disable-next-line @typescript-eslint/no-unused-vars
3131 const [ highlightedRHF , setHighlightedRHF ] = useState < string > ( "" ) ;
3232
33+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34+ const [ highlightedHF , setHighlightedHF ] = useState < string > ( "" ) ;
35+
3336 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3437 const unitNamesQuery : UseQueryResult < any , unknown > = useUnitNamesQuery (
3538 "all" ,
@@ -69,6 +72,18 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
6972 return selectedSet . intersection ( hfSet ) . size > 0 ;
7073 } ;
7174
75+ const hospitalsChecked = ( ) => {
76+ const selectedSet = new Set ( [ ...unitSelection ] ) ;
77+ const hospitals = row . hf
78+ . map ( ( hf ) => {
79+ return hf . hospital ;
80+ } )
81+ . flat ( ) ;
82+
83+ const hospitalSet = new Set ( [ ...hospitals ] ) ;
84+ return selectedSet . intersection ( hospitalSet ) . size > 0 ;
85+ } ;
86+
7287 return (
7388 < FormControlLabel
7489 label = { row . rhf }
@@ -79,7 +94,10 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
7994 control = {
8095 < Checkbox
8196 checked = { unitSelection . includes ( row . rhf ) }
82- indeterminate = { ! unitSelection . includes ( row . rhf ) && hfChecked ( ) }
97+ indeterminate = {
98+ ! unitSelection . includes ( row . rhf ) &&
99+ ( hfChecked ( ) || hospitalsChecked ( ) )
100+ }
83101 onChange = { handleChange }
84102 key = { row . rhf + "_checkbox" }
85103 />
@@ -89,6 +107,7 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
89107 } ) as JSX . Element [ ] ) ;
90108
91109 const HFCheckBoxes = { } ;
110+ const HospitalCheckBoxes = { } ;
92111
93112 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
94113 unitNames &&
@@ -97,6 +116,39 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
97116 return a . hf_sort - b . hf_sort ;
98117 } ) ;
99118
119+ // Add hospitals to the list
120+ hfs . map ( ( hf ) => {
121+ const CheckBoxes = hf . hospital . map ( ( hospital ) => {
122+ const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
123+ if ( event . target . checked ) {
124+ const newUnitSelection = [ ...unitSelection , hospital ] ;
125+ setUnitSelection ( [ ...newUnitSelection ] ) ;
126+ } else {
127+ const newUnitSelection = [
128+ ...unitSelection . filter ( ( row ) => {
129+ return row != hospital ;
130+ } ) ,
131+ ] ;
132+ setUnitSelection ( newUnitSelection ) ;
133+ }
134+ } ;
135+ return (
136+ < FormControlLabel
137+ label = { hospital }
138+ key = { hospital }
139+ control = {
140+ < Checkbox
141+ checked = { unitSelection . includes ( hospital ) }
142+ onChange = { handleChange }
143+ key = { hospital + "_checkbox" }
144+ />
145+ }
146+ />
147+ ) ;
148+ } ) ;
149+ HospitalCheckBoxes [ hf . hf ] = CheckBoxes ;
150+ } ) ;
151+
100152 const CheckBoxes = hfs . map ( ( hf ) => {
101153 const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
102154 if ( event . target . checked ) {
@@ -111,13 +163,26 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
111163 setUnitSelection ( newHFSelection ) ;
112164 }
113165 } ;
166+
167+ const hospitalChecked = ( ) => {
168+ const selectedSet = new Set ( [ ...unitSelection ] ) ;
169+ const hospitalSet = new Set ( [ ...hf . hospital ] ) ;
170+ return selectedSet . intersection ( hospitalSet ) . size > 0 ;
171+ } ;
172+
114173 return (
115174 < FormControlLabel
116175 label = { hf . hf }
117176 key = { hf . hf }
177+ onMouseEnter = { ( ) => {
178+ setHighlightedHF ( hf . hf ) ;
179+ } }
118180 control = {
119181 < Checkbox
120182 checked = { unitSelection . includes ( hf . hf ) }
183+ indeterminate = {
184+ ! unitSelection . includes ( hf . hf ) && hospitalChecked ( )
185+ }
121186 onChange = { handleChange }
122187 key = { hf . hf + "_checkbox" }
123188 />
@@ -146,20 +211,29 @@ export const TreatmentUnitPopup = (props: TreatmentUnitPopupProps) => {
146211 sx = { { height : 1000 } }
147212 onMouseLeave = { ( ) => {
148213 setHighlightedRHF ( "" ) ;
214+ setHighlightedHF ( "" ) ;
149215 } }
150216 >
151217 < Grid container spacing = { 2 } >
152- < Grid size = { 6 } >
153- < FormControl sx = { { m : 1 , width : "50 %" } } >
218+ < Grid size = { 4 } >
219+ < FormControl sx = { { m : 1 , width : "100 %" } } >
154220 { RHFCheckboxes && RHFCheckboxes . map ( ( row : JSX . Element ) => row ) }
155221 </ FormControl >
156222 </ Grid >
157- < Grid size = { 6 } >
158- < FormControl sx = { { m : 1 , width : "50 %" } } >
223+ < Grid size = { 4 } >
224+ < FormControl sx = { { m : 1 , width : "100 %" } } >
159225 { HFCheckBoxes [ highlightedRHF ] &&
160226 HFCheckBoxes [ highlightedRHF ] . map ( ( row : JSX . Element ) => row ) }
161227 </ FormControl >
162228 </ Grid >
229+ < Grid size = { 4 } >
230+ < FormControl sx = { { m : 1 , width : "100%" } } >
231+ { HospitalCheckBoxes [ highlightedHF ] &&
232+ HospitalCheckBoxes [ highlightedHF ] . map (
233+ ( row : JSX . Element ) => row ,
234+ ) }
235+ </ FormControl >
236+ </ Grid >
163237 </ Grid >
164238 </ DialogContent >
165239 < DialogActions >
0 commit comments