summaryrefslogtreecommitdiff
path: root/ksh-report.el
blob: 0cd2815aabdf5ded4bc0c5b602cd5f80b0827217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(require 'seq)

(defvar ksh-path (file-name-directory load-file-name))

(defun ksh-discharge ()
  (interactive)
  (forms-find-file (expand-file-name "ksh-discharge.el" ksh-path)))

(defun ksh-scan1 ()
  (interactive)
  (error "Not yet implemented"))

(defun ksh-scan2 ()
  (interactive)
  (forms-find-file (expand-file-name "ksh-scan2.el" ksh-path)))

(defun ksh-scan3 ()
  (interactive)
  (forms-find-file (expand-file-name "ksh-scan3.el" ksh-path)))

(defun biometry-subfloat (param-name param param-age percentile)
  (format
   "\\subfloat {
    \\begin{tikzpicture}
      \\coordinate (O) at (0,0);
      \\coordinate (A) at (2,0);
      \\coordinate (B) at ($0.5*(A)$);
      \\draw (O) -- (A);
      \\draw ($(O) + 0.05*(A)$) -- +(0,-\\tickheight) node [below] {5\\%%};
      \\draw ($(O) + 0.25*(A)$) -- +($0.5*(0,-\\tickheight)$);
      \\draw ($(O) + 0.5*(A)$) -- +(0,-\\tickheight) node [below] {50\\%%};
      \\draw ($(O) + 0.75*(A)$) -- +($0.5*(0,-\\tickheight)$);
      \\draw ($(O) + 0.95*(A)$) -- +(0,-\\tickheight) node [below] {95\\%%};
      \\node [above] at ($(O) + %s*0.01*(A)$) {*};
      \\node at ($0.5*(A) + (0,\\parameterheight)$) {%s %s};
      \\node at ($0.5*(A) + (0,\\parameterageheight)$) {%s};
    \\end{tikzpicture}
  }
" percentile param-name param param-age))

(defun insert-biometry (caption readings)
  (princ "#+BEGIN_EXPORT latex\n")
  (princ "\\begin{figure}\n")
  (princ "\\centering\n")
  (princ (format "\\caption*{%s}" caption))
  (seq-do (lambda (reading)
            (princ (apply 'biometry-subfloat
                          (seq-map 'get-field reading))))
          readings)
  (princ "\\end{figure}\n")
  (princ "#+END_EXPORT\n"))

(defun latex-use-package (package &optional arguments)
  (if arguments
      (format "\\usepackage[%s]{%s}" arguments package)
    (format "\\usepackage{%s}" package)))

(defun latex-macro (name value)
  (format "\\newcommand{\\%s}{%s}" name value))

(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 "caption")
                (latex-use-package "fullpage")
                (latex-use-package "nopageno")
                (latex-use-package "datetime" "ddmmyyyy")
                (latex-use-package "subfig")
                (latex-use-package "tikz")
                "\\usetikzlibrary{calc}"
                "\\renewcommand{\\dateseparator}{-}"
                (latex-macro "tickheight" "0.3")
                (latex-macro "parameterheight" "1")
                (latex-macro "parameterageheight" "0.6")
                "\\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)