@@ -15,16 +15,34 @@ async function stateChange(state) {
1515 document . getElementById ( 'please-login' ) . style . visibility = 'hidden' ;
1616 document . getElementById ( 'data-view' ) . style . visibility = 'visible' ;
1717 setSharingLink ( ) ;
18- await drLib . getPatientsList ( ) ;
18+ setPatientList ( ) ;
1919 } else {
2020 document . getElementById ( 'please-login' ) . style . visibility = 'visible' ;
2121 document . getElementById ( 'data-view' ) . style . visibility = 'hidden' ;
2222 }
2323}
2424
25- async function setSharingLink ( ) {
26-
25+ const rowItems = [ 'name' , 'surname' , 'nationality' ] ;
26+ /**
27+ * Update the patient list
28+ */
29+ async function setPatientList ( ) {
30+ const table = document . getElementById ( 'patients-table' ) ;
31+ const patients = await drLib . getPatientsList ( ) ;
32+ for ( const patient of Object . values ( patients ) ) {
33+ const row = table . insertRow ( - 1 ) ;
34+ const cellUsername = row . insertCell ( - 1 ) ;
35+ cellUsername . innerHTML = patient . username ;
36+ for ( const field of rowItems ) {
37+ row . insertCell ( - 1 ) . innerHTML = patient . formData [ field ] ?. value || '' ;
38+ }
39+ }
40+ }
2741
42+ /**
43+ * Creates the sharing link on the page
44+ */
45+ async function setSharingLink ( ) {
2846 const currentPage = window . location . href ;
2947 const posDrHTML = currentPage . indexOf ( 'dr.html' ) ;
3048 const patientURL = currentPage . substring ( 0 , posDrHTML ) + 'patient.html' ;
0 commit comments