]> git.plutz.net Git - lobster/blob - therapies/page.sh
disable autosubmit, submit when using back-button
[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 n=$((n + 1)); done
48
49   sid=session$n
50   cat <<-EOF
51         [fieldset .tab
52           [submit "new_session" "$sid" .no . +]
53           [input .date name="${sid}_date" value="" placeholder=$(l10n date)]
54           [input .therapist name="${sid}_therapist" value="" placeholder=$(l10n therapist)]
55           [span .signature]
56           [hidden "${sid}_note1" ""]
57         ]
58         EOF
59
60   for n in $(seq $((n - 1)) -1 1); do
61     session_n="$n"
62     sid=session${session_n}
63
64     cat <<-EOF
65         [hidden "$sid" "exists"]
66         [checkbox "${sid}_open" "checked" #${sid}_open .tab $(checked "$(TPY "${sid}_open")" checked)]
67         [label .tab for="${sid}_open"
68           [span .no ${session_n}.]
69           [span .date . $(TPY "${sid}_date" |HTML)]
70           [input .date name="${sid}_date" value="$(TPY "${sid}_date" |HTML)" placeholder="$(l10n date)"]
71           [span .therapist . $(TPY "${sid}_therapist" |HTML)]
72           [input .therapist name="${sid}_therapist" value="$(TPY "${sid}_therapist" |HTML)" placeholder="$(l10n therapist)"]
73           [span .signature [checkbox "${sid}_sigset" "pos" $(checked "$(TPY "${sid}_sigset")" "pos")]]
74         ]
75         [div .tab
76           [img .dotmark .ov src="/therapies/${id}_${sid}.png?${_DATE}" alt=""]
77           $(n=1; while TPY "session${session_n}_note${n}" >/dev/null; do
78               [ "$(TPY "session${session_n}_note${n}")" ] && x=$n
79               n=$(($n + 1))
80             done
81             for n in $(seq 1 $((${x:-0} + 3)) ); do
82               t_session_note $session_n $n
83             done
84           )
85           [button type="submit" .trailbtn $(l10n trailbtn)]
86           [button type="submit" name=delete_session value="$session_n" .delete $(l10n delete_session)]
87         ]
88         EOF
89   done
90 }
91
92 cat <<EOF
93 [h1 $(l10n therapy)]
94
95 [div .patient
96   [h2 . &#x2b05; $(VCF FN |HTML)]
97 ]
98
99 [div .therapies
100   [h2 $(l10n therapies)]
101   $(
102   (cd "$_DATA/therapies/"; printf '%s\n' "${id%%.*}".*.tpy) \
103   | while read tpyfile; do
104     [ "$tpyfile" = "${id%%.*}.*.tpy" ] && break
105     tpy="${tpyfile%.tpy}";
106     tpydates="$(sed -En 's;^session[0-9]+_date:;;p;' "$_DATA/therapies/$tpyfile" \
107                 | sort \
108                 | sed -E ':X;N;$!bX; s;^[\n ]+;;; s;[\n ]+$;;; s;(\n.*\n|\n); - ;;'
109                )"
110     if [ "${tpy%.*}.${tpy#*.}" = "${id}" ]; then
111       printf '[a .item .therapy .current href="/therapies/%s" . %s] ' \
112              "${tpy%.*}/${tpy#*.}" "$(HTML "${tpydates:--}")"
113     else
114       printf '[a .item .therapy href="/therapies/%s" . %s] ' \
115              "${tpy%.*}/${tpy#*.}" "$(HTML "${tpydates:--}")"
116     fi
117   done |sort -n
118   )
119   [a .item .therapy href="/therapies/${id%%.*}/new" . +]
120 ]
121 EOF
122
123 if [ "$mpx" ]; then
124   printf '[div .prescription [h2 %s]' "$(l10n therapy_prescription)"
125   
126   printf '[ul'
127   for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
128     remidy="$(MPX remidy$n)"
129     quantity="$(MPX quantity$n)"
130     quantity_weekly="$(MPX quantity_weekly$n)"
131   
132     if [ "$remidy" -a "$quantity_weekly" ]; then
133       printf '[li %s %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")" "$(HTML "$quantity_weekly") $(l10n weekly)"
134     elif [ "$remidy" ]; then
135       printf '[li %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")"
136     fi
137   done
138   printf ']'
139   
140   for field in indicator icd10; do
141     val="$(MPX "$field")"
142     [ "$val" ] && printf '[span .%s [label . %s:]%s]' "$field" "$(l10n "$field")" "$(HTML "$val")"
143   done
144   
145   if [ "$(MPX indicator_reading)" ]; then
146     printf '[h3 %s][p . %s]' \
147            "$(l10n indicator_reading)" "$(MPX indicator_reading |HTML)"
148   fi
149
150   printf ']'
151 fi
152
153 cat <<EOF
154 [form #report method=POST action="/therapies/update_therapy.sh"
155   [hidden "id" "$id"][hidden "tid" "$(transid "$tpyfile")"]
156
157   [button #backbutton type=submit name="vcfreturn" value="true" &#x2b05; $(VCF FN |HTML)]
158
159   [input .stickynote type=checkbox name=c_stickynote #show_stickynote]
160   [fieldset .stickynote
161     [label for="show_stickynote" $(l10n notes)]
162     [h2 $(l10n notes)]
163     [textarea name=stickynote . $(TPY stickynote |HTML)]
164     [button type=submit $(l10n save)]
165   ]
166 EOF
167
168 # cat <<EOF
169 #   [input .stickynote type=checkbox name=c_timesheet #show_timesheet]
170 #   [fieldset .stickynote
171 #     [label for="show_timesheet" $(l10n timesheet)]
172 #     [h2 $(l10n timesheet)]
173 #     [table [thead [tr
174 #       [th $(l10n time_goal)][th $(l10n time_actual)][th $(l10n time_difference)]
175 #     ]][tbody
176 #       $(for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
177 #         tsgoal="$(TPY tsgoal$n |grep -m1 -xE '[0-9]+')"
178 #         tsactual="$(TPY tsactual$n |grep -m1 -xE '[0-9]+')"
179 #         printf '[tr [td [input type=number name=tsgoal value="%s"]][td [input type=number name=tsactual value="%s"]][td %s]]' \
180 #                "$tsgoal" "$tsactual" "$(( ${tsgoal:-0} - ${tsactual:-0} ))"
181 #       done)
182 #     ]]
183 #     [button type=submit $(l10n save)]
184 #   ]
185 # EOF
186
187 cat <<EOF
188   [label .tab .heading
189     [span .no $(l10n number)][span .date $(l10n date)][span .therapist $(l10n therapist)][span .signature $(l10n signature)]
190   ]
191 EOF
192
193 therapy_sessions
194
195 ## ==== Drawing canvas ==== ##
196 ### ====================== ###
197
198 penwidth="$(TPY penwidth |grep -xE -m1 '(4|12|36)' || printf '4')"
199 color="$(TPY color |grep -xE -m1 '#(000|00A|0A0|0AA|A00|A0A|AA0|FFF)' || printf '#000')"
200 cat <<EOF
201   [fieldset .penwidth
202     [radio "penwidth" "4"  #pw1 $(checked "$penwidth" 4) ][label for="pw2"]
203     [radio "penwidth" "12" #pw2 $(checked "$penwidth" 12)][label for="pw3"]
204     [radio "penwidth" "36" #pw3 $(checked "$penwidth" 36)][label for="pw1"]
205   ]
206   [fieldset .color
207     [radio "color" "#000" .color #c000 $(checked "$color" '#000') ][label for=c000 ]
208     [radio "color" "#00A" .color #c001 $(checked "$color" '#00A') ][label for=c001 ]
209     [radio "color" "#0A0" .color #c010 $(checked "$color" '#0A0') ][label for=c010 ]
210     [radio "color" "#0AA" .color #c011 $(checked "$color" '#0AA') ][label for=c011 ]
211     [radio "color" "#A00" .color #c100 $(checked "$color" '#A00') ][label for=c100 ]
212     [radio "color" "#A0A" .color #c101 $(checked "$color" '#A0A') ][label for=c101 ]
213     [radio "color" "#AA0" .color #c110 $(checked "$color" '#AA0') ][label for=c110 ]
214     [radio "color" "#FFF" .color #c111 $(checked "$color" '#FFF') ][label for=c111 ]
215   ]
216   [img .dotmark .bg src="/therapies/therapy_background.png" alt="WARNING: Missing background image!"]
217   [canvas #canvas .dotmark .ov width="${bg_dim%x*}" height="${bg_dim#*x}" ]
218   [input type=hidden #image_serialize name=imagedata value=""]
219
220   [input type=hidden name=formend value=formend]
221   [button #savebutton type=submit $(l10n save)]
222 ]
223
224 [span #jsdebug style="display: none; position: fixed; right:0; bottom:0" Debug]
225
226 [script type="text/javascript" src="/therapies/therapy_draw.js"]
227 [!-- script type="text/javascript" src="/therapies/autosave.js" --]
228 EOF