@@ -103,9 +103,9 @@ async function showQuestionnary(questionaryId) {
103103 await refreshInviteList ( collector ) ;
104104
105105 // show current patients
106- await setPatientList ( collector ) ;
106+ await refreshPatientList ( collector ) ;
107107
108- //const {headers, patientsData} = await setPatientList (questionaryId);
108+ //const {headers, patientsData} = await refreshPatientList (questionaryId);
109109 document . getElementById ( 'button-download' ) . onclick = async ( ) => {
110110 await exportXLSFile ( headers , patientsData , 'patients' ) ;
111111 }
@@ -144,73 +144,38 @@ async function refreshInviteList(collector) {
144144/**
145145 * Update the patient list
146146 */
147- async function setPatientList ( collector ) {
147+ async function refreshPatientList ( collector ) {
148+ const { headers, patientsData } = await drLib . getPatientsData ( collector ) ;
149+
148150 const table = document . getElementById ( 'patients-table' ) ;
149151
150152 const requestContent = collector . statusData . requestContent ;
151153 console . log ( '## collector requestContent' , requestContent ) ;
152154
153155 // clear table
154156 table . innerHTML = '' ;
155- const itemDefs = drLib . getFirstFormFields ( requestContent . app . data . forms ) ;
156- const staticHeaders = {
157- status : 'Status' ,
158- inviteName : 'Invite' ,
159- username : 'Username' ,
160- createdAt : 'Date'
161- }
162- const headers = structuredClone ( staticHeaders ) ;
163-
164157 // --- headers
165158 const headerRow = table . insertRow ( - 1 ) ;
166159 for ( const [ key , value ] of Object . entries ( headers ) ) {
167- const headerStatusCell = document . createElement ( "TH" ) ;
168- headerStatusCell . innerHTML = value ;
169- headerRow . appendChild ( headerStatusCell ) ;
170- }
171-
172- for ( const itemDef of itemDefs ) {
173160 const headerCell = document . createElement ( "TH" ) ;
174- headerCell . innerHTML = HDSLib . l ( itemDef . data . label ) ;
161+ headerCell . innerHTML = value ;
175162 headerRow . appendChild ( headerCell ) ;
176- headers [ itemDef . key ] = HDSLib . l ( itemDef . data . label ) ;
177163 }
178164
179165 // --- patients
180166
181- // get all invites
182- const invites = await collector . getInvites ( ) ;
183- const activeInvites = invites . filter ( i => i . status === 'active' ) ;
184- activeInvites . sort ( ( a , b ) => b . dateCreation - a . dateCreation ) ; // sort by creation date reverse
185-
186- // fetch patient data
187- const patientPromises = activeInvites . map ( ( invite ) =>
188- drLib . getPatientDetails ( invite , itemDefs )
189- ) ;
190- const patientsResults = await Promise . all ( patientPromises ) ;
191- console . log ( '## patientsResults' , patientsResults ) ;
192-
193- const patientsData = [ ] ;
194- for ( const patient of patientsResults ) {
167+ for ( const patient of patientsData ) {
195168 const row = table . insertRow ( - 1 ) ;
196- const patientData = { } ;
197-
198- for ( const key of Object . keys ( staticHeaders ) ) {
169+
170+ for ( const key of Object . keys ( headers ) ) {
199171 let text = patient [ key ] ;
200- patientData [ key ] = patient [ key ] ;
201- if ( key === 'inviteName' ) {
202- const page = `dr-patient-view.html?collectorKey=${ collector . key } ` ;
172+ if ( key === 'inviteName' ) { // for inviteName add a link
173+ const page = `dr-patient-view.html?collectorId=${ collector . id } &inviteKey=${ patient . invite . key } ` ;
203174 text = `<A HREF="${ page } ">${ patient . inviteName } </A>` ;
204175 }
205176 row . insertCell ( - 1 ) . innerHTML = text ;
206177 }
207178
208- for ( const itemDef of itemDefs ) {
209- const value = patient . formData [ itemDef . key ] ?. value ;
210- row . insertCell ( - 1 ) . innerHTML = ( value != null ) ? value : '' ;
211- patientData [ itemDef . key ] = value ;
212- }
213- patientsData . push ( patientData ) ;
214179 }
215180 // return this to be used by Excel Download
216181 return { headers, patientsData } ;
0 commit comments