allow additional remedies to be prescribed
[confetti] / templates / view_client.sh
index ef214c5..c83fac9 100755 (executable)
@@ -86,16 +86,20 @@ cat <<END_HTML
   --><div class="section prescriptions">
     <h3>$(l10n prescriptions)</h3>
     <ul>
-    $(find "$_DATA/prescriptions/" -name "${id%.vcf}.*.mpx" \
+    $(declare -A mpx
+      find "$_DATA/prescriptions/" -name "${id%.vcf}.*.mpx" \
       | while read pfile; do
-        printf '%s\t%s\t%s\n'  
-        printf '<li><a href="?p=prescriptions&amp;client=%s#%s" >%s: %s - %s%s</a></li>' \
-          "${id}" \
-          "${id}" \
-          "$(sed -nr 's;^date:(.+)$;\1;p' "$pfile")" \
-          "$(sed -nr 's;^indicator:(.+)$;\1;p' "$pfile")" \
-          "$(sed -nr 's;^quantity:(.+) ?$;\1x ;p' "$pfile")$(sed -nr 's;^remidy:(.+)$;\1;p' "$pfile")" \
-          "$(sed -nr 's;^quantity1:(.+) ?$;,\1x ;p' "$pfile")$(sed -nr 's;^remidy1:(.+)$;\1;p' "$pfile")"
+        mpx=(); cat "$pfile" |while read -r line; do
+          val="${line#*:}"
+          mpx[${line%%:*}]="$(htmlsafe "${val//\\n/$BR}")"
+        done
+        printf '<li><a href="?p=prescriptions&amp;client=%s#%s" >%s: %s - %s</a></li>' \
+          "${id}" "${pfile##*/}" "${mpx[date]}" "${mpx[indicator]}" \
+          "$([ -n "${mpx[remidy]}" ] && printf '%s %s' "${mpx[quantity]}" "${mpx[remidy]}" 
+             for n in {0..10}; do
+               [ -n "${mpx[remidy${n}]}" ] && printf ', %s %s' "${mpx[quantity${n}]}" "${mpx[remidy${n}]}" 
+             done
+           )"
       done |sort -r
     )
     </ul>