1+ import { initHDSModel , stateGetApp } from "./common-lib.js" ;
12import { drPatientLib } from "./dr-patient-view-lib.js" ;
23import { exportXLSFile } from './exporToXLS.js' ;
3- import { patientLib } from "./patient-lib.js" ;
4+
45/**
56 * Based on
67 * - drApiConnecion
@@ -11,24 +12,29 @@ import { patientLib } from "./patient-lib.js";
1112 */
1213
1314
14- let infos ;
15- let username ;
16- let qId ;
15+ let invite ;
1716window . onload = async ( event ) => {
18- const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint ( ) ;
19- infos = await drPatientLib . setRefresh ( patientApiEndpoint , questionaryId , refresh )
17+ await initHDSModel ( ) ;
18+ // get collectorId & inviteKey from URL
19+ const params = new URLSearchParams ( document . location . search ) ;
20+ const collectorId = params . get ( 'collectorId' ) ;
21+ const inviteKey = params . get ( 'inviteKey' ) ;
22+
23+ // get app from state management
24+ const appManaging = await stateGetApp ( 'managing' ) ;
25+ const collector = await appManaging . getCollectorById ( collectorId ) ;
26+ invite = await collector . getInviteByKey ( inviteKey ) ;
27+ console . log ( '# Loaded with invite' , invite ) ;
28+
29+ await drPatientLib . setRefresh ( invite , refresh )
2030 // -- home button
21- document . getElementById ( 'home-button' ) . href = 'dr.html?questionaryId =' + questionaryId ;
31+ document . getElementById ( 'home-button' ) . href = 'dr.html?collectorId =' + collectorId ;
2232
2333 // - form title
2434 const formTitle = document . getElementById ( 'card-questionnary-details-title' ) ;
25- formTitle . innerHTML = patientLib . getFormTitle ( questionaryId ) ;
26-
27- qId = questionaryId ;
35+ formTitle . innerHTML = collector . name ;
2836
29- // -- set patient Id
30- username = infos . user . username ;
31- document . getElementById ( 'patient-label' ) . innerHTML = username ;
37+ document . getElementById ( 'patient-label' ) . innerHTML = invite . displayName ;
3238}
3339
3440const tableHeaders = {
@@ -48,7 +54,7 @@ const downloadHeaders = Object.assign({
4854async function refresh ( lines ) {
4955 // -- set download button
5056 document . getElementById ( 'button-download' ) . onclick = async ( ) => {
51- await exportXLSFile ( downloadHeaders , lines , username + '-' + qId ) ;
57+ await exportXLSFile ( downloadHeaders , lines , invite . displayName + '-' + invite . collector . name ) ;
5258 } ;
5359
5460 // -- update table
@@ -70,11 +76,3 @@ async function refresh (lines) {
7076 }
7177 }
7278}
73-
74- // ------- Get Dr's info -------- //
75- function getRequestFrormApiEndPoint ( ) {
76- const params = new URLSearchParams ( document . location . search ) ;
77- const patientApiEndpoint = params . get ( 'patientApiEndpoint' ) ;
78- const questionaryId = params . get ( 'questionaryId' ) ;
79- return { patientApiEndpoint, questionaryId } ;
80- }
0 commit comments