summaryrefslogtreecommitdiff
path: root/ksh-scan2.el
blob: 6a5dc746f7df004814b6b0be4ec5bc7d57857491 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
;; -*- lexical-binding: t -*-

(require 'ksh-forms)
(require 'ksh-report)

;; Datafile path and fields
(setq forms-file (expand-file-name "data/scan2.dat" ksh-path))
(setq forms-number-of-fields
      (forms-enumerate
       '(ip-op-no patient-name age sex visit-date lmp-date lmp-edd
		    scan
		    maternal-cervix maternal-internal-os
		    survey-presentation survey-placenta survey-liquor
		    survey-umbilical-cord survey-fetal-activity survey-cardiac-activity
		    biometry-bpd biometry-bpd-age biometry-bpd-percentile
		    biometry-hc biometry-hc-age biometry-hc-percentile
		    biometry-ac biometry-ac-age biometry-ac-percentile
		    biometry-fl biometry-fl-age biometry-fl-percentile
		    biometry-fetal-weight
		    extended-foot-length extended-tcd
		    anatomy-intracranial anatomy-neck anatomy-spine
		    anatomy-face anatomy-lungs anatomy-heart
		    anatomy-abdominal-situs anatomy-kidneys-bladder
		    anatomy-long-bones
		    impression-gestational-age impression-menstrual-age
		    impression-corrected-edd impression-notes
		    sonologist)))

;; Default values for fields
(setq default-field-values
      `((,sex . "F")
	(,survey-presentation . "cephalic")
	(,survey-placenta . "posterior")
	(,survey-liquor . "normal")
	(,survey-fetal-activity . "present")
	(,survey-cardiac-activity . "present")
	(,anatomy-intracranial . "normal")
	(,anatomy-neck . "normal. No evidence of significant open neural tube defect")
	(,anatomy-spine . "normal")
	(,anatomy-face . "normal")
	(,anatomy-lungs . "normal")
	(,anatomy-heart . "normal")
	(,anatomy-abdominal-situs . "normal")
	(,anatomy-kidneys-bladder . "normal")
	(,anatomy-long-bones . "normal for the period of gestation")
	(,sonologist . "Dr. Bala Bharathy")))

;; Format specification for form display
(setq forms-format-list
      (append
       (list "Trimester 2 - Scan Report\n\n")
       (seq-mapcat 'form-entry
                   '(("IP/OP No" . ip-op-no)
                     ("Patient Name" . patient-name)
                     ("Age" . age)
                     ("Sex" . sex)
                     ("Visit Date" . visit-date)
                     ("LMP Date" . lmp-date)
                     ("LMP EDD" . lmp-edd)))
       (list "Indications\n" "Growth Scan\n"
	     "Real time B-mode ultrasonography of gravid uterus done.\n"
	     "Route: Transabdominal\n" scan "\n\n")
       (list "Maternal\n")
       (seq-mapcat 'form-entry
                   '(("Cervix" . maternal-cervix)
                     ("Internal os" . maternal-internal-os)))
       (list "Fetal Survey\n")
       (seq-mapcat 'form-entry
                   '(("Presentation" . survey-presentation)
                     ("Placenta" . survey-placenta)
                     ("Liquor" . survey-liquor)
                     ("Umbilical cord" . survey-umbilical-cord)
                     ("Fetal activity" . survey-fetal-activity)
                     ("Cardiac activity" . survey-cardiac-activity)))
       (list "Fetal Biometry\n")
       (seq-mapcat 'form-entry
                   '(("BPD" . biometry-bpd)
                     ("BPD-Age" . biometry-bpd-age)
                     ("BPD-Percentile" . biometry-bpd-percentile)
                     ("HC" . biometry-hc)
                     ("HC-Age" . biometry-hc-age)
                     ("HC-Percentile" . biometry-hc-percentile)
                     ("AC" . biometry-ac)
                     ("AC-Age" . biometry-ac-age)
                     ("AC-Percentile" . biometry-ac-percentile)
                     ("FL" . biometry-fl)
                     ("FL-Age" . biometry-fl-age)
                     ("FL-Percentile" . biometry-fl-percentile)
                     ("Estimated fetal weight according to BPD, HC, AC, FL" . biometry-fetal-weight)))
       (list "Extended Biometry\n")
       (seq-mapcat 'form-entry
                   '(("Foot Length" . extended-foot-length)
                     ("TCD" . extended-tcd)))
       (list "Fetal Anatomy\n")
       (seq-mapcat 'form-entry
                   '(("Intracranial structures" . anatomy-intracranial)
                     ("Neck" . anatomy-neck)
                     ("Spine" . anatomy-spine)
                     ("Fetal face" . anatomy-face)
                     ("Both lungs" . anatomy-lungs)
                     ("Heart" . anatomy-heart)
                     ("Abdominal situs" . anatomy-abdominal-situs)
                     ("Both kidneys and bladder" . anatomy-kidneys-bladder)
                     ("All long bones" . anatomy-long-bones)))
       (list "Impression\n")
       (seq-mapcat 'form-entry
                   '(("Gestational age" . impression-gestational-age)
                     ("Menstrual age" . impression-menstrual-age)
                     ("Corrected EDD" . impression-corrected-edd)
                     ("Notes" . impression-notes)
                     ("Sonologist" . sonologist)))))

(setq form-to-org
      (lambda ()
	(with-output-to-string
	  (make-report-header "OB - 2/3 TRIMESTER SCAN REPORT")
	  (seq-do 'single-line-org-entry
                  `(("IP/OP No" . ,ip-op-no)
                    ("Age" . ,age)
                    ("Sex" . ,sex)
                    ("Name of Patient" . ,patient-name)
                    ("Visit Date" . ,visit-date)
                    ("LMP Date" . ,lmp-date)
                    ("LMP EDD" . ,lmp-edd)))
	  (mapc 'princ `("* Indications\n" "** Target Scan\n"
			 "Real time B-mode ultrasonography of gravid uterus done.\n\n"))
          (single-line-org-entry '("Route" . "Transabdominal"))
	  (princ (get-field scan))
	  (princ "\n\n* Maternal\n")
	  (seq-do 'single-line-org-entry
                  `(("Cervix" . ,maternal-cervix)
                    ("Internal os" . ,maternal-internal-os)))
	  (princ "* Fetal Survey\n")
	  (seq-do 'single-line-org-entry
                  `(("Presentation" . ,survey-presentation)
                    ("Placenta" . ,survey-placenta)
                    ("Liquor" . ,survey-liquor)
                    ("Umbilical cord" . ,survey-umbilical-cord)
                    ("Fetal activity" . ,survey-fetal-activity)
                    ("Cardiac activity" . ,survey-cardiac-activity)))
	  (princ "* Fetal Biometry\n")
	  (insert-biometry
	   `(("BPD" ,biometry-bpd ,biometry-bpd-age ,biometry-bpd-percentile)
	     ("HC" ,biometry-hc ,biometry-hc-age ,biometry-hc-percentile)
	     ("AC" ,biometry-ac ,biometry-ac-age ,biometry-ac-percentile)
	     ("FL" ,biometry-fl ,biometry-fl-age ,biometry-fl-percentile)))
	  (princ "* Extended Biometry\n")
	  (seq-do 'single-line-org-entry
                  `(("Foot Length" . ,extended-foot-length)
                    ("TCD" . ,extended-tcd)))
	  (princ "* Fetal Anatomy\n")
	  (seq-do 'single-line-org-entry
                  `(("Intracranial structures" . ,anatomy-intracranial)
                    ("Neck" . ,anatomy-neck)
                    ("Spine" . ,anatomy-spine)
                    ("Fetal face" . ,anatomy-face)
                    ("Both lungs" . ,anatomy-lungs)
                    ("Heart" . ,anatomy-heart)
                    ("Abdominal situs" . ,anatomy-abdominal-situs)
                    ("Both kidneys and bladder" . ,anatomy-kidneys-bladder)
                    ("All long bones" . ,anatomy-long-bones)))
	  (princ "* Impression\n")
	  (princ (format "%s corresponding to a gestational age of %s\n\n"
			 (get-field scan) (get-field impression-gestational-age)))
	  (princ "Gestational age assigned as per biometry (CRL)\n\n")
	  (seq-do 'single-line-org-entry
                  `(("Menstrual age" . ,impression-menstrual-age)
                    ("Corrected EDD" . ,impression-corrected-edd)
                    ("Placenta" . ,survey-placenta)
                    ("Presentation" . ,survey-presentation)
                    ("Liquor" . ,survey-liquor)
                    ("Estimated fetal weight according to BPD, HC, AC, FL" . ,biometry-fetal-weight)))
	  (text-if-non-blank (get-field impression-notes))
          (multi-line-org-entry `("Sonologist" . ,sonologist)))))