]> Softwares of Agnibho - medscript.git/blob - README
Bugfix: Windows uninstall package permission error
[medscript.git] / README
1 MedScript
2 =========
3
4 MedScript is a medical prescription writing software. It is primarily for
5 medical practitioners for writing prescriptions.
6
7 The purpose of the program is to enable medical practitioners to prepare
8 computerized prescriptions. The program has been designed after the commonly
9 used prescription format among the medical practitioners in India.
10
11 File
12 ----
13
14 The program uses a custom file format mpaz (Medical Prescription Archive -
15 Zipped). It is a zip file in a specific format which includes:
16
17 1. A meta.json file containing file type and mpaz version.
18 2. A prescription.zip file containing the actual prescription.
19 3. An attachment folder containing attached files.
20 4. A template folder containing the bundled prescription template.
21
22 Optionally the mpaz archive may also include an S/MIME signature and
23 certificate for authentication.
24
25 The structure of the mpaz file is as follows:
26
27 <filename>.mpaz (zipped file)
28 |-- meta.json (e.g. {"type": "MedScript", "version": "<mpaz version>"})
29 |-- prescription.json (Prescription object in JSON format)
30 |-- template (included template for rendering)
31 | |-- index.html (Jinja2 template)
32 | |-- <other template files e.g. CSS>
33 |-- attachment (directory containing attachments)
34 | |-- <attached files>
35 |-- signature (optional: S/MIME signature)
36 |-- certificate.pem (optional: full certificate chain including end-user, intermediates and root certificate)
37
38 Directory
39 ---------
40
41 MedScript uses a directory structure to store user files. It is highly
42 configurable. An example directory structure is given below:
43
44 <medscript data directory> (configurable)
45 |-- document (for storing prescription files)
46 | |-- <document files>
47 |-- form (for custom input form files)
48 | |-- <custom forms in JSON format)
49 |-- log (for storing log files)
50 | |-- <log files written by the program>
51 |-- plugin (for installing plugins)
52 | |-- <installed plugins>
53 |-- prescriber (for storing prescriber information)
54 | |-- <prescriber files in JSON format>
55 |-- preset (for storing preset files)
56 | |-- additional.csv
57 | |-- advice.csv
58 | |-- certificate.csv
59 | |-- investigation.csv
60 | |-- medication.csv
61 | |-- note.csv
62 | |-- report.csv
63 |-- template
64 | |-- <installed templates>
65 |-- config.json (the configuration file)
66
67 Install
68 -------
69
70 MedScript can be used by simply downloading it from the repository and running
71 it with the Python 3 interpreter. The necessary python libraries need to
72 be installed. Alternatively the release versions can be
73 downloaded and used directly.
74
75 The required Python libraries are as follows:
76
77 1. PyQt6
78 2. PyQt6_sip
79 3. python_dateutil
80 4. Jinja2
81 5. lxml
82 6. Markdown
83 7. cryptography
84 8. packaging
85 9. watchdog
86
87 Usage
88 -----
89
90 When starting the program, the main window of is shown.The menu bar at the top
91 can be used to access most of the functions. The toolbar below it contains the
92 most commonly used functions for quick access.
93
94 ### Creating a prescription
95
96 A new prescription can be created right from the starting window.
97 Alternatively the "New File" menu option can be used to create a new
98 prescription.
99
100 There are eight tabs in the tab bar containing important parts of a
101 prescription.
102
103 1. Patient tab: It contains the demographical data of the patient, diagnosis
104 and a few extra parameters of the prescription. The diagnosis can be entered
105 here. To enter multiple diagnosis semicolon (;) may be used to separate them.
106 Please note that date of birth and age cannot be used simultaneously. There
107 are radio buttons to select which field to use in the prescription.
108
109 2. Clinical tab: It contains the clinical note regarding the patient. The
110 presets can be selected from the preset box at the top and inserted into the
111 note by clicking the insert button.
112
113 3. Report tab: It contains the reports shown by the patient. It also has the
114 preset option.
115
116 4. Advice tab: It contains the primary advices given to the patient. It is
117 usually printed at the top of the advice section of the prescription. It also
118 has the preset option.
119
120 5. Investigation tab: It contains the investigations suggested to the
121 patient. It also has the preset option.
122
123 6. Medication tab: It contains the medications advised to the patient. It has
124 the preset option. It can contain both the generic and brand names of a
125 medicine. To insert an alternative name (generic/brand) write it on the same
126 line and surround it with square brackets i.e []. It also has the preset
127 option.
128
129 7. Additional tab: It contains additional advice given to the patient. It is
130 commonly printed at the bottom of the prescription.
131
132 8. Certificate tab: It can be used to write a medical certificate. Rendering a
133 medical certificate requires use of a different template. The "medcert"
134 template included with MedScript can be used for this purpose.
135
136 9. Attachment tab: Files e.g. PDF, images may be attached to the prescription
137 file from the attachment tab. These attachments can be viewed later when
138 opening the prescription file with the program. However, this attachments are
139 not printed with the prescription.
140
141 ### Viewing the prescription
142
143 The prescription can be quickly viewed by using the "Quick Display" option
144 under the "Process" menu. Viewing the prescriptions this way only shows the
145 prescription data without considering the formatting. To display the
146 prescription in a printable format, use the rendering option instead.
147
148 ### Saving a prescription
149
150 The "Save File" or the "Save As" option from the "File" menu can be used to
151 save a file created or edited in the program.
152
153 While saving the template can be selected from the "Template" combo box in the
154 toolbar. The template will be saved in the mpaz file. When opening an existing
155 file the "Template" combo box has the option to change the template or to keep
156 it unchanged.
157
158 ### Opening a prescription
159
160 The prescriptions are saved in mpaz files and can be shared easily. To open a
161 prescription file, the "Open File" option from the file menu can be used.
162 Alternatively the file name can be supplied to the program as command line
163 argument when starting from the command line.
164
165
166 ### Rendering a prescription
167
168 The prescriptions can be rendered and subsequently printed from the "Process"
169 menu by selecting the "Render Prescription" option. Note that the files must
170 be saved before rendering. The rendered prescription is opened in a separate
171 window. It can be saved as PDF or printed directly.
172
173 ### Data
174
175 The prescription files in the default document folder are incorporated into an
176 index which can be used to quickly find a particular prescription. To use this
177 feature, select the "Show Index" option in the "File" menu. Any changes to the
178 directory including creation, modification or deletion of files is monitored
179 by the index and reflected accordingly.
180
181 The index can be filtered by using patient id, prescription id or patient's
182 name. The entries can be viewed directly, opened in the program for
183 editing/rendering or copied into a new prescription. This can be useful while
184 consulting follow up patients.
185
186 ### Template
187
188 The program uses Jinja2 template for rendering the prescription. A default
189 template is provided with the program. However, other templates (see default
190 template for reference) can be created and placed in the template folder to be
191 used for rendering the prescriptions. The drop down option in the toolbar can
192 be used to switch between available templates.
193
194 Note that the templates are packaged with the mpaz file which can be used for
195 rendering. However, modifying/saving the file overwrites it.
196
197 It is easy to develop templates for the program. How to develop templates is
198 mentioned below.
199
200 ### Markdown
201
202 This program supports markdown formatting. Markdown can be used to format the
203 prescriptions and certificates. It can be turned on from the
204 "Edit Configuration" dialog under the "Settings" menu.
205
206 Prescriber
207 ----------
208
209 The program is primarily targeted towards individual practitioners. However,
210 it can be easily adapted for multiple practitioners.
211
212 The "Current Prescriber" option under the "Settings" menu can be used to
213 view/edit the current prescriber. The "Select Prescriber" option can be used
214 to open the prescriber selector dialog. All the prescribers are listed here. A
215 prescriber can be selected from here. Prescribers can also be edited, deleted
216 or new prescribers can be created from this dialog.
217
218 The data of the practitioner is stored in JSON files in the prescriber
219 directory. The default file to be loaded is configured in the config file. A
220 command line option can be used to specify which alternative prescriber file
221 to load in the program, e.g. `<program> --prescriber <prescriber file>`.
222
223 Preset
224 ------
225
226 The program uses a preset system to insert repeatedly used text without the
227 need to type them. To use this feature the text must be entered beforehand to
228 the respective files. These files are in the CSV format and can be edited
229 with any spreadsheet editing software.
230
231 There is a preset editor included with this software as well. This editor can
232 be accessed by going to the "Settings" menu and selecting the "Edit Presets"
233 option.
234
235 The preset editor contains a drop down input at the top which can be used to
236 select the respective file to edit. There is also a "Save" button at the top
237 which can be used to save the changes to the selected file.
238
239 The data is presented in an editable table which can be used to edit the data
240 in the selected file. While editing, the KEY/VALUE format is to be used as
241 shown in the top row. The "Add Row" button at the bottom can be used to add a
242 new row for entry of new data.
243
244 The preset files are kept in the preset directory. The files associated with
245 medical certificate, clinical note, report, advice, investigation, medication
246 and additional are certificate.csv, note.csv, report.csv, advice.csv,
247 investigation.csv, medication.csv and additional.csv. Each file contains a top
248 row indicating the variables in the columns. The data is entered in two
249 columns with each row containing a KEY and a TEXT. The TEXT can be entered in
250 the edit area by selecting the KEY from the preset input. Blank files with
251 only the top row are included with the program.
252
253 Configuration
254 -------------
255
256 The default configuration file contains sane defaults and the program can be
257 used without editing it. However, the json formatted configuration file can be
258 edited to further tune the program to the users preference.
259
260 The default configuration is the config.json located in the config directory.
261 However, a different config file may be provided by using the
262 `<program> --config <filename>` command line argument.
263
264 It is recommended to use the default config file as base while creating
265 another customized config file.
266
267 A graphical configuration editor is also included with the program. It can be
268 accessed by going to the "Settings" menu and selecting the "Edit Configuration"
269 option. The configurable options are as follows:
270
271 1. Data directory: where the user data of the program is stored.
272
273 2. Prescriber: the default prescriber which is loaded when the program
274 starts.
275
276 3. Preset newline: whether a newline / line break to be inserted after a preset
277 is inserted.
278
279 4. Preset delimiter: CSV files may have different delimiters. By default
280 this program uses "," as delimiter, however this can be changed to ";" from
281 here.
282
283 5. Age/DOB: Checking this box makes new documents use age instead of date of
284 birth by default.
285
286 6. Markdown: The markdown formatting can be enabled from here.
287
288 7. Check update: Whether updates are available can be checked at program start
289 up by enabling this option.
290
291 8. Form: The custom input form system can be enabled from here.
292
293 9. Plugin: The plugin system can be enabled from here.
294
295 10. S/MIME: This is an experimental feature and is disabled by default. To use
296 it, it has to be enabled first from the settings. The Private key, X509
297 certificate and Root bundle can be selected from the options that follow this.
298
299 Prescription Object
300 -------------------
301
302 The program uses a Prescription object to store the prescription data. The
303 structure of the Prescription object is as follows:
304
305 prescription (Prescription object)
306 |-- date (string: date-time in the %Y-%m-%d %H:%M:%S format)
307 |-- id (string: the id of the prescription)
308 |-- pid (string: the patient's id)
309 |-- name (string: the name of the patient)
310 |-- dob (string: the date of birth)
311 |-- age (string: the age of the patient, may contain unit)
312 |-- sex (string: sex of the patient)
313 |-- address (string: address of the patient)
314 |-- contact (string: contact number / email of the patient)
315 |-- extra (string: extra data related to the prescription)
316 |-- mode (string: the mode of consultation e.g. tele-consultation)
317 |-- daw (boolean: dispense as written)
318 |-- diagnosis (string: diagnosis of the patient's condition)
319 |-- note (string: clinical note e.g. history, physical examination)
320 |-- report (string: available reports)
321 |-- advice (string: advice given to the patient, not the medications)
322 |-- investigation (string: investigations suggested for the patient)
323 |-- medication (string: the list of medications prescribed)
324 |-- additional (string: any additional advice/instructions)
325 |-- certificate (string: content of a medical certificate)
326 |-- custom (list: contents of custom input forms)
327 |-- properties (dictionary: plugin data, each plugin in separate key)
328 |-- prescriber (Prescriber object)
329 | |-- name (string: the name of the prescriber)
330 | |-- qualification (string: the qualification of the prescriber)
331 | |-- registration (string: the registration number of the prescriber)
332 | |-- address (string: the address of the prescriber)
333 | |-- contact (string: contact number / email of the prescriber)
334 | |-- extra (string: any extra data about the prescriber)
335 | |-- properties (dictionary: plugin data, each plugin in separate key)
336
337 Best practice for assigning plugin data to properties is to use a separate
338 key for each plugin and store the data as the value associated with that key.
339
340 Plugin
341 ------
342
343 MedScript has a plugin system which can be used to incorporate customized
344 plugins written in python. To use the plugins, the plugins must be saved in
345 the configured plugin directory and plugin must be enabled in the
346 configuration.
347
348 Enabling arbitrary plugin is dangerous and may cause catastrophic damage. Only
349 install plugins from trusted sources and review the code.
350
351 Plugin Development
352 ------------------
353
354 Developing MedScript plugin is very simple. All you need is to create a python
355 file and implement a few functions.
356
357 The plugin is kept in its own directory. The name of the directory is the name
358 of the plugin. A plugin directory must contain a file called main.py which
359 contains the functions needed by MedScript plugin system. The directory tree
360 is as follows:
361
362 <medscript data directory (e.g. ~/MedScript)>
363 |-- plugin
364 | |-- <plugin directory (e.g. the name of the plugin)
365 | | |-- main.py
366 | | |-- <other files needed by the plugin>
367
368 The main.py file may implement the following functions which will be called by
369 the program as needed:
370
371 def new(prescription)
372 Called when creating a new document. It is also called during program startup.
373 def open(prescription)
374 Called when opening a document.
375 def save(prescription)
376 Called when saving a document.
377 def refresh(prescription)
378 Called when the refresh interface option is selected.
379 def run(prescription)
380 Called when the option associated with the plugin is selected from the plugin menu.
381
382 The `prescription` parameter passed to the functions is a Prescription object.
383 The structure of this object is mentioned above. The `prescription` object can
384 be modified directly by the plugins.
385
386 Please note that an option associated with the plugin is added to the "Plugin"
387 menu if the plugin implements a `run` function. By default the name of the
388 option is the name of the plugin. However, this can be overridden by setting a
389 global variable called `name` with the desired name.
390
391 Plugins may ask for user confirmation before executing the `run` function by
392 setting a global variable called `confirm` containing the confirmation prompt.
393
394 Each function mentioned above may return a string which will be displayed to
395 the user by the program.
396
397 Plugins may get input from the user by implementing one or more of the
398 following functions:
399
400 def input(string text)
401 Get text input from the user.
402 def fileopen(string path)
403 Get file to open. Only called before "run" function.
404 def filesave(string path)
405 Get file to save. Only called before "run" function.
406
407 Plugin may run in the background by defining a global variable `background`
408 with the value `True`. This may be useful for long running tasks without
409 freezing the program. This is only available for the "run" function. However,
410 plugins running in the background can not modify the prescription object.
411
412 The plugin may implement one or more functions mentioned above, it is not
413 necessary to implement all.
414
415 An example plugin, that modifies the name of the patient, may be as follows:
416
417 name="Change Name"
418 background=False
419 text=""
420
421 def run(prescription):
422 global text
423 prescription.name=text
424 return("Name change")
425
426 def input(data):
427 global text
428 text=data.strip()
429
430 Plugins may also contain a web app written in HTML/JavaScript. To use it the
431 plugin must contain a function called `web` which takes the prescription object
432 and returns a tuple containing the URL of the web app and a json string
433 containing any data to be passed on to the web app. The `run` function of such
434 a plugin must take two arguments, the prescription and the data returned from
435 the web app.
436
437 The web app itself must include the `qtwebchannel.js` from PyQt6
438 (qrc:///qtwebchannel/qwebchannel.js). The webchannel exposes an object named
439 `js` to the web app. The web app may access the data from the plugin by using
440 the `js.get()` function. The web app may return data to the plugin by calling
441 the `run` function of the exposed `js` object with the return data as the
442 argument. The web app window may be closed by calling the `close` function of
443 the `js` object.
444
445 Template Development
446 --------------------
447
448 Templates are used to render the prescriptions to HTML. A template contains a
449 directory with the name of the template. This directory contains a file called
450 index.html and any other additional files needed.
451
452 <medscript data directory (e.g. ~/MedScript)>
453 |-- template
454 | |-- <template directory e.g. the name of the template>
455 | | |-- index.html (the Jinja2 template)
456 | | |-- <additional files e.g. CSS>
457
458 The index.html file is the Jinja2 template. The attributes of the Prescription
459 object is available to the template. For example the name of the patient can
460 be accessed by `{{name}}` while the name of the prescriber can be accessed by
461 `{{prescriber.name}}`.
462
463 Custom Input Forms
464 ------------------
465
466 Custom input forms can be used to create customized input fields which can be
467 accessed from the "Custom" tab. For this, the custom input form files must be
468 stored in the configured form directory and the form option must be enabled in
469 the configuration.
470
471 A custom form file is a JSON file with contains the following:
472
473 1. **title**: the title of the form.
474 2. **form**: a list containing the inputs. Each input has the following:
475 1. **name**: name of the input field, can be accessed from
476 templates/plugins.
477 2. **type**: valid input types are line (single line), text (multiple line),
478 date (date time), check (checkbox).
479 3. **description**: this is shown to the user and should briefly describe
480 the input.
481
482 An example form is provided below:
483
484 {
485 "title": "Example Form",
486 "form": [
487 {
488 "name": "example",
489 "type": "line",
490 "description": "Example Input"
491 }
492 ]
493 }
494
495 Package Installer
496 -----------------
497
498 MedScript has a package installer for convenient installation and
499 uninstallation of presets, templates, custom forms and plugins. It can be
500 accessed from the "Package Installer" option under the "Settings" menu.
501
502 The installed components are listed there. The installed components can be
503 uninstalled by selecting it and clicking the "Uninstall" button. New packages
504 can be installed by clicking the "Install" button and selecting the package
505 file. MedScript will ask for user's confirmation before installing each
506 component of the package.
507
508 Package Development
509 -------------------
510
511 MedScript installable packages are zip files containing preset, template,
512 form and plugin in respective folders. More than one of each component is
513 allowed in each package. The package structure is as follows:
514
515 <package as a zip file>
516 |-- preset
517 | |-- <preset files in CSV format>
518 |-- template
519 | |-- <template directories each containing index.html and other files>
520 |-- form
521 | |-- <custom input forms in JSON format>
522 |-- plugin
523 | |-- <plugin directories each containing main.py and other files>
524
525 The following names are not allowed as component names:
526
527 1. note
528 2. report
529 3. advice
530 4. investigation
531 5. medication
532 6. additional
533 7. certificate
534 8. default
535 9. medcert
536 10. <unchanged>
537
538
539 Website
540 -------
541
542 <https://code.agnibho.com/medscript/>
543
544 License
545 -------
546
547 MedScript
548
549 Copyright (C) 2023 Dr. Agnibho Mondal
550
551 MedScript is free software: you can redistribute it and/or modify it under the
552 terms of the GNU General Public License as published by the Free Software
553 Foundation, either version 3 of the License, or (at your option) any later
554 version.
555
556 MedScript is distributed in the hope that it will be useful, but WITHOUT ANY
557 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
558 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
559
560 You should have received a copy of the GNU General Public License along with
561 MedScript. If not, see <https://www.gnu.org/licenses/>.
562
563 Contact
564 -------
565
566 Dr. Agnibho Mondal
567
568 mondal@agnibho.com
569
570 www.agnibho.com