Rushabh Mehta | f056974 | 2017-09-13 12:52:30 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | import frappe |
| 3 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
| 4 | |
| 5 | from frappe import _ |
| 6 | |
| 7 | def setup_healthcare(): |
| 8 | create_medical_departments() |
| 9 | create_antibiotics() |
| 10 | create_test_uom() |
| 11 | create_duration() |
| 12 | create_dosage() |
| 13 | create_healthcare_item_groups() |
| 14 | create_lab_test_items() |
| 15 | create_lab_test_template() |
| 16 | create_sensitivity() |
| 17 | make_custom_fields() |
| 18 | |
| 19 | def make_custom_fields(): |
| 20 | custom_fields = { |
| 21 | 'Sales Invoice': [ |
| 22 | dict(fieldname='appointment', label='Patient Appointment', |
| 23 | fieldtype='Link', options='Patient Appointment', |
| 24 | insert_after='customer') |
| 25 | ] |
| 26 | } |
| 27 | |
| 28 | create_custom_fields(custom_fields) |
| 29 | |
| 30 | |
| 31 | def create_medical_departments(): |
| 32 | depts = ["Accident and emergency care" ,"Anaesthetics", "Biochemistry", "Cardiology", "Dermatology", |
| 33 | "Diagnostic imaging", "ENT", "Gastroenterology", "General Surgery", "Gynaecology", |
| 34 | "Haematology", "Maternity", "Microbiology", "Nephrology", "Neurology", "Oncology", |
| 35 | "Orthopaedics", "Pathology", "Physiotherapy", "Rheumatology", "Serology", "Urology"] |
| 36 | for d in depts: |
| 37 | mediacal_department = frappe.new_doc("Medical Department") |
| 38 | mediacal_department.department = d |
| 39 | try: |
| 40 | mediacal_department.save() |
| 41 | except frappe.DuplicateEntryError: |
| 42 | pass |
| 43 | |
| 44 | def create_antibiotics(): |
| 45 | abt = ["Amoxicillin", "Ampicillin", "Bacampicillin", "Carbenicillin", "Cloxacillin", "Dicloxacillin", |
| 46 | "Flucloxacillin", "Mezlocillin", "Nafcillin", "Oxacillin", "Penicillin G", "Penicillin V", |
| 47 | "Piperacillin", "Pivampicillin", "Pivmecillinam", "Ticarcillin", "Cefacetrile (cephacetrile)", |
| 48 | "Cefadroxil (cefadroxyl)", "Cefalexin (cephalexin)", "Cefaloglycin (cephaloglycin)", |
| 49 | "Cefalonium (cephalonium)", "Cefaloridine (cephaloradine)", "Cefalotin (cephalothin)", |
| 50 | "Cefapirin (cephapirin)", "Cefatrizine", "Cefazaflur", "Cefazedone", "Cefazolin (cephazolin)", |
| 51 | "Cefradine (cephradine)", "Cefroxadine", "Ceftezole", "Cefaclor", "Cefamandole", "Cefmetazole", |
| 52 | "Cefonicid", "Cefotetan", "Cefoxitin", "Cefprozil (cefproxil)", "Cefuroxime", "Cefuzonam", |
| 53 | "Cefcapene", "Cefdaloxime", "Cefdinir", "Cefditoren", "Cefetamet", "Cefixime", "Cefmenoxime", |
| 54 | "Cefodizime", "Cefotaxime", "Cefpimizole", "Cefpodoxime", "Cefteram", "Ceftibuten", "Ceftiofur", |
| 55 | "Ceftiolene", "Ceftizoxime", "Ceftriaxone", "Cefoperazone", "Ceftazidime", "Cefclidine", "Cefepime", |
| 56 | "Cefluprenam", "Cefoselis", "Cefozopran", "Cefpirome", "Cefquinome", "Ceftobiprole", "Ceftaroline", |
| 57 | "Cefaclomezine","Cefaloram", "Cefaparole", "Cefcanel", "Cefedrolor", "Cefempidone", "Cefetrizole", |
| 58 | "Cefivitril", "Cefmatilen", "Cefmepidium", "Cefovecin", "Cefoxazole", "Cefrotil", "Cefsumide", |
| 59 | "Cefuracetime", "Ceftioxide", "Ceftazidime/Avibactam", "Ceftolozane/Tazobactam", "Aztreonam", |
| 60 | "Imipenem", "Imipenem/cilastatin", "Doripenem", "Meropenem", "Ertapenem", "Azithromycin", |
| 61 | "Erythromycin", "Clarithromycin", "Dirithromycin", "Roxithromycin", "Telithromycin", "Clindamycin", |
| 62 | "Lincomycin", "Pristinamycin", "Quinupristin/dalfopristin", "Amikacin", "Gentamicin", "Kanamycin", |
| 63 | "Neomycin", "Netilmicin", "Paromomycin", "Streptomycin", "Tobramycin", "Flumequine", "Nalidixic acid", |
| 64 | "Oxolinic acid", "Piromidic acid", "Pipemidic acid", "Rosoxacin", "Ciprofloxacin", "Enoxacin", |
| 65 | "Lomefloxacin", "Nadifloxacin", "Norfloxacin", "Ofloxacin", "Pefloxacin", "Rufloxacin", "Balofloxacin", |
| 66 | "Gatifloxacin", "Grepafloxacin", "Levofloxacin", "Moxifloxacin", "Pazufloxacin", "Sparfloxacin", |
| 67 | "Temafloxacin", "Tosufloxacin", "Besifloxacin", "Clinafloxacin", "Gemifloxacin", |
| 68 | "Sitafloxacin", "Trovafloxacin", "Prulifloxacin", "Sulfamethizole", "Sulfamethoxazole", |
| 69 | "Sulfisoxazole", "Trimethoprim-Sulfamethoxazole", "Demeclocycline", "Doxycycline", "Minocycline", |
| 70 | "Oxytetracycline", "Tetracycline", "Tigecycline", "Chloramphenicol", "Metronidazole", |
| 71 | "Tinidazole", "Nitrofurantoin", "Vancomycin", "Teicoplanin", "Telavancin", "Linezolid", |
| 72 | "Cycloserine 2", "Rifampin", "Rifabutin", "Rifapentine", "Rifalazil", "Bacitracin", "Polymyxin B", |
| 73 | "Viomycin", "Capreomycin"] |
| 74 | for a in abt: |
| 75 | antibiotic = frappe.new_doc("Antibiotic") |
| 76 | antibiotic.antibiotic_name = a |
| 77 | try: |
| 78 | antibiotic.save() |
| 79 | except frappe.DuplicateEntryError: |
| 80 | pass |
| 81 | |
| 82 | def create_test_uom(): |
| 83 | records = [ |
| 84 | {"doctype": "Lab Test UOM", "name": "umol/L", "test_uom": "umol/L", "uom_description": None }, |
| 85 | {"doctype": "Lab Test UOM", "name": "mg/L", "test_uom": "mg/L", "uom_description": None }, |
| 86 | {"doctype": "Lab Test UOM", "name": "mg / dl", "test_uom": "mg / dl", "uom_description": None }, |
| 87 | {"doctype": "Lab Test UOM", "name": "pg / ml", "test_uom": "pg / ml", "uom_description": None }, |
| 88 | {"doctype": "Lab Test UOM", "name": "U/ml", "test_uom": "U/ml", "uom_description": None }, |
| 89 | {"doctype": "Lab Test UOM", "name": "/HPF", "test_uom": "/HPF", "uom_description": None }, |
| 90 | {"doctype": "Lab Test UOM", "name": "Million Cells / cumm", "test_uom": "Million Cells / cumm", "uom_description": None }, |
| 91 | {"doctype": "Lab Test UOM", "name": "Lakhs Cells / cumm", "test_uom": "Lakhs Cells / cumm", "uom_description": None }, |
| 92 | {"doctype": "Lab Test UOM", "name": "U / L", "test_uom": "U / L", "uom_description": None }, |
| 93 | {"doctype": "Lab Test UOM", "name": "g / L", "test_uom": "g / L", "uom_description": None }, |
| 94 | {"doctype": "Lab Test UOM", "name": "IU / ml", "test_uom": "IU / ml", "uom_description": None }, |
| 95 | {"doctype": "Lab Test UOM", "name": "gm %", "test_uom": "gm %", "uom_description": None }, |
| 96 | {"doctype": "Lab Test UOM", "name": "Microgram", "test_uom": "Microgram", "uom_description": None }, |
| 97 | {"doctype": "Lab Test UOM", "name": "Micron", "test_uom": "Micron", "uom_description": None }, |
| 98 | {"doctype": "Lab Test UOM", "name": "Cells / cumm", "test_uom": "Cells / cumm", "uom_description": None }, |
| 99 | {"doctype": "Lab Test UOM", "name": "%", "test_uom": "%", "uom_description": None }, |
| 100 | {"doctype": "Lab Test UOM", "name": "mm / dl", "test_uom": "mm / dl", "uom_description": None }, |
| 101 | {"doctype": "Lab Test UOM", "name": "mm / hr", "test_uom": "mm / hr", "uom_description": None }, |
| 102 | {"doctype": "Lab Test UOM", "name": "ulU / ml", "test_uom": "ulU / ml", "uom_description": None }, |
| 103 | {"doctype": "Lab Test UOM", "name": "ng / ml", "test_uom": "ng / ml", "uom_description": None }, |
| 104 | {"doctype": "Lab Test UOM", "name": "ng / dl", "test_uom": "ng / dl", "uom_description": None }, |
| 105 | {"doctype": "Lab Test UOM", "name": "ug / dl", "test_uom": "ug / dl", "uom_description": None } |
| 106 | ] |
| 107 | |
| 108 | insert_record(records) |
| 109 | |
| 110 | def create_duration(): |
| 111 | records = [ |
| 112 | {"doctype": "Prescription Duration", "name": "3 Month", "number": "3", "period": "Month" }, |
| 113 | {"doctype": "Prescription Duration", "name": "2 Month", "number": "2", "period": "Month" }, |
| 114 | {"doctype": "Prescription Duration", "name": "1 Month", "number": "1", "period": "Month" }, |
| 115 | {"doctype": "Prescription Duration", "name": "12 Hour", "number": "12", "period": "Hour" }, |
| 116 | {"doctype": "Prescription Duration", "name": "11 Hour", "number": "11", "period": "Hour" }, |
| 117 | {"doctype": "Prescription Duration", "name": "10 Hour", "number": "10", "period": "Hour" }, |
| 118 | {"doctype": "Prescription Duration", "name": "9 Hour", "number": "9", "period": "Hour" }, |
| 119 | {"doctype": "Prescription Duration", "name": "8 Hour", "number": "8", "period": "Hour" }, |
| 120 | {"doctype": "Prescription Duration", "name": "7 Hour", "number": "7", "period": "Hour" }, |
| 121 | {"doctype": "Prescription Duration", "name": "6 Hour", "number": "6", "period": "Hour" }, |
| 122 | {"doctype": "Prescription Duration", "name": "5 Hour", "number": "5", "period": "Hour" }, |
| 123 | {"doctype": "Prescription Duration", "name": "4 Hour", "number": "4", "period": "Hour" }, |
| 124 | {"doctype": "Prescription Duration", "name": "3 Hour", "number": "3", "period": "Hour" }, |
| 125 | {"doctype": "Prescription Duration", "name": "2 Hour", "number": "2", "period": "Hour" }, |
| 126 | {"doctype": "Prescription Duration", "name": "1 Hour", "number": "1", "period": "Hour" }, |
| 127 | {"doctype": "Prescription Duration", "name": "5 Week", "number": "5", "period": "Week" }, |
| 128 | {"doctype": "Prescription Duration", "name": "4 Week", "number": "4", "period": "Week" }, |
| 129 | {"doctype": "Prescription Duration", "name": "3 Week", "number": "3", "period": "Week" }, |
| 130 | {"doctype": "Prescription Duration", "name": "2 Week", "number": "2", "period": "Week" }, |
| 131 | {"doctype": "Prescription Duration", "name": "1 Week", "number": "1", "period": "Week" }, |
| 132 | {"doctype": "Prescription Duration", "name": "6 Day", "number": "6", "period": "Day" }, |
| 133 | {"doctype": "Prescription Duration", "name": "5 Day", "number": "5", "period": "Day" }, |
| 134 | {"doctype": "Prescription Duration", "name": "4 Day", "number": "4", "period": "Day" }, |
| 135 | {"doctype": "Prescription Duration", "name": "3 Day", "number": "3", "period": "Day" }, |
| 136 | {"doctype": "Prescription Duration", "name": "2 Day", "number": "2", "period": "Day" }, |
| 137 | {"doctype": "Prescription Duration", "name": "1 Day", "number": "1", "period": "Day" } |
| 138 | ] |
| 139 | insert_record(records) |
| 140 | |
| 141 | def create_dosage(): |
| 142 | records = [ |
| 143 | {"doctype": "Prescription Dosage", "name": "1-1-1-1", "dosage": "1-1-1-1","dosage_strength": |
| 144 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "13:00:00"},{"strength": "1.0","strength_time": "17:00:00"},{"strength": "1.0","strength_time": "21:00:00"}] |
| 145 | }, |
| 146 | {"doctype": "Prescription Dosage", "name": "0-0-1", "dosage": "0-0-1","dosage_strength": |
| 147 | [{"strength": "1.0","strength_time": "21:00:00"}] |
| 148 | }, |
| 149 | {"doctype": "Prescription Dosage", "name": "1-0-0", "dosage": "1-0-0","dosage_strength": |
| 150 | [{"strength": "1.0","strength_time": "9:00:00"}] |
| 151 | }, |
| 152 | {"doctype": "Prescription Dosage", "name": "0-1-0", "dosage": "0-1-0","dosage_strength": |
| 153 | [{"strength": "1.0","strength_time": "14:00:00"}] |
| 154 | }, |
| 155 | {"doctype": "Prescription Dosage", "name": "1-1-1", "dosage": "1-1-1","dosage_strength": |
| 156 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "14:00:00"},{"strength": "1.0","strength_time": "21:00:00"}] |
| 157 | }, |
| 158 | {"doctype": "Prescription Dosage", "name": "1-0-1", "dosage": "1-0-1","dosage_strength": |
| 159 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "21:00:00"}] |
| 160 | }, |
| 161 | {"doctype": "Prescription Dosage", "name": "Once Bedtime", "dosage": "Once Bedtime","dosage_strength": |
| 162 | [{"strength": "1.0","strength_time": "21:00:00"}] |
| 163 | }, |
| 164 | {"doctype": "Prescription Dosage", "name": "5 times a day", "dosage": "5 times a day","dosage_strength": |
| 165 | [{"strength": "1.0","strength_time": "5:00:00"}, {"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "13:00:00"},{"strength": "1.0","strength_time": "17:00:00"},{"strength": "1.0","strength_time": "21:00:00"}] |
| 166 | }, |
| 167 | {"doctype": "Prescription Dosage", "name": "QID", "dosage": "QID","dosage_strength": |
| 168 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "13:00:00"},{"strength": "1.0","strength_time": "17:00:00"},{"strength": "1.0","strength_time": "21:00:00"}] |
| 169 | }, |
| 170 | {"doctype": "Prescription Dosage", "name": "TID", "dosage": "TID","dosage_strength": |
| 171 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "14:00:00"},{"strength": "1.0","strength_time": "21:00:00"}] |
| 172 | }, |
| 173 | {"doctype": "Prescription Dosage", "name": "BID", "dosage": "BID","dosage_strength": |
| 174 | [{"strength": "1.0","strength_time": "9:00:00"}, {"strength": "1.0","strength_time": "21:00:00"}] |
| 175 | }, |
| 176 | {"doctype": "Prescription Dosage", "name": "Once Daily", "dosage": "Once Daily","dosage_strength": |
| 177 | [{"strength": "1.0","strength_time": "9:00:00"}] |
| 178 | } |
| 179 | ] |
| 180 | insert_record(records) |
| 181 | |
| 182 | def create_healthcare_item_groups(): |
| 183 | records = [ |
| 184 | {'doctype': 'Item Group', 'item_group_name': _('Laboratory'), |
| 185 | 'is_group': 0, 'parent_item_group': _('All Item Groups') }, |
| 186 | {'doctype': 'Item Group', 'item_group_name': _('Drug'), |
| 187 | 'is_group': 0, 'parent_item_group': _('All Item Groups') } |
| 188 | ] |
| 189 | insert_record(records) |
| 190 | |
| 191 | def create_lab_test_items(): |
| 192 | records = [ |
| 193 | {"doctype": "Item", "item_code": "MCH", "item_name": "MCH", "item_group": "Laboratory", |
| 194 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 195 | {"doctype": "Item", "item_code": "LDL", "item_name": "LDL", "item_group": "Laboratory", |
| 196 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 197 | {"doctype": "Item", "item_code": "GTT", "item_name": "GTT", "item_group": "Laboratory", |
| 198 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 199 | {"doctype": "Item", "item_code": "HDL", "item_name": "HDL", "item_group": "Laboratory", |
| 200 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 201 | {"doctype": "Item", "item_code": "BILT", "item_name": "BILT", "item_group": "Laboratory", |
| 202 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 203 | {"doctype": "Item", "item_code": "BILD", "item_name": "BILD", "item_group": "Laboratory", |
| 204 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 205 | {"doctype": "Item", "item_code": "BP", "item_name": "BP", "item_group": "Laboratory", |
| 206 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1}, |
| 207 | {"doctype": "Item", "item_code": "BS", "item_name": "BS", "item_group": "Laboratory", |
| 208 | "stock_uom": "Unit", "is_stock_item": 0, "is_purchase_item": 0, "is_sales_item": 1} |
| 209 | ] |
| 210 | insert_record(records) |
| 211 | |
| 212 | def create_lab_test_template(): |
| 213 | records = [ |
| 214 | {"doctype": "Lab Test Template", "name": "MCH","test_name": "MCH","test_code": "MCH", |
| 215 | "test_group": "Laboratory","department": "Haematology","item": "MCH", |
| 216 | "test_template_type": "Single","is_billable": 1,"test_rate": 0.0,"test_uom": "Microgram", |
| 217 | "test_normal_range": "27 - 32 Microgram", |
| 218 | "sensitivity": 0,"test_description": "Mean Corpuscular Hemoglobin"}, |
| 219 | {"doctype": "Lab Test Template", "name": "LDL","test_name": "LDL (Serum)","test_code": "LDL", |
| 220 | "test_group": "Laboratory","department": "Biochemistry", |
| 221 | "item": "LDL","test_template_type": "Single", |
| 222 | "is_billable": 1,"test_rate": 0.0,"test_uom": "mg / dl","test_normal_range": "70 - 160 mg/dlLow-density Lipoprotein (LDL)", |
| 223 | "sensitivity": 0,"test_description": "Low-density Lipoprotein (LDL)"}, |
| 224 | {"doctype": "Lab Test Template", "name": "GTT","test_name": "GTT","test_code": "GTT", |
| 225 | "test_group": "Laboratory","department": "Haematology", |
| 226 | "item": "GTT","test_template_type": "Single", |
| 227 | "is_billable": 1,"test_rate": 0.0,"test_uom": "mg / dl","test_normal_range": "Less than 85 mg/dl", |
| 228 | "sensitivity": 0,"test_description": "Glucose Tolerance Test"}, |
| 229 | {"doctype": "Lab Test Template", "name": "HDL","test_name": "HDL (Serum)","test_code": "HDL", |
| 230 | "test_group": "Laboratory","department": "Biochemistry", |
| 231 | "item": "HDL","test_template_type": "Single", |
| 232 | "is_billable": 1,"test_rate": 0.0,"test_uom": "mg / dl","test_normal_range": "35 - 65 mg/dl", |
| 233 | "sensitivity": 0,"test_description": "High-density Lipoprotein (HDL)"}, |
| 234 | {"doctype": "Lab Test Template", "name": "BILT","test_name": "Bilirubin Total","test_code": "BILT", |
| 235 | "test_group": "Laboratory","department": "Biochemistry", |
| 236 | "item": "BILT","test_template_type": "Single", |
| 237 | "is_billable": 1,"test_rate": 0.0,"test_uom": "mg / dl","test_normal_range": "0.2 - 1.2 mg / dl", |
| 238 | "sensitivity": 0,"test_description": "Bilirubin Total"}, |
| 239 | {"doctype": "Lab Test Template", "name": "BILD","test_name": "Bilirubin Direct","test_code": "BILD", |
| 240 | "test_group": "Laboratory","department": "Biochemistry", |
| 241 | "item": "BILD","test_template_type": "Single", |
| 242 | "is_billable": 1,"test_rate": 0.0,"test_uom": "mg / dl","test_normal_range": "0.4 mg / dl", |
| 243 | "sensitivity": 0,"test_description": "Bilirubin Direct"}, |
| 244 | |
| 245 | {"doctype": "Lab Test Template", "name": "BP","test_name": "Bile Pigment","test_code": "BP", |
| 246 | "test_group": "Laboratory","department": "Pathology", |
| 247 | "item": "BP","test_template_type": "Single", |
| 248 | "is_billable": 1,"test_rate": 0.0,"test_uom": "","test_normal_range": "", |
| 249 | "sensitivity": 0,"test_description": "Bile Pigment"}, |
| 250 | {"doctype": "Lab Test Template", "name": "BS","test_name": "Bile Salt","test_code": "BS", |
| 251 | "test_group": "Laboratory","department": "Pathology", |
| 252 | "item": "BS","test_template_type": "Single", |
| 253 | "is_billable": 1,"test_rate": 0.0,"test_uom": "","test_normal_range": "", |
| 254 | "sensitivity": 0,"test_description": "Bile Salt"} |
| 255 | ] |
| 256 | insert_record(records) |
| 257 | |
| 258 | def create_sensitivity(): |
| 259 | records = [ |
| 260 | {"doctype": "Sensitivity", "sensitivity": "Low Sensitivity"}, |
| 261 | {"doctype": "Sensitivity", "sensitivity": "High Sensitivity"}, |
| 262 | {"doctype": "Sensitivity", "sensitivity": "Moderate Sensitivity"}, |
| 263 | {"doctype": "Sensitivity", "sensitivity": "Susceptible"}, |
| 264 | {"doctype": "Sensitivity", "sensitivity": "Resistant"}, |
| 265 | {"doctype": "Sensitivity", "sensitivity": "Intermediate"} |
| 266 | ] |
| 267 | insert_record(records) |
| 268 | |
| 269 | def insert_record(records): |
| 270 | for r in records: |
| 271 | doc = frappe.new_doc(r.get("doctype")) |
| 272 | doc.update(r) |
| 273 | try: |
| 274 | doc.insert(ignore_permissions=True) |
| 275 | except frappe.DuplicateEntryError, e: |
| 276 | # pass DuplicateEntryError and continue |
| 277 | if e.args and e.args[0]==doc.doctype and e.args[1]==doc.name: |
| 278 | # make sure DuplicateEntryError is for the exact same doc and not a related doc |
| 279 | pass |
| 280 | else: |
| 281 | raise |