]> git.plutz.net Git - lobster/blob - therapies/page.sh
auto submit therapy form data
[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 . [a "/cards/#${id%.*}.vcf" &#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"]
156
157   [input .stickynote type=checkbox name=c_stickynote #show_stickynote]
158   [fieldset .stickynote
159     [label for="show_stickynote" $(l10n notes)]
160     [h2 $(l10n notes)]
161     [textarea name=stickynote . $(TPY stickynote |HTML)]
162     [button type=submit $(l10n save)]
163   ]
164
165   [input .stickynote type=checkbox name=c_timesheet #show_timesheet]
166   [fieldset .stickynote
167     [label for="show_timesheet" $(l10n timesheet)]
168     [h2 $(l10n timesheet)]
169     [table [thead [tr
170       [th $(l10n time_goal)][th $(l10n time_actual)][th $(l10n time_difference)]
171     ]][tbody
172       $(for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
173         tsgoal="$(TPY tsgoal$n |grep -m1 -xE '[0-9]+')"
174         tsactual="$(TPY tsactual$n |grep -m1 -xE '[0-9]+')"
175         printf '[tr [td [input type=number name=tsgoal value="%s"]][td [input type=number name=tsactual value="%s"]][td %s]]' \
176                "$tsgoal" "$tsactual" "$(( ${tsgoal:-0} - ${tsactual:-0} ))"
177       done)
178     ]]
179     [button type=submit $(l10n save)]
180   ]
181
182   [label .tab .heading
183     [span .no $(l10n number)][span .date $(l10n date)][span .therapist $(l10n therapist)][span .signature $(l10n signature)]
184   ]
185 EOF
186
187 therapy_sessions
188
189 ## ==== Drawing canvas ==== ##
190 ### ====================== ###
191
192 penwidth="$(TPY penwidth |grep -xE -m1 '(4|12|36)' || printf '4')"
193 color="$(TPY color |grep -xE -m1 '#(000|00A|0A0|0AA|A00|A0A|AA0|FFF)' || printf '#000')"
194 cat <<EOF
195   [fieldset .penwidth
196     [radio "penwidth" "4"  #pw1 $(checked "$penwidth" 4) ][label for="pw2"]
197     [radio "penwidth" "12" #pw2 $(checked "$penwidth" 12)][label for="pw3"]
198     [radio "penwidth" "36" #pw3 $(checked "$penwidth" 36)][label for="pw1"]
199   ]
200   [fieldset .color
201     [radio "color" "#000" .color #c000 $(checked "$color" '#000') ][label for=c000 ]
202     [radio "color" "#00A" .color #c001 $(checked "$color" '#00A') ][label for=c001 ]
203     [radio "color" "#0A0" .color #c010 $(checked "$color" '#0A0') ][label for=c010 ]
204     [radio "color" "#0AA" .color #c011 $(checked "$color" '#0AA') ][label for=c011 ]
205     [radio "color" "#A00" .color #c100 $(checked "$color" '#A00') ][label for=c100 ]
206     [radio "color" "#A0A" .color #c101 $(checked "$color" '#A0A') ][label for=c101 ]
207     [radio "color" "#AA0" .color #c110 $(checked "$color" '#AA0') ][label for=c110 ]
208     [radio "color" "#FFF" .color #c111 $(checked "$color" '#FFF') ][label for=c111 ]
209   ]
210   [img .dotmark .bg src="/therapies/therapy_background.png" alt="WARNING: Missing background image!"]
211   [canvas #canvas .dotmark .ov width="${bg_dim%x*}" height="${bg_dim#*x}" ]
212   [input type=hidden #image_serialize name=imagedata value=""]
213
214   [button #savebutton type=submit $(l10n save)]
215 ]
216
217 [span #jsdebug style="display: none; position: fixed; right:0; bottom:0" Debug]
218
219 [script type="text/javascript" src="/therapies/therapy_draw.js"]
220 [script type="text/javascript" src="/therapies/autosave.js"]
221 EOF