From 79da3ff61ffb5d3c825c37002115639ffdd0789f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 31 Dec 2020 13:45:36 +0530 Subject: Combine biometry and report into single file. * ksh-report-header.el, ksh-biometry.el: Combine into ksh-report.el. * ksh-scan2.el, ksh-scan3.el: Require ksh-report instead of loading ksh-report-header.el and ksh-biometry.el. --- ksh-biometry.el | 41 ------------------------------ ksh-report-header.el | 25 ------------------ ksh-report.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ksh-scan2.el | 4 +-- ksh-scan3.el | 4 +-- 5 files changed, 73 insertions(+), 72 deletions(-) delete mode 100644 ksh-biometry.el delete mode 100644 ksh-report-header.el create mode 100644 ksh-report.el diff --git a/ksh-biometry.el b/ksh-biometry.el deleted file mode 100644 index 0e5f1d7..0000000 --- a/ksh-biometry.el +++ /dev/null @@ -1,41 +0,0 @@ -(defun draw-biometry (param-name param param-age percentile) - (let ((temp-script-file (make-temp-script - (format "%s %s" param-name param) - param-age (string-to-number percentile)))) - (message "Drawing %s..." temp-script-file) - (shell-command - (format "asy -f pdf -o %s %s" (file-name-directory temp-script-file) temp-script-file)) - (delete-file temp-script-file) - (format "%s.pdf" temp-script-file))) - -(defun make-temp-script (param param-age percentile) - (let ((temp-script-file (make-temp-file "biometry"))) - (with-temp-file temp-script-file - (insert "include \"biometry\";\n") - (insert (format - "draw_biometry(\"%s\", \"%s\", %d);" - param param-age percentile))) - temp-script-file)) - -(defun insert-biometry (readings) - (princ - (format "[[%s]]\n" - (crop-pdf - (combine-pdfs - (mapcar (lambda (reading) - (apply 'draw-biometry - (mapcar 'get-field reading))) readings)))))) - -(defun combine-pdfs (pdfs) - (let ((temp-combination (make-temp-file "pdfjam" nil ".pdf"))) - (apply 'call-process "pdfjam" nil nil nil - "--nup" "4x1" - "--outfile" temp-combination pdfs) - (mapc 'delete-file pdfs) - temp-combination)) - -(defun crop-pdf (pdf) - (message "Cropping %s..." pdf) - (let ((output-pdf (format "%s-crop.pdf" (file-name-sans-extension pdf)))) - (shell-command (format "pdfcrop %s %s" pdf output-pdf)) - (delete-file pdf) output-pdf)) diff --git a/ksh-report-header.el b/ksh-report-header.el deleted file mode 100644 index 0fc912a..0000000 --- a/ksh-report-header.el +++ /dev/null @@ -1,25 +0,0 @@ -(defun latex-use-package (package &optional arguments) - (if arguments - (format "\\usepackage[%s]{%s}" arguments package) - (format "\\usepackage{%s}" package))) - -(defun make-report-header (title) - (seq-do 'ksh-forms-org-keyword - '(("TITLE" . "Kuzhanthai Sanjeevi Hospital") - ("AUTHOR" . "Dr. Serene Isaac, MD, DGO, DNB"))) - (seq-do 'ksh-forms-org-latex-header - (list (latex-use-package "fullpage") - (latex-use-package "nopageno") - (latex-use-package "datetime" "ddmmyyyy") - "\\renewcommand{\\dateseparator}{-}" - "\\setlength{\\parindent}{0cm}" - (latex-use-package "titlesec" "tiny") - (latex-use-package "wasysym") - (latex-use-package "titling") - ,(format "\\pretitle{\\hrule \\begin{center} {\\Large \\textbf{%s}} \\par \\small \\sc}" title) - "\\posttitle{\\par 17, Jawahar Street, Ramavarmapuram, Nagercoil - 629001 \\par \\phone \\, 223374 \\end{center}}" - "\\preauthor{}" - "\\postauthor{\\par Obstetrician and Gynaecologist}" - "\\predate{\\hfill \\textbf{Date: }}" - "\\date{\\today}" - "\\postdate{\\vspace{1em} \\hrule \\par}"))) diff --git a/ksh-report.el b/ksh-report.el new file mode 100644 index 0000000..4d6d4e8 --- /dev/null +++ b/ksh-report.el @@ -0,0 +1,71 @@ +(require 'seq) + +(defun draw-biometry (param-name param param-age percentile) + (let ((temp-script-file (make-temp-script + (format "%s %s" param-name param) + param-age (string-to-number percentile)))) + (message "Drawing %s..." temp-script-file) + (shell-command + (format "asy -f pdf -o %s %s" (file-name-directory temp-script-file) temp-script-file)) + (delete-file temp-script-file) + (format "%s.pdf" temp-script-file))) + +(defun make-temp-script (param param-age percentile) + (let ((temp-script-file (make-temp-file "biometry"))) + (with-temp-file temp-script-file + (insert "include \"biometry\";\n") + (insert (format + "draw_biometry(\"%s\", \"%s\", %d);" + param param-age percentile))) + temp-script-file)) + +(defun insert-biometry (readings) + (princ + (format "[[%s]]\n" + (crop-pdf + (combine-pdfs + (mapcar (lambda (reading) + (apply 'draw-biometry + (mapcar 'get-field reading))) readings)))))) + +(defun combine-pdfs (pdfs) + (let ((temp-combination (make-temp-file "pdfjam" nil ".pdf"))) + (apply 'call-process "pdfjam" nil nil nil + "--nup" "4x1" + "--outfile" temp-combination pdfs) + (mapc 'delete-file pdfs) + temp-combination)) + +(defun crop-pdf (pdf) + (message "Cropping %s..." pdf) + (let ((output-pdf (format "%s-crop.pdf" (file-name-sans-extension pdf)))) + (shell-command (format "pdfcrop %s %s" pdf output-pdf)) + (delete-file pdf) output-pdf)) + +(defun latex-use-package (package &optional arguments) + (if arguments + (format "\\usepackage[%s]{%s}" arguments package) + (format "\\usepackage{%s}" package))) + +(defun make-report-header (title) + (seq-do 'ksh-forms-org-keyword + '(("TITLE" . "Kuzhanthai Sanjeevi Hospital") + ("AUTHOR" . "Dr. Serene Isaac, MD, DGO, DNB"))) + (seq-do 'ksh-forms-org-latex-header + (list (latex-use-package "fullpage") + (latex-use-package "nopageno") + (latex-use-package "datetime" "ddmmyyyy") + "\\renewcommand{\\dateseparator}{-}" + "\\setlength{\\parindent}{0cm}" + (latex-use-package "titlesec" "tiny") + (latex-use-package "wasysym") + (latex-use-package "titling") + ,(format "\\pretitle{\\hrule \\begin{center} {\\Large \\textbf{%s}} \\par \\small \\sc}" title) + "\\posttitle{\\par 17, Jawahar Street, Ramavarmapuram, Nagercoil - 629001 \\par \\phone \\, 223374 \\end{center}}" + "\\preauthor{}" + "\\postauthor{\\par Obstetrician and Gynaecologist}" + "\\predate{\\hfill \\textbf{Date: }}" + "\\date{\\today}" + "\\postdate{\\vspace{1em} \\hrule \\par}"))) + +(provide 'ksh-report) diff --git a/ksh-scan2.el b/ksh-scan2.el index 0ea63dd..22d8cb9 100644 --- a/ksh-scan2.el +++ b/ksh-scan2.el @@ -1,9 +1,7 @@ ;; -*- lexical-binding: t -*- (require 'ksh-forms) - -(load "ksh-report-header.el") -(load "ksh-biometry.el") +(require 'ksh-report) ;; Datafile path and fields (setq forms-file (expand-file-name "scan2.dat" ksh-data-path)) diff --git a/ksh-scan3.el b/ksh-scan3.el index cb8947e..75389ff 100644 --- a/ksh-scan3.el +++ b/ksh-scan3.el @@ -1,9 +1,7 @@ ;; -*- lexical-binding: t -*- (require 'ksh-forms) - -(load "ksh-report-header.el") -(load "ksh-biometry.el") +(require 'ksh-report) ;; Datafile path and fields (setq forms-file (expand-file-name "scan3.dat" ksh-data-path)) -- cgit v1.2.3