%% shotlog.sty -- printable injection log sheets and site-rotation keys.
%% Copyright (C) 2026 Alex Bell. LaTeX Project Public License 1.3c or later.
%% Maintainer: Alex Bell <strawbelly.app at gmail.com>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{shotlog}[2026/11/21 v1.0 Printable injection log sheets]
\RequirePackage{pgfkeys}
\RequirePackage{array}
\RequirePackage{xcolor}
\pgfkeys{/shotlog/.is family,/shotlog,
  rows/.store in=\sl@rows, rows=15,
  height/.store in=\sl@height, height=1.4em,
  columns/.store in=\sl@columns, columns={Date,Medication,Dose (as prescribed),Site,Side effects,Notes},
  title/.store in=\sl@title, title={Injection log}}
\newcount\sl@n \newcount\sl@i
\newtoks\sl@head \newtoks\sl@body
% \shotlog[options] : a blank log table filling \linewidth
\newcommand\shotlog[1][]{\begingroup\pgfkeys{/shotlog,#1}%
  \sl@n=0 \sl@head={}%
  \def\sl@sep{}%
  \@for\sl@c:=\sl@columns\do{\advance\sl@n by 1
    \edef\sl@tmp{\the\sl@head\sl@sep\noexpand\textbf{\sl@c}}\sl@head=\expandafter{\sl@tmp}\def\sl@sep{&}}%
  \toks@={}\count@=1
  \@whilenum\count@<\sl@n\do{\advance\count@ by 1 \toks@=\expandafter{\the\toks@&}}%
  \edef\sl@tmp{\noexpand\rule{0pt}{\sl@height}\the\toks@\noexpand\\\noexpand\hline}%
  \sl@body={}\sl@i=0
  \@whilenum\sl@i<\sl@rows\do{\advance\sl@i by 1 \sl@body=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\sl@body\sl@tmp}}%
  \par\noindent{\large\bfseries\sl@title}\par\smallskip\noindent
  \edef\sl@spec{|*{\the\sl@n}{p{\dimexpr(\linewidth-\the\numexpr\sl@n*2\relax\tabcolsep)/\the\sl@n\relax}|}}%
  \expandafter\tabular\expandafter{\sl@spec}\hline\the\sl@head\\\hline\the\sl@body\endtabular\par\endgroup}
% \sitekey : the six common subcutaneous sites as tick boxes
\newcommand\sitekey{\par\noindent{\small\textbf{Site rotation key:}\quad
  \fbox{\phantom{x}} Abdomen L\quad\fbox{\phantom{x}} Abdomen R\quad\fbox{\phantom{x}} Thigh L\quad
  \fbox{\phantom{x}} Thigh R\quad\fbox{\phantom{x}} Upper arm L\quad\fbox{\phantom{x}} Upper arm R}\par}
\endinput
