11import { dataDefs } from './common-data-defs.js' ;
22import { CookieUtils } from './CookieUtils.js' ;
33
4+
5+
46export const patientLib = {
57 handleFormSubmit,
68 getFormTitle,
79 getFormContent,
810 connect,
9- getNavigationQueryParams,
1011 navSetData,
11- navGetData
12+ navGetData,
13+ getForms,
14+ navGetPages
1215}
1316
1417
@@ -22,10 +25,6 @@ async function connect (apiEndpoint, questionaryId) {
2225 return accessInfo ;
2326}
2427
25- function getNavigationQueryParams ( ) {
26- return `?patientApiEndpoint=${ connection . apiEndpoint } &questionaryId=${ _questionaryId } `
27- }
28-
2928// --------------- navigation - to be replaced if built-in framework ------- //
3029
3130const COOKIE_KEY = 'hds-' + dataDefs . appId ;
@@ -35,7 +34,34 @@ function navSetData(data) {
3534}
3635
3736function navGetData ( ) {
38- return CookieUtils . get ( COOKIE_KEY ) ;
37+ const cookieContent = CookieUtils . get ( COOKIE_KEY ) ;
38+ const formKey = ( new URLSearchParams ( window . location . search ) ) . get ( 'formKey' ) ;
39+ return Object . assign ( { formKey } , cookieContent ) ;
40+ }
41+
42+ const pagesByTypes = {
43+ home : 'patient.html' ,
44+ permanent : 'patient-profile.html' ,
45+ recurring : 'patient-history.html'
46+ } ;
47+
48+ async function navGetPages ( questionaryId ) {
49+ const pages = [ {
50+ type : 'home' ,
51+ url : pagesByTypes . home ,
52+ label : 'Home' ,
53+ formKey : null
54+ } ] ;
55+ const forms = await patientLib . getForms ( questionaryId ) ;
56+ for ( const [ formKey , form ] of Object . entries ( forms ) ) {
57+ pages . push ( {
58+ type : form . type ,
59+ label : form . name ,
60+ url : pagesByTypes [ form . type ] + '?formKey=' + formKey ,
61+ formKey
62+ } ) ;
63+ }
64+ return pages ;
3965}
4066
4167
@@ -45,6 +71,11 @@ function getFormTitle (questionaryId) {
4571 return dataDefs . questionnaires [ questionaryId ] . title ;
4672}
4773
74+ async function getForms ( questionaryId ) {
75+ return dataDefs . questionnaires [ questionaryId ] . forms ;
76+ }
77+
78+
4879async function getFormContent ( questionaryId , formKey ) {
4980 const form = dataDefs . questionnaires [ questionaryId ] . forms [ formKey ] ;
5081 console . log ( '## getFormContent' , form , questionaryId , formKey ) ;
0 commit comments