]> git.plutz.net Git - lobster/blob - therapies/page.sh
functions for easyer tpy/mpx file parsing, deliver png overlays
[lobster] / therapies / page.sh
1 # Copyright 2016, 2017, 2020 Paul Hänsch
2 #
3 # This file is part of Lobster.
4
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
10 # Lobster is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Lobster.  If not, see <http://www.gnu.org/licenses/>. 
17
18 t_session_note(){
19   session_n="$1"
20   note_n="$2"
21   
22   color=session${session_n}_note${note_n}_color
23   
24   if [ "$note_n" -eq 1 -o "$(TPY "session${session_n}_note${note_n}")" ]; then
25     printf '[input type="checkbox" .trailbtn checked="checked"]'
26   else
27     printf '[input type="checkbox" .trailbtn]'
28   fi
29
30   check="$(TPY "$color" |grep -xE -m1 '#(888|00A|0A0|0AA|A00|A0A|AA0)' || printf '#FFF')"
31   cat <<-EOF
32         [fieldset .note .trailbox
33           [radio "$color" "#888" .color #${color}_000 $(checked "$check" '#888') ][label for=${color}_000]
34           [radio "$color" "#00A" .color #${color}_001 $(checked "$check" '#00A') ][label for=${color}_001]
35           [radio "$color" "#0A0" .color #${color}_010 $(checked "$check" '#0A0') ][label for=${color}_010]
36           [radio "$color" "#0AA" .color #${color}_011 $(checked "$check" '#0AA') ][label for=${color}_011]
37           [radio "$color" "#A00" .color #${color}_100 $(checked "$check" '#A00') ][label for=${color}_100]
38           [radio "$color" "#A0A" .color #${color}_101 $(checked "$check" '#A0A') ][label for=${color}_101]
39           [radio "$color" "#AA0" .color #${color}_110 $(checked "$check" '#AA0') ][label for=${color}_110]
40           [radio "$color" "#FFF" .color #${color}_111 $(checked "$check" '#FFF') ][label for=${color}_111]
41           [textarea name="session${session_n}_note${note_n}" . $(TPY "session${session_n}_note${note_n}" |HTML)]
42         ]
43         EOF
44 }
45
46 therapy_sessions(){
47   n=1; while [ "$(TPY session$n)" ]; do
48     session_n="$n"
49     sid=session${session_n}
50
51     cat <<-EOF
52         [hidden "$sid" "exists"]
53         [checkbox "${sid}_open" "checked" #${sid}_open .tab $(checked "$(TPY "${sid}_open")" checked)]
54         [label .tab for="${sid}_open"
55           [span .no ${session_n}.]
56           [span .date . $(TPY "${sid}_date" |HTML)]
57           [input .date name="${sid}_date" value="$(TPY "${sid}_date" |HTML)" placeholder="$(l10n date)"]
58           [span .therapist . $(TPY "${sid}_therapist" |HTML)]
59           [input .therapist name="${sid}_therapist" value="$(TPY "${sid}_therapist" |HTML)" placeholder="$(l10n therapist)"]
60           [span .signature [checkbox "${sid}_sigset" "pos" $(checked "$(TPY "${sid}_sigset")" "pos")]]
61         ]
62         [div .tab
63           [img .dotmark .ov src="/therapies/${id}_${sid}.png" alt=""]
64           $(n=1; while TPY "session${session_n}_note${n}" >/dev/null; do
65               [ "$(TPY "session${session_n}_note${n}")" ] && x=$n
66               n=$(($n + 1))
67             done
68             for n in $(seq 1 $((${x:-0} + 3)) ); do
69               t_session_note $session_n $n
70             done
71           )
72           [button type="submit" .trailbtn $(l10n trailbtn)]
73           [button type="submit" name=delete_session value="$session_n" .delete $(l10n delete_session)]
74         ]
75         EOF
76     n=$(($n+1))
77   done
78
79   sid=session$n
80
81   cat <<-EOF
82         [fieldset .tab
83           [submit "new_session" "$sid" .no . +]
84           [input .date name="${sid}_date" value="" placeholder=$(l10n date)]
85           [input .therapist name="${sid}_therapist" value="" placeholder=$(l10n therapist)]
86           [span .signature]
87           [hidden "${sid}_note1" ""]
88         ]
89         EOF
90 }
91
92 cat <<EOF
93 [h1 $(l10n therapy)]
94
95 [div .patient
96   [h2 . $(VCF FN |HTML)]
97   [a href="/cards/#${id%.*}.vcf" \< $(l10n client)]
98 ]
99
100 [div .prescription
101   [h2 $(l10n therapy_prescription)]
102   [span .insurance . $(MPX insurance |HTML)]
103   [span .date [label $(l10n date):] $(MPX date |HTML)]
104 EOF
105
106   if [ "$(MPX prescreviewed)" ]; then
107     printf '[label .checkbox .checked for=prescreviewed . %s]' "$(l10n prescreviewed)"
108   else
109     printf '[label .checkbox for=prescreviewed . %s]' "$(l10n prescreview)"
110   fi
111
112   field="$(MPX prescno)"
113   [ "$field" ] && printf '[span .prescno . %s]' "$(l10n "presc$field")"
114   for field in grouptherapy housecall report; do
115     [ "$(MPX "$field")" ] && printf '[span .catalogue . %s]' "$(l10n "$field")"
116   done
117
118   printf '[ul'
119   for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
120     remidy="$(MPX remidy$n)"
121     quantity="$(MPX quantity$n)"
122     quantity_weekly="$(MPX quantity_weekly$n)"
123
124     if [ "$remidy" -a "$quantity_weekly" ]; then
125       printf '[li %s %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")" "$(HTML "$quantity_weekly") $(l10n weekly)"
126     elif [ "$remidy" ]; then
127       printf '[li %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")"
128     fi
129   done
130   printf ']'
131
132   for field in indicator icd10; do
133     val="$(MPX "$field")"
134     [ "$val" ] && printf '[span .%s [label . %s:]%s]' "$field" "$(l10n "$field")" "$(HTML "$val")"
135   done
136
137   addcontrib="$(MPX addcontrib)"
138   contribconfirm="$(MPX contribconfirm)"
139
140   if [ "$addcontrib" -a "$contribconfirm" ]; then
141     printf '[label .checkbox .checked for=addcontrib . %s %s]' "$(l10n contribconfirm)" "$(HTML $contribconfirm)"
142   elif [ "$addcontrib" ]; then
143     printf '[label .checkbox for=addcontrib . %s]' "$(l10n addcontrib)"
144   fi
145
146 cat <<EOF
147   [input .tab type="checkbox" #indicator_reading][label .tab for=indicator_reading $(l10n indicator_reading)]
148   [div .tab . $(MPX indicator_reading |HTML)]
149 ]
150
151 [form #report method=POST action="/therapies/update_therapy.sh"
152   [hidden "id" "$id"]
153
154   [input .stickynote type=checkbox name=c_stickynote #show_stickynote]
155   [fieldset .stickynote
156     [label for="show_stickynote" $(l10n notes)]
157     [h2 $(l10n notes)]
158     [textarea name=stickynote . $(TPY stickynote |HTML)]
159     [button type=submit $(l10n save)]
160   ]
161
162   [input .stickynote type=checkbox name=c_timesheet #show_timesheet]
163   [fieldset .stickynote
164     [label for="show_timesheet" $(l10n timesheet)]
165     [h2 $(l10n timesheet)]
166     [table [thead [tr
167       [th $(l10n time_goal)][th $(l10n time_actual)][th $(l10n time_difference)]
168     ]][tbody
169       $(for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
170         tsgoal="$(TPY tsgoal$n |grep -m1 -xE '[0-9]+')"
171         tsactual="$(TPY tsactual$n |grep -m1 -xE '[0-9]+')"
172         printf '[tr [td [input type=number name=tsgoal value="%s"]][td [input type=number name=tsactual value="%s"]][td %s]]' \
173                "$tsgoal" "$tsactual" "$(( ${tsgoal:-0} - ${tsactual:-0} ))"
174       done)
175     ]]
176     [button type=submit $(l10n save)]
177   ]
178
179   [label .tab .heading
180     [span .no $(l10n number)][span .date $(l10n date)][span .therapist $(l10n therapist)][span .signature $(l10n signature)]
181   ]
182 EOF
183
184 therapy_sessions
185
186 ## ==== Drawing canvas ==== ##
187 ### ====================== ###
188
189 penwidth="$(TPY penwidth |grep -xE -m1 '(4|12|36)' || printf '4')"
190 color="$(TPY color |grep -xE -m1 '#(000|00A|0A0|0AA|A00|A0A|AA0|FFF)' || printf '#000')"
191 cat <<EOF
192   [fieldset .penwidth
193     [radio "penwidth" "4"  #pw1 $(selected $penwidth 4) ][label for="pw2"]
194     [radio "penwidth" "12" #pw2 $(selected $penwidth 12)][label for="pw3"]
195     [radio "penwidth" "36" #pw3 $(selected $penwidth 36)][label for="pw1"]
196   ]
197   [fieldset .color
198     [radio "color" "#000" .color #c000 $(checked $color '#000') ][label for=c000 ]
199     [radio "color" "#00A" .color #c001 $(checked $color '#00A') ][label for=c001 ]
200     [radio "color" "#0A0" .color #c010 $(checked $color '#0A0') ][label for=c010 ]
201     [radio "color" "#0AA" .color #c011 $(checked $color '#0AA') ][label for=c011 ]
202     [radio "color" "#A00" .color #c100 $(checked $color '#A00') ][label for=c100 ]
203     [radio "color" "#A0A" .color #c101 $(checked $color '#A0A') ][label for=c101 ]
204     [radio "color" "#AA0" .color #c110 $(checked $color '#AA0') ][label for=c110 ]
205     [radio "color" "#FFF" .color #c111 $(checked $color '#FFF') ][label for=c111 ]
206   ]
207   [img .dotmark .bg src="/therapies/therapy_background.png" alt="WARNING: Missing background image!"]
208   [canvas #canvas .dotmark .ov width="${bg_dim%x*}" height="${bg_dim#*x}" ]
209   [input type=hidden #image_serialize name=imagedata value=""]
210
211   [button type=submit $(l10n save)]
212 ]
213
214 [span #jsdebug style="display: none; position: fixed; right:0; bottom:0" Debug]
215
216 [script type="text/javascript" src="/therapies/therapy_draw.js"]
217 EOF