- (cd "$_DATA/prescriptions/"; printf '%s\n' "${client}".*.mpx) \
- | while read mpxfile; do
- [ "$mpxfile" = "${client}.*.mpx" ] && break
- mpx="${mpxfile%.mpx}";
- printf '[a .item .therapy href="/therapies/%s" . Therapy - %s]' \
- "${mpx%.*}/${mpx#*.}" "$(sed -E '/^date:.*/{s;^date:;;;q;};d;' "$_DATA/prescriptions/$mpxfile")"
- done |sort -r
+ (cd "$_DATA/therapies/"; printf '%s\n' "${client}".*.tpy) \
+ | while read tpyfile; do
+ [ "$tpyfile" = "${client}.*.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); - ;;'
+ )"
+ printf '[a .item .therapy href="/therapies/%s" . %s] ' \
+ "${tpy%.*}/${tpy#*.}" "$(HTML "${tpydates:--}")"
+ done |sort -n
+ printf '[a .item .therapy href="/therapies/%s/new" . +]' "${client}"