@@ -18,24 +18,61 @@ async function stateChange(state) {
1818 if ( state === 'loggedIN' ) {
1919 document . getElementById ( 'please-login' ) . style . visibility = 'hidden' ;
2020 document . getElementById ( 'data-view' ) . style . visibility = 'visible' ;
21- setSharingLink ( ) ;
22- const { headers, patientsData} = await setPatientList ( questionaryId ) ;
23- document . getElementById ( 'button-download' ) . onclick = ( ) => {
24- exportCSVFile ( headers , patientsData , 'patients' ) ;
25- }
21+ setQuestionnaries ( ) ;
2622
2723 } else {
2824 document . getElementById ( 'please-login' ) . style . visibility = 'visible' ;
2925 document . getElementById ( 'data-view' ) . style . visibility = 'hidden' ;
3026 }
3127}
3228
29+ async function setQuestionnaries ( ) {
30+ const select = document . getElementById ( "select-questionnary" ) ;
31+ const optionNull = document . createElement ( "option" ) ;
32+ optionNull . text = '---' ;
33+ optionNull . value = '' ;
34+ select . add ( optionNull ) ;
35+
36+ const quests = await drLib . getQuestionnaires ( ) ;
37+ for ( const [ key , value ] of Object . entries ( quests ) ) {
38+ const option = document . createElement ( "option" ) ;
39+ option . text = value . title ;
40+ option . value = key ;
41+ select . add ( option ) ;
42+ }
43+
44+ // --
45+ select . onchange = function ( ) {
46+ if ( select . value === '' ) {
47+ showQuestionnary ( null ) ;
48+ return ;
49+ }
50+ showQuestionnary ( select . value ) ;
51+ }
52+ }
53+
54+ async function showQuestionnary ( questionaryId ) {
55+ if ( questionaryId == null ) {
56+ document . getElementById ( 'questionnary-view' ) . style . visibility = 'hidden' ;
57+ return ;
58+ }
59+
60+ setSharingLink ( questionaryId ) ;
61+ const { headers, patientsData} = await setPatientList ( questionaryId ) ;
62+ document . getElementById ( 'button-download' ) . onclick = ( ) => {
63+ exportCSVFile ( headers , patientsData , 'patients' ) ;
64+ }
65+ document . getElementById ( 'questionnary-view' ) . style . visibility = 'visible' ;
66+ }
67+
3368const rowItems = [ 'name' , 'surname' , 'nationality' ] ;
3469/**
3570 * Update the patient list
3671 */
3772async function setPatientList ( questionaryId ) {
3873 const table = document . getElementById ( 'patients-table' ) ;
74+ // clear table
75+ table . innerHTML = '' ;
3976 const fields = drLib . getFields ( questionaryId ) ;
4077 const headers = {
4178 status : 'Status' ,
@@ -84,12 +121,12 @@ async function setPatientList(questionaryId) {
84121/**
85122 * Creates the sharing link on the page
86123 */
87- async function setSharingLink ( ) {
124+ async function setSharingLink ( questionaryId ) {
88125 const currentPage = window . location . href ;
89126 const posDrHTML = currentPage . indexOf ( 'dr.html' ) ;
90127 const patientURL = currentPage . substring ( 0 , posDrHTML ) + 'patient.html' ;
91128
92- const formApiEndpoint = await drLib . getSharingToken ( ) ;
129+ const formApiEndpoint = await drLib . getSharingToken ( questionaryId ) ;
93130 const sharingLink = patientURL + '?formApiEndpoint=' + formApiEndpoint ;
94131 const sharingMailBody = 'Hello,\n\nI am sending you a link to fill out a form.\nPlease click on the link below to access the form: \n\n' + sharingLink + '\n\nBest regards,\nYour Doctor' ;
95132 const sharingLinkHTML = `<A HREF="mailto:?subject=Invitation&body=${ encodeURI ( sharingMailBody ) } ">Send by email</A> - ${ sharingLink } ` ;
0 commit comments