]> git.plutz.net Git - confetti/blobdiff - pages/therapy.sh
dynamic therapy section
[confetti] / pages / therapy.sh
index 571333ec7008d98720597bb42ea5f9c6020033ef..6127b4dfd5979011f2b94aeb6a9484999185afe2 100755 (executable)
@@ -18,6 +18,7 @@
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
 declare -A tpy
+declare -A mpx
 
 BR='
 '
@@ -25,8 +26,26 @@ BR='
 id="$_GET[id]"
 
 tpyfile="$_DATA/therapies/$id"
+mpxfile="$_DATA/prescriptions/${id%.tpy}.mpx"
+client="$_DATA/vcard/${id%%.*}.vcf"
+
+card_N="$(sed -nr 's:^(N)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:gp' "$client")"
+card_FN="$(sed -nr 's:^(FN)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:gp' "$client")"
+card_NICK="$(sed -nr 's:^(NICKNAME)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:gp' "$client")"
+
+n=$(printf %s "$card_N" \
+    | sed -rn 's:^([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\4 \2 \3 \1 \5:gp' \
+    | sed -r 's:,: :;s:\;: :g;s: +: :g;s:^ $::;'
+   )
+client_name="${n:-${card_FN:-${card_NICK}}}"
 
 mpx=()
+cat "$mpxfile" |while read -r line; do
+  val="${line#*:}"
+  mpx[${line%%:*}]="${val//\\n/$BR}"
+done
+
+tpy=()
 cat "$tpyfile" |while read -r line; do
   val="${line#*:}"
   tpy[${line%%:*}]="${val//\\n/$BR}"