]> git.plutz.net Git - lobster/blobdiff - therapies/page.sh
better visibility for sticky note close button
[lobster] / therapies / page.sh
index c3f3c5c40097dbb2da10d94246d1581cff97f553..a38372f9e3443ebc5caec497cc391369d8aaa432 100755 (executable)
 # You should have received a copy of the GNU Affero General Public License
 # along with Lobster.  If not, see <http://www.gnu.org/licenses/>. 
 
-# t_session_note(){
-#   session_n="$1"
-#   note_n="$2"
-#   
-#   color=session${session_n}_note${note_n}_color
-#   unset c0 c1 c2 c3 c4 c5 c6 c7
-#   
-#   if [ "$note_n" -eq 1 -o -n "${tpy[session${session_n}_note${note_n}]}" ]; then
-#     printf '<input class="trailbtn" type="checkbox" checked="checked">'
-#   else
-#     printf '<input class="trailbtn" type="checkbox">'
-#   fi
-# 
-#   _checked="$(validate "$tpy[$color]" '#(888|00A|0A0|0AA|A00|A0A|AA0)' '#FFF')"
-#      cat <<-EOF
-#        <fieldset class="note trailbox">
-#          <input class=color type=radio name="$color" value="#888" id=${color}_000 $(checked \#888)><label for=${color}_000></label>
-#          <input class=color type=radio name="$color" value="#00A" id=${color}_001 $(checked \#00A)><label for=${color}_001></label>
-#          <input class=color type=radio name="$color" value="#0A0" id=${color}_010 $(checked \#0A0)><label for=${color}_010></label>
-#          <input class=color type=radio name="$color" value="#0AA" id=${color}_011 $(checked \#0AA)><label for=${color}_011></label>
-#          <input class=color type=radio name="$color" value="#A00" id=${color}_100 $(checked \#A00)><label for=${color}_100></label>
-#          <input class=color type=radio name="$color" value="#A0A" id=${color}_101 $(checked \#A0A)><label for=${color}_101></label>
-#          <input class=color type=radio name="$color" value="#AA0" id=${color}_110 $(checked \#AA0)><label for=${color}_110></label>
-#          <input class=color type=radio name="$color" value="#FFF" id=${color}_111 $(checked \#FFF)><label for=${color}_111></label>
-#          <textarea name="session${session_n}_note${note_n}">${tpy[session${session_n}_note${note_n}]}</textarea>
-#        </fieldset>
-#      EOF
-# }
-# 
-# t_session(){
-#   session_n="$1"
-# 
-#   sid=session${session_n}
-# 
-#   if [ "$tpy[${sid}_sigset]" = pos ]; then
-#     sigcheck=checked
-#   else
-#     unset sigcheck
-#   fi
-# 
-#      cat <<-EOF
-#        <input type=hidden name=$sid value=exists>
-#        <input class="tab" type="checkbox" id=${sid}_open name="${sid}_open" value="checked" ${tpy[${sid}_open]}>
-#        <label class="tab" for="${sid}_open">
-#          <span class=no>${session_n}.</span><!--
-#       --><span class=date>${tpy[${sid}_date]}</span><!--
-#       --><input class="date" name="${sid}_date" value="${tpy[${sid}_date]}" placeholder="$(l10n date)"><!--
-#       --><span class=therapist>${tpy[${sid}_therapist]}</span><!--
-#       --><input class="therapist" name="${sid}_therapist" value="${tpy[${sid}_therapist]}" placeholder="$(l10n therapist)"><!--
-#       --><span class=signature><input type="checkbox" name="${sid}_sigset" value="pos" $sigcheck></span>
-#        </label>
-#        <div class=tab>
-#          <img class="dotmark ov" src="/therapies/${id%.tpy}_${sid}.png" alt="">
-#          $(n=1;
-#               while [ -n "${tpy[session${session_n}_note${n}]+x}" ]; do
-#                 if [ -n "${tpy[session${session_n}_note${n}]}" ]; then
-#                   x=$n
-#                 fi
-#                 n=$(($n + 1))
-#               done
-#               for n in $(seq 1 $((${x:-0} + 3)) ); do t_session_note $session_n $n; done
-#              )
-#          <button class="trailbtn" type="submit">$(l10n trailsave)</button>
-#          <button class=delete type=submit name=delete_session value=${session_n}>$(l10n delete_session)</button>
-#        </div>
-#      EOF
-# }
-# 
-# therapy_sessions(){
-#   n=1; while [ -n "${tpy[session${n}]}" ]; do
-#     t_session $n
-#     n=$(($n+1))
-#   done
-# 
-#   sid=session$n
-# 
-#      cat <<-EOF
-#        <fieldset class="tab">
-#          <button class=no type=submit name=new_session value=$sid>+</button><!--
-#       --><input class=date name=${sid}_date value="" placeholder="$(l10n date)" /><!--
-#       --><input class=therapist name=${sid}_therapist value="" placeholder="$(l10n therapist)" /><!--
-#       --><span class=signature><span></span>
-#          <input type=hidden name="${sid}_note1" value="">
-#        </fieldset>
-#      EOF
-# }
+t_session_note(){
+  session_n="$1"
+  note_n="$2"
+  
+  color=session${session_n}_note${note_n}_color
+  
+  if [ "$note_n" -eq 1 -o "$(TPY "session${session_n}_note${note_n}")" ]; then
+    printf '[input type="checkbox" .trailbtn checked="checked"]'
+  else
+    printf '[input type="checkbox" .trailbtn]'
+  fi
+
+  check="$(TPY "$color" |grep -xE -m1 '#(888|00A|0A0|0AA|A00|A0A|AA0)' || printf '#FFF')"
+  cat <<-EOF
+       [fieldset .note .trailbox
+         [radio "$color" "#888" .color #${color}_000 $(checked "$check" '#888') ][label for=${color}_000]
+         [radio "$color" "#00A" .color #${color}_001 $(checked "$check" '#00A') ][label for=${color}_001]
+         [radio "$color" "#0A0" .color #${color}_010 $(checked "$check" '#0A0') ][label for=${color}_010]
+         [radio "$color" "#0AA" .color #${color}_011 $(checked "$check" '#0AA') ][label for=${color}_011]
+         [radio "$color" "#A00" .color #${color}_100 $(checked "$check" '#A00') ][label for=${color}_100]
+         [radio "$color" "#A0A" .color #${color}_101 $(checked "$check" '#A0A') ][label for=${color}_101]
+         [radio "$color" "#AA0" .color #${color}_110 $(checked "$check" '#AA0') ][label for=${color}_110]
+         [radio "$color" "#FFF" .color #${color}_111 $(checked "$check" '#FFF') ][label for=${color}_111]
+         [textarea name="session${session_n}_note${note_n}" . $(TPY "session${session_n}_note${note_n}" |HTML)]
+       ]
+       EOF
+}
+
+therapy_sessions(){
+  n=1; while [ "$(TPY session$n)" ]; do n=$((n + 1)); done
+
+  sid=session$n
+  cat <<-EOF
+       [fieldset .tab
+         [submit "new_session" "$sid" .no . +]
+         [input .date name="${sid}_date" value="" placeholder=$(l10n date)]
+         [input .therapist name="${sid}_therapist" value="" placeholder=$(l10n therapist)]
+         [span .signature]
+         [hidden "${sid}_note1" ""]
+       ]
+       EOF
+
+  seq $((n - 1)) -1 1 | while read n; do
+    session_n="$n"
+    sid=session${session_n}
+
+    cat <<-EOF
+       [hidden "$sid" "exists"]
+       [checkbox "${sid}_open" "checked" #${sid}_open .tab $(checked "$(TPY "${sid}_open")" checked)]
+       [label .tab for="${sid}_open"
+         [span .no ${session_n}.]
+         [span .date . $(TPY "${sid}_date" |HTML)]
+         [input .date name="${sid}_date" value="$(TPY "${sid}_date" |HTML)" placeholder="$(l10n date)"]
+         [span .therapist . $(TPY "${sid}_therapist" |HTML)]
+         [input .therapist name="${sid}_therapist" value="$(TPY "${sid}_therapist" |HTML)" placeholder="$(l10n therapist)"]
+         [span .signature [checkbox "${sid}_sigset" "pos" $(checked "$(TPY "${sid}_sigset")" "pos")]]
+       ]
+       [div .tab
+         [img .dotmark .ov src="/therapies/${id}_${sid}.png?${_DATE}" alt=""]
+         $(n=1; while TPY "session${session_n}_note${n}" >/dev/null; do
+             [ "$(TPY "session${session_n}_note${n}")" ] && x=$n
+             n=$(($n + 1))
+           done
+           for n in $(seq 1 $((${x:-0} + 3)) ); do
+             t_session_note $session_n $n
+           done
+         )
+         [button type="submit" .trailbtn $(l10n trailbtn)]
+         [button type="submit" name=delete_session value="$session_n" .delete $(l10n delete_session)]
+       ]
+       EOF
+  done
+}
 
 cat <<EOF
 [h1 $(l10n therapy)]
 
 [div .patient
-  [h2 . $(pdi_value "$vcf" FN)]
-  [a href="/cards/#${id%.*}.vcf" \< $(l10n client)]
+  [h2 . [a "/cards/#${id%.*}.vcf" &#x2b05; $(VCF FN |HTML)]]
 ]
 
-[div .prescription
-  [h2 $(l10n therapy_prescription)]
-  [span .insurance . $(pdi_value "$mpx" INSURANCE)]
-  [span .date [label $(l10n date):] $(pdi_value "$mpx" DATE)]
+[div .therapies
+  [h2 $(l10n therapies)]
+  $(
+  (cd "$_DATA/therapies/"; printf '%s\n' "${id%%.*}".*.tpy) \
+  | while read tpyfile; do
+    [ "$tpyfile" = "${id%%.*}.*.tpy" ] && break
+    tpy="${tpyfile%.tpy}";
+    tpydates="$(sed -En 's;^session[0-9]+_date:;;p;' "$_DATA/therapies/$tpyfile" \
+                | sort \
+                | sed -E ':X;N;$!bX; s;^[\n ]+;;; s;[\n ]+$;;; s;(\n.*\n|\n); - ;;'
+               )"
+    if [ "${tpy%.*}.${tpy#*.}" = "${id}" ]; then
+      printf '[a .item .therapy .current href="/therapies/%s" . %s] ' \
+             "${tpy%.*}/${tpy#*.}" "$(HTML "${tpydates:--}")"
+    else
+      printf '[a .item .therapy href="/therapies/%s" . %s] ' \
+             "${tpy%.*}/${tpy#*.}" "$(HTML "${tpydates:--}")"
+    fi
+  done |sort -n
+  )
+  [a .item .therapy href="/therapies/${id%%.*}/new" . +]
+]
 EOF
 
-  if [ "$(pdi_value "$mpx" PRESCREVIEWED)" ]; then
-    printf '[label .checkbox .checked for=prescreviewed . %s]' "$(l10n prescreviewed)"
-  else
-    printf '[label .checkbox for=prescreviewed . %s]' "$(l10n prescreview)"
-  fi
-
-  field="$(pdi_value "$mpx" PRESCNO)"
-  [ "$field" ] && printf '[span .prescno . %s]' "$(l10n "presc$field")"
-  for field in grouptherapy housecall report; do
-    [ "$(pdi_value "$mpx" "$field")" ] && printf '[span .catalogue . %s]' "$(l10n "$field")"
-  done
-
+if [ "$mpx" ]; then
+  printf '[div .prescription [h2 %s]' "$(l10n therapy_prescription)"
+  
   printf '[ul'
   for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
-    remidy="$(pdi_value "$mpx" REMIDY$n)"
-    quantity="$(pdi_value "$mpx" QUANTITY$n)"
-    quantity_weekly="$(pdi_value "$mpx" QUANTITY_WEEKLY$n)"
-
+    remidy="$(MPX remidy$n)"
+    quantity="$(MPX quantity$n)"
+    quantity_weekly="$(MPX quantity_weekly$n)"
+  
     if [ "$remidy" -a "$quantity_weekly" ]; then
-      printf '[li %s %s %s]' "$quantity" "$remidy" "$quantity_weekly $(l10n weekly)"
+      printf '[li %s %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")" "$(HTML "$quantity_weekly") $(l10n weekly)"
     elif [ "$remidy" ]; then
-      printf '[li %s %s]' "$quantity" "$remidy"
+      printf '[li %s %s]' "$(HTML "$quantity")" "$(HTML "$remidy")"
     fi
   done
   printf ']'
-
+  
   for field in indicator icd10; do
-    val="$(pdi_value "$mpx" "$field")"
-    [ "$val" ] && printf '[span .%s [label . %s:]%s]' "$field" "$(l10n "$field")" "$val"
+    val="$(MPX "$field")"
+    [ "$val" ] && printf '[span .%s [label . %s:]%s]' "$field" "$(l10n "$field")" "$(HTML "$val")"
   done
-
-  addcontrib="$(pdi_value "$mpx" ADDCONTRIB)"
-  contribconfirm="$(pdi_value "$mpx" CONTRIBCONFIRM)"
-
-  if [ "$addcontrib" -a "$contribconfirm" ]; then
-    printf '[label .checkbox .checked for=addcontrib . %s %s]' "$(l10n contribconfirm)" "$contribconfirm"
-  elif [ "$addcontrib" ]; then
-    printf '[label .checkbox for=addcontrib . %s]' "$(l10n addcontrib)"
+  
+  if [ "$(MPX indicator_reading)" ]; then
+    printf '[h3 %s][p . %s]' \
+           "$(l10n indicator_reading)" "$(MPX indicator_reading |HTML)"
   fi
 
-cat <<EOF
-  [input .tab type="checkbox" #indicator_reading][label .tab for=indicator_reading $(l10n indicator_reading)]
-  [div .tab . $(pdi_value "$mpx" INDICATOR_READING)]
-]
+  printf ']'
+fi
 
+cat <<EOF
 [form #report method=POST action="/therapies/update_therapy.sh"
-  [input type=hidden name=id value="$id"]
+  [hidden "id" "$id"]
 
   [input .stickynote type=checkbox name=c_stickynote #show_stickynote]
   [fieldset .stickynote
     [label for="show_stickynote" $(l10n notes)]
     [h2 $(l10n notes)]
-    [textarea name=stickynote . $(pdi_value "$tpy" STICKYNOTE)]
+    [textarea name=stickynote . $(TPY stickynote |HTML)]
     [button type=submit $(l10n save)]
   ]
+EOF
 
-  [input .stickynote type=checkbox name=c_timesheet #show_timesheet]
-  [fieldset .stickynote
-    [label for="show_timesheet" $(l10n timesheet)]
-    [h2 $(l10n timesheet)]
-    [table [thead [tr
-      [th $(l10n time_goal)][th $(l10n time_actual)][th $(l10n time_difference)]
-    ]][tbody
-      $(for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
-        tsgoal="$(pdi_value "$tpy" TSGOAL$n)"
-        tsactual="$(pdi_value "$tpy" TSACTUAL$n)"
-        printf '[tr [td [input type=number name=tsgoal value="%s"]][td [input type=number name=tsactual value="%s"]][td %s]]' \
-               "$tsgoal" "$tsactual" "$(( ${tsgoal:-0} - ${tsactual:-0} ))"
-      done)
-    ]]
-    [button type=submit $(l10n save)]
-  ]
+# cat <<EOF
+#   [input .stickynote type=checkbox name=c_timesheet #show_timesheet]
+#   [fieldset .stickynote
+#     [label for="show_timesheet" $(l10n timesheet)]
+#     [h2 $(l10n timesheet)]
+#     [table [thead [tr
+#       [th $(l10n time_goal)][th $(l10n time_actual)][th $(l10n time_difference)]
+#     ]][tbody
+#       $(for n in '' 0 1 2 3 4 5 6 7 8 9 10; do
+#         tsgoal="$(TPY tsgoal$n |grep -m1 -xE '[0-9]+')"
+#         tsactual="$(TPY tsactual$n |grep -m1 -xE '[0-9]+')"
+#         printf '[tr [td [input type=number name=tsgoal value="%s"]][td [input type=number name=tsactual value="%s"]][td %s]]' \
+#                "$tsgoal" "$tsactual" "$(( ${tsgoal:-0} - ${tsactual:-0} ))"
+#       done)
+#     ]]
+#     [button type=submit $(l10n save)]
+#   ]
+# EOF
 
+cat <<EOF
   [label .tab .heading
     [span .no $(l10n number)][span .date $(l10n date)][span .therapist $(l10n therapist)][span .signature $(l10n signature)]
   ]
 EOF
 
-# therapy_sessions
+therapy_sessions
+
+## ==== Drawing canvas ==== ##
+### ====================== ###
 
-penwith="$(pdi_value "$tpy" PENWITH |grep -xE -m1 '(4|12|36)' || printf '4')"
-color="$(pdi_value "$tpy" COLOR |grep -xE -m1 '#(000|00A|0A0|0AA|A00|A0A|AA0|FFF)' || printf '#000')"
+penwidth="$(TPY penwidth |grep -xE -m1 '(4|12|36)' || printf '4')"
+color="$(TPY color |grep -xE -m1 '#(000|00A|0A0|0AA|A00|A0A|AA0|FFF)' || printf '#000')"
 cat <<EOF
   [fieldset .penwidth
-    [radio "penwidth" "4"  #pw1 $(checked $penwidth 4) ][label for="pw2"]
-    [radio "penwidth" "12" #pw2 $(checked $penwidth 12)][label for="pw3"]
-    [radio "penwidth" "36" #pw3 $(checked $penwidth 36)][label for="pw1"]
+    [radio "penwidth" "4"  #pw1 $(checked "$penwidth" 4) ][label for="pw2"]
+    [radio "penwidth" "12" #pw2 $(checked "$penwidth" 12)][label for="pw3"]
+    [radio "penwidth" "36" #pw3 $(checked "$penwidth" 36)][label for="pw1"]
   ]
   [fieldset .color
-    [radio "color" "#000" .color #c000 $(checked $color '#000') ][label for=c000 ]
-    [radio "color" "#00A" .color #c001 $(checked $color '#00A') ][label for=c001 ]
-    [radio "color" "#0A0" .color #c010 $(checked $color '#0A0') ][label for=c010 ]
-    [radio "color" "#0AA" .color #c011 $(checked $color '#0AA') ][label for=c011 ]
-    [radio "color" "#A00" .color #c100 $(checked $color '#A00') ][label for=c100 ]
-    [radio "color" "#A0A" .color #c101 $(checked $color '#A0A') ][label for=c101 ]
-    [radio "color" "#AA0" .color #c110 $(checked $color '#AA0') ][label for=c110 ]
-    [radio "color" "#FFF" .color #c111 $(checked $color '#FFF') ][label for=c111 ]
+    [radio "color" "#000" .color #c000 $(checked "$color" '#000') ][label for=c000 ]
+    [radio "color" "#00A" .color #c001 $(checked "$color" '#00A') ][label for=c001 ]
+    [radio "color" "#0A0" .color #c010 $(checked "$color" '#0A0') ][label for=c010 ]
+    [radio "color" "#0AA" .color #c011 $(checked "$color" '#0AA') ][label for=c011 ]
+    [radio "color" "#A00" .color #c100 $(checked "$color" '#A00') ][label for=c100 ]
+    [radio "color" "#A0A" .color #c101 $(checked "$color" '#A0A') ][label for=c101 ]
+    [radio "color" "#AA0" .color #c110 $(checked "$color" '#AA0') ][label for=c110 ]
+    [radio "color" "#FFF" .color #c111 $(checked "$color" '#FFF') ][label for=c111 ]
   ]
   [img .dotmark .bg src="/therapies/therapy_background.png" alt="WARNING: Missing background image!"]
   [canvas #canvas .dotmark .ov width="${bg_dim%x*}" height="${bg_dim#*x}" ]
   [input type=hidden #image_serialize name=imagedata value=""]
 
-  [button type=submit $(l10n save)]
+  [button #savebutton type=submit $(l10n save)]
 ]
 
 [span #jsdebug style="display: none; position: fixed; right:0; bottom:0" Debug]
 
 [script type="text/javascript" src="/therapies/therapy_draw.js"]
+[script type="text/javascript" src="/therapies/autosave.js"]
 EOF