1+ /**
2+ * UI management code.
3+ * Relies on patientLib for API calls and data management
4+ *
5+ * @param {* } event
6+ */
7+
8+ window . onload = async ( event ) => {
9+ const { patientApiEndpoint, questionaryId } = getPatientApiEndpointAndFormId ( ) ;
10+ console . log ( '## patientApiEndpoint:' , patientApiEndpoint ) ;
11+ await connect ( patientApiEndpoint , questionaryId ) ;
12+ // -- navigation
13+ document . getElementById ( 'nav-profile' ) . onclick = ( ) => {
14+ document . location . href = 'patient-profile.html' + patientLib . getNavigationQueryParams ( ) ;
15+ } ;
16+
17+ // -- connection
18+ updateFormContent ( questionaryId , 'history' ) ;
19+ document . getElementById ( 'submit-button-history' ) . addEventListener ( "click" , function ( ) {
20+ submitForm ( questionaryId , 'history' ) ;
21+ } ) ;
22+ }
23+
24+
25+ // ------- Get Questionnary and endpoint info -------- //
26+ function getPatientApiEndpointAndFormId ( ) {
27+ const params = new URLSearchParams ( document . location . search ) ;
28+ const patientApiEndpoint = params . get ( 'patientApiEndpoint' ) ;
29+ const questionaryId = params . get ( 'questionaryId' ) ;
30+ if ( ! patientApiEndpoint ) {
31+ alert ( 'No patientApiEndpoint found in the URL' ) ;
32+ return ;
33+ }
34+ if ( ! questionaryId ) {
35+ alert ( 'No questionaryId found in the URL' ) ;
36+ return ;
37+ }
38+ return { patientApiEndpoint, questionaryId } ;
39+ }
40+
41+
42+ // ------- Form -------- //
43+
44+ /**
45+ * Take the from content from the definition and actual values and create the HTML
46+ */
47+ async function updateFormContent ( questionaryId , formKey ) {
48+ const formData = await patientLib . getFormContent ( questionaryId , formKey ) ;
49+ console . log ( 'Form content:' , formData ) ;
50+
51+ }
52+
53+ /**
54+ * Submit the form and send the data to the API
55+ */
56+ async function submitForm ( questionaryId , formKey ) {
57+
58+ } ;
0 commit comments