]>
Softwares of Agnibho - medscript.git/blob - config.py
2 # Copyright (C) 2023 Dr. Agnibho Mondal
3 # This file is part of MedScript.
4 # MedScript is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
8 import argparse
, json
, os
, sys
, shutil
, imp
10 default_config_file
= os
. path
. abspath ( os
. path
. join ( os
. path
. dirname ( os
. path
. realpath ( sys
. argv
[ 0 ])), "data" , "config.json" ))
12 real_dir
= os
. path
. dirname ( os
. path
. realpath ( sys
. argv
[ 0 ]))
15 imp
. find_module ( "M2Crypto" )
17 except Exception as e
:
21 parser
= argparse
. ArgumentParser ()
22 parser
. add_argument ( "filename" , nargs
= "?" )
23 parser
. add_argument ( "-c" , "--config" )
24 parser
. add_argument ( "-p" , "--prescriber" )
25 args
= parser
. parse_args ()
27 if ( args
. config
is None ):
28 config_file
= default_config_file
30 config_file
= args
. config
33 "data_directory" : "data" ,
34 "document_directory" : "document" ,
35 "prescriber_directory" : "prescriber" ,
36 "prescriber" : "prescriber" ,
37 "template_directory" : "template" ,
38 "template" : "default_prescription" ,
39 "preset_directory" : "preset" ,
40 "preset_newline" : "True" ,
41 "preset_delimiter" : "," ,
50 with
open ( config_file
) as conf
:
51 read
= json
. loads ( conf
. read ())
52 config
= default | read
53 except Exception as e
:
57 config
[ "filename" ]= args
. filename
58 config
[ "data_directory" ]= os
. path
. abspath ( os
. path
. join ( real_dir
, os
. path
. expanduser ( config
[ "data_directory" ])))
59 config
[ "document_directory" ]= os
. path
. join ( config
[ "data_directory" ], config
[ "document_directory" ])
60 config
[ "preset_directory" ]= os
. path
. join ( config
[ "data_directory" ], config
[ "preset_directory" ])
61 config
[ "template_directory" ]= os
. path
. join ( config
[ "data_directory" ], config
[ "template_directory" ])
62 config
[ "template" ]= os
. path
. join ( config
[ "template_directory" ], config
[ "template" ])
63 config
[ "resource" ]= os
. path
. abspath ( os
. path
. join ( real_dir
, "resource" ))
64 if ( args
. prescriber
is None ):
65 config
[ "prescriber_directory" ]= os
. path
. join ( config
[ "data_directory" ], config
[ "prescriber_directory" ])
66 config
[ "prescriber" ]= os
. path
. join ( config
[ "prescriber_directory" ], config
[ "prescriber" ])
67 if ( not config
[ "prescriber" ]. endswith ( ".json" )): config
[ "prescriber" ]= config
[ "prescriber" ]+ ".json"
69 if ( not os
. path
. isabs ( args
. prescriber
)):
70 args
. prescriber
= os
. path
. join ( config
[ "prescriber_directory" ], args
. prescriber
)
71 if ( os
. path
. isfile ( args
. prescriber
)):
72 config
[ "prescriber" ]= args
. prescriber
74 config
[ "prescriber" ]= os
. path
. join ( config
[ "prescriber_directory" ], config
[ "prescriber" ])
75 print ( "File " + args
. prescriber
+ " not found." )
77 os
. makedirs ( config
[ "data_directory" ], exist_ok
= True )
78 os
. makedirs ( config
[ "document_directory" ], exist_ok
= True )
79 os
. makedirs ( config
[ "prescriber_directory" ], exist_ok
= True )
80 os
. makedirs ( config
[ "preset_directory" ], exist_ok
= True )
81 os
. makedirs ( config
[ "template_directory" ], exist_ok
= True )
82 if not os
. path
. exists ( os
. path
. join ( config
[ "data_directory" ], "config.json" )):
83 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "config.json" )), os
. path
. join ( config
[ "data_directory" ], "config.json" ))
84 if not os
. path
. exists ( os
. path
. join ( config
[ "prescriber_directory" ], "prescriber.json" )):
85 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "prescriber" , "prescriber.json" )), os
. path
. join ( config
[ "prescriber_directory" ], "prescriber.json" ))
86 if not os
. path
. exists ( os
. path
. join ( config
[ "template_directory" ], "default" )):
87 shutil
. copytree ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "template" , "default" )), os
. path
. join ( config
[ "template_directory" ], "default" ))
88 if not os
. path
. exists ( os
. path
. join ( config
[ "template_directory" ], "medcert" )):
89 shutil
. copytree ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "template" , "medcert" )), os
. path
. join ( config
[ "template_directory" ], "medcert" ))
90 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "certify.csv" )):
91 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "certify.csv" )), os
. path
. join ( config
[ "preset_directory" ], "certify.csv" ))
92 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "note.csv" )):
93 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "note.csv" )), os
. path
. join ( config
[ "preset_directory" ], "note.csv" ))
94 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "report.csv" )):
95 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "report.csv" )), os
. path
. join ( config
[ "preset_directory" ], "report.csv" ))
96 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "investigation.csv" )):
97 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "investigation.csv" )), os
. path
. join ( config
[ "preset_directory" ], "investigation.csv" ))
98 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "advice.csv" )):
99 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "advice.csv" )), os
. path
. join ( config
[ "preset_directory" ], "advice.csv" ))
100 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "medication.csv" )):
101 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "medication.csv" )), os
. path
. join ( config
[ "preset_directory" ], "medication.csv" ))
102 if not os
. path
. exists ( os
. path
. join ( config
[ "preset_directory" ], "additional.csv" )):
103 shutil
. copyfile ( os
. path
. abspath ( os
. path
. join ( real_dir
, "data" , "preset" , "additional.csv" )), os
. path
. join ( config
[ "preset_directory" ], "additional.csv" ))