chore: Removed healthcare demo, patch files

This commit is contained in:
ChillarAnand 2021-09-02 18:25:36 +05:30
parent bcb3f0fedb
commit 5d4133ecac
10 changed files with 0 additions and 504 deletions

View File

@ -1,171 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import datetime
import json
import frappe
from frappe.utils import getdate
from frappe.utils.make_random import get_random
from erpnext.demo.setup.setup_data import import_json
from erpnext.healthcare.doctype.lab_test.lab_test import create_test_from_template
def setup_data():
frappe.flags.mute_emails = True
make_masters()
make_patient()
make_lab_test()
make_consulation()
make_appointment()
consulation_on_appointment()
lab_test_on_encounter()
frappe.db.commit()
frappe.clear_cache()
def make_masters():
import_json("Healthcare Practitioner")
import_drug()
frappe.db.commit()
def make_patient():
file_path = get_json_path("Patient")
with open(file_path, "r") as open_file:
patient_data = json.loads(open_file.read())
count = 1
for d in enumerate(patient_data):
patient = frappe.new_doc("Patient")
patient.patient_name = d[1]['patient_name'].title()
patient.sex = d[1]['gender']
patient.blood_group = "A Positive"
patient.date_of_birth = datetime.datetime(1990, 3, 25)
patient.email_id = d[1]['patient_name'] + "_" + patient.date_of_birth.strftime('%m/%d/%Y') + "@example.com"
if count <5:
patient.insert()
frappe.db.commit()
count+=1
def make_appointment():
i = 1
while i <= 4:
practitioner = get_random("Healthcare Practitioner")
department = frappe.get_value("Healthcare Practitioner", practitioner, "department")
patient = get_random("Patient")
patient_sex = frappe.get_value("Patient", patient, "sex")
appointment = frappe.new_doc("Patient Appointment")
startDate = datetime.datetime.now()
for x in random_date(startDate,0):
appointment_datetime = x
appointment.appointment_datetime = appointment_datetime
appointment.appointment_time = appointment_datetime
appointment.appointment_date = appointment_datetime
appointment.patient = patient
appointment.patient_sex = patient_sex
appointment.practitioner = practitioner
appointment.department = department
appointment.save(ignore_permissions = True)
i += 1
def make_consulation():
for i in range(3):
practitioner = get_random("Healthcare Practitioner")
department = frappe.get_value("Healthcare Practitioner", practitioner, "department")
patient = get_random("Patient")
patient_sex = frappe.get_value("Patient", patient, "sex")
encounter = set_encounter(patient, patient_sex, practitioner, department, getdate(), i)
encounter.save(ignore_permissions=True)
def consulation_on_appointment():
for i in range(3):
appointment = get_random("Patient Appointment")
appointment = frappe.get_doc("Patient Appointment",appointment)
encounter = set_encounter(appointment.patient, appointment.patient_sex, appointment.practitioner, appointment.department, appointment.appointment_date, i)
encounter.appointment = appointment.name
encounter.save(ignore_permissions=True)
def set_encounter(patient, patient_sex, practitioner, department, encounter_date, i):
encounter = frappe.new_doc("Patient Encounter")
encounter.patient = patient
encounter.patient_sex = patient_sex
encounter.practitioner = practitioner
encounter.visit_department = department
encounter.encounter_date = encounter_date
if i > 2 and patient_sex=='Female':
encounter.symptoms = "Having chest pains for the last week."
encounter.diagnosis = """This patient's description of dull, aching,
exertion related substernal chest pain is suggestive of ischemic
cardiac origin. Her findings of a FH of early ASCVD, hypertension,
and early surgical menopause are pertinent risk factors for development
of coronary artery disease. """
else:
encounter = append_drug_rx(encounter)
encounter = append_test_rx(encounter)
return encounter
def make_lab_test():
practitioner = get_random("Healthcare Practitioner")
patient = get_random("Patient")
patient_sex = frappe.get_value("Patient", patient, "sex")
template = get_random("Lab Test Template")
set_lab_test(patient, patient_sex, practitioner, template)
def lab_test_on_encounter():
i = 1
while i <= 2:
test_rx = get_random("Lab Prescription", filters={'test_created': 0})
test_rx = frappe.get_doc("Lab Prescription", test_rx)
encounter = frappe.get_doc("Patient Encounter", test_rx.parent)
set_lab_test(encounter.patient, encounter.patient_sex, encounter.practitioner, test_rx.test_code, test_rx.name)
i += 1
def set_lab_test(patient, patient_sex, practitioner, template, rx=None):
lab_test = frappe.new_doc("Lab Test")
lab_test.practitioner = practitioner
lab_test.patient = patient
lab_test.patient_sex = patient_sex
lab_test.template = template
lab_test.prescription = rx
create_test_from_template(lab_test)
def append_test_rx(encounter):
i = 1
while i <= 2:
test_rx = encounter.append("test_prescription")
test_rx.test_code = get_random("Lab Test Template")
i += 1
return encounter
def append_drug_rx(encounter):
i = 1
while i <= 3:
drug = get_random("Item", filters={"item_group":"Drug"})
drug = frappe.get_doc("Item", drug)
drug_rx = encounter.append("drug_prescription")
drug_rx.drug_code = drug.item_code
drug_rx.drug_name = drug.item_name
drug_rx.dosage = get_random("Prescription Dosage")
drug_rx.period = get_random("Prescription Duration")
i += 1
return encounter
def random_date(start,l):
current = start
while l >= 0:
curr = current + datetime.timedelta(minutes=60)
yield curr
l-=1
def import_drug():
frappe.flags.in_import = True
data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'drug_list.json')).read())
for d in data:
doc = frappe.new_doc("Item")
doc.update(d)
doc.insert()
frappe.flags.in_import = False
def get_json_path(doctype):
return frappe.get_app_path('erpnext', 'demo', 'data', frappe.scrub(doctype) + '.json')

View File

@ -1,71 +0,0 @@
from __future__ import unicode_literals
data = {
'desktop_icons': [
'Patient',
'Patient Appointment',
'Patient Encounter',
'Lab Test',
'Healthcare',
'Vital Signs',
'Clinical Procedure',
'Inpatient Record',
'Accounts',
'Buying',
'Stock',
'HR',
'ToDo'
],
'default_portal_role': 'Patient',
'restricted_roles': [
'Healthcare Administrator',
'LabTest Approver',
'Laboratory User',
'Nursing User',
'Physician',
'Patient'
],
'custom_fields': {
'Sales Invoice': [
{
'fieldname': 'patient', 'label': 'Patient', 'fieldtype': 'Link', 'options': 'Patient',
'insert_after': 'naming_series'
},
{
'fieldname': 'patient_name', 'label': 'Patient Name', 'fieldtype': 'Data', 'fetch_from': 'patient.patient_name',
'insert_after': 'patient', 'read_only': True
},
{
'fieldname': 'ref_practitioner', 'label': 'Referring Practitioner', 'fieldtype': 'Link', 'options': 'Healthcare Practitioner',
'insert_after': 'customer'
}
],
'Sales Invoice Item': [
{
'fieldname': 'reference_dt', 'label': 'Reference DocType', 'fieldtype': 'Link', 'options': 'DocType',
'insert_after': 'edit_references'
},
{
'fieldname': 'reference_dn', 'label': 'Reference Name', 'fieldtype': 'Dynamic Link', 'options': 'reference_dt',
'insert_after': 'reference_dt'
}
],
'Stock Entry': [
{
'fieldname': 'inpatient_medication_entry', 'label': 'Inpatient Medication Entry', 'fieldtype': 'Link', 'options': 'Inpatient Medication Entry',
'insert_after': 'credit_note', 'read_only': True
}
],
'Stock Entry Detail': [
{
'fieldname': 'patient', 'label': 'Patient', 'fieldtype': 'Link', 'options': 'Patient',
'insert_after': 'po_detail', 'read_only': True
},
{
'fieldname': 'inpatient_medication_entry_child', 'label': 'Inpatient Medication Entry Child', 'fieldtype': 'Data',
'insert_after': 'patient', 'read_only': True
}
]
},
'on_setup': 'erpnext.healthcare.setup.setup_healthcare'
}

View File

@ -1,22 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe import _
def execute():
""" assign lft and rgt appropriately """
if "Healthcare" not in frappe.get_active_domains():
return
frappe.reload_doc("healthcare", "doctype", "healthcare_service_unit")
frappe.reload_doc("healthcare", "doctype", "healthcare_service_unit_type")
company = frappe.get_value("Company", {"domain": "Healthcare"}, "name")
if company:
frappe.get_doc({
'doctype': 'Healthcare Service Unit',
'healthcare_service_unit_name': _('All Healthcare Service Units'),
'is_group': 1,
'company': company
}).insert(ignore_permissions=True)

View File

@ -1,69 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from frappe.modules import get_doctype_module, scrub
from erpnext.domains.healthcare import data
sales_invoice_referenced_doc = {
"Patient Appointment": "sales_invoice",
"Patient Encounter": "invoice",
"Lab Test": "invoice",
"Lab Prescription": "invoice",
"Sample Collection": "invoice"
}
def execute():
frappe.reload_doc('accounts', 'doctype', 'loyalty_program')
frappe.reload_doc('accounts', 'doctype', 'sales_invoice_item')
if "Healthcare" not in frappe.get_active_domains():
return
healthcare_custom_field_in_sales_invoice()
for si_ref_doc in sales_invoice_referenced_doc:
if frappe.db.exists('DocType', si_ref_doc):
frappe.reload_doc(get_doctype_module(si_ref_doc), 'doctype', scrub(si_ref_doc))
if frappe.db.has_column(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]) \
and frappe.db.has_column(si_ref_doc, 'invoiced'):
# Set Reference DocType and Reference Docname
doc_list = frappe.db.sql("""
select name from `tab{0}`
where {1} is not null
""".format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]))
if doc_list:
frappe.reload_doc(get_doctype_module("Sales Invoice"), 'doctype', 'sales_invoice')
for doc_id in doc_list:
invoice_id = frappe.db.get_value(si_ref_doc, doc_id[0], sales_invoice_referenced_doc[si_ref_doc])
if frappe.db.exists("Sales Invoice", invoice_id):
if si_ref_doc == "Lab Test":
template = frappe.db.get_value("Lab Test", doc_id[0], "template")
if template:
item = frappe.db.get_value("Lab Test Template", template, "item")
if item:
frappe.db.sql("""update `tabSales Invoice Item` set reference_dt = '{0}',
reference_dn = '{1}' where parent = '{2}' and item_code='{3}'""".format\
(si_ref_doc, doc_id[0], invoice_id, item))
else:
invoice = frappe.get_doc("Sales Invoice", invoice_id)
for item_line in invoice.items:
if not item_line.reference_dn:
item_line.db_set({"reference_dt":si_ref_doc, "reference_dn": doc_id[0]})
break
# Documents mark invoiced for submitted sales invoice
frappe.db.sql("""update `tab{0}` doc, `tabSales Invoice` si
set doc.invoiced = 1 where si.docstatus = 1 and doc.{1} = si.name
""".format(si_ref_doc, sales_invoice_referenced_doc[si_ref_doc]))
def healthcare_custom_field_in_sales_invoice():
frappe.reload_doc('healthcare', 'doctype', 'patient')
frappe.reload_doc('healthcare', 'doctype', 'healthcare_practitioner')
if data['custom_fields']:
create_custom_fields(data['custom_fields'])
frappe.db.sql("""
delete from `tabCustom Field`
where fieldname = 'appointment' and options = 'Patient Appointment'
""")

View File

@ -1,11 +0,0 @@
# Copyright (c) 2018, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.rename_doc('DocType', 'Health Insurance', 'Employee Health Insurance', force=True)
frappe.reload_doc('hr', 'doctype', 'employee_health_insurance')

View File

@ -1,67 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
from frappe.modules import get_doctype_module, scrub
field_rename_map = {
"Patient Encounter": [
["consultation_time", "encounter_time"],
["consultation_date", "encounter_date"],
["consultation_comment", "encounter_comment"],
["physician", "practitioner"]
],
"Fee Validity": [
["physician", "practitioner"]
],
"Lab Test": [
["physician", "practitioner"]
],
"Patient Appointment": [
["physician", "practitioner"],
["referring_physician", "referring_practitioner"]
],
"Procedure Prescription": [
["physician", "practitioner"]
]
}
doc_rename_map = {
"Physician Schedule Time Slot": "Healthcare Schedule Time Slot",
"Physician Schedule": "Practitioner Schedule",
"Physician Service Unit Schedule": "Practitioner Service Unit Schedule",
"Consultation": "Patient Encounter",
"Physician": "Healthcare Practitioner"
}
def execute():
for dt in doc_rename_map:
if frappe.db.exists('DocType', dt):
frappe.rename_doc('DocType', dt, doc_rename_map[dt], force=True)
for dn in field_rename_map:
if frappe.db.exists('DocType', dn):
frappe.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))
for dt, field_list in field_rename_map.items():
if frappe.db.exists('DocType', dt):
for field in field_list:
if frappe.db.has_column(dt, field[0]):
rename_field(dt, field[0], field[1])
if frappe.db.exists('DocType', 'Practitioner Service Unit Schedule'):
if frappe.db.has_column('Practitioner Service Unit Schedule', 'parentfield'):
frappe.db.sql("""
update `tabPractitioner Service Unit Schedule` set parentfield = 'practitioner_schedules'
where parentfield = 'physician_schedules' and parenttype = 'Healthcare Practitioner'
""")
if frappe.db.exists("DocType", "Healthcare Practitioner"):
frappe.reload_doc("healthcare", "doctype", "healthcare_practitioner")
frappe.reload_doc("healthcare", "doctype", "practitioner_service_unit_schedule")
if frappe.db.has_column('Healthcare Practitioner', 'physician_schedule'):
for doc in frappe.get_all('Healthcare Practitioner'):
_doc = frappe.get_doc('Healthcare Practitioner', doc.name)
if _doc.physician_schedule:
_doc.append('practitioner_schedules', {'schedule': _doc.physician_schedule})
_doc.save()

View File

@ -1,54 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
from frappe.modules import get_doctype_module, scrub
lab_test_name = ["test_name", "lab_test_name"]
lab_test_code = ["test_code", "lab_test_code"]
lab_test_comment = ["test_comment", "lab_test_comment"]
lab_test_created = ["test_created", "lab_test_created"]
lab_test_template = ["test_template", "lab_test_template"]
lab_test_rate = ["test_rate", "lab_test_rate"]
lab_test_description = ["test_description", "lab_test_description"]
lab_test_group = ["test_group", "lab_test_group"]
lab_test_template_type = ["test_template_type", "lab_test_template_type"]
lab_test_uom = ["test_uom", "lab_test_uom"]
lab_test_normal_range = ["test_normal_range", "lab_test_normal_range"]
lab_test_event = ["test_event", "lab_test_event"]
lab_test_particulars = ["test_particulars", "lab_test_particulars"]
field_rename_map = {
"Lab Test Template": [lab_test_name, lab_test_code, lab_test_rate, lab_test_description,
lab_test_group, lab_test_template_type, lab_test_uom, lab_test_normal_range],
"Normal Test Items": [lab_test_name, lab_test_comment, lab_test_uom, lab_test_event],
"Lab Test": [lab_test_name, lab_test_comment, lab_test_group],
"Lab Prescription": [lab_test_name, lab_test_code, lab_test_comment, lab_test_created],
"Lab Test Groups": [lab_test_template, lab_test_rate, lab_test_description],
"Lab Test UOM": [lab_test_uom],
"Normal Test Template": [lab_test_uom, lab_test_event],
"Special Test Items": [lab_test_particulars]
}
def execute():
for dt, field_list in field_rename_map.items():
if frappe.db.exists('DocType', dt):
frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
for field in field_list:
if frappe.db.has_column(dt, field[0]):
rename_field(dt, field[0], field[1])
if frappe.db.exists('DocType', 'Lab Prescription'):
if frappe.db.has_column('Lab Prescription', 'parentfield'):
frappe.db.sql("""
update `tabLab Prescription` set parentfield = 'lab_test_prescription'
where parentfield = 'test_prescription'
""")
if frappe.db.exists('DocType', 'Lab Test Groups'):
if frappe.db.has_column('Lab Test Groups', 'parentfield'):
frappe.db.sql("""
update `tabLab Test Groups` set parentfield = 'lab_test_groups'
where parentfield = 'test_groups'
""")

View File

@ -1,8 +0,0 @@
import frappe
def execute():
job = frappe.db.exists('Scheduled Job Type', 'patient_appointment.send_appointment_reminder')
if job:
method = 'erpnext.healthcare.doctype.patient_appointment.patient_appointment.send_appointment_reminder'
frappe.db.set_value('Scheduled Job Type', job, 'method', method)

View File

@ -1,12 +0,0 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from erpnext.domains.healthcare import data
def execute():
if 'Healthcare' not in frappe.get_active_domains():
return
if data['custom_fields']:
create_custom_fields(data['custom_fields'])

View File

@ -1,19 +0,0 @@
from __future__ import unicode_literals
import frappe
from erpnext.healthcare.setup import setup_patient_history_settings
def execute():
if "Healthcare" not in frappe.get_active_domains():
return
frappe.reload_doc("healthcare", "doctype", "Inpatient Medication Order")
frappe.reload_doc("healthcare", "doctype", "Therapy Session")
frappe.reload_doc("healthcare", "doctype", "Clinical Procedure")
frappe.reload_doc("healthcare", "doctype", "Patient History Settings")
frappe.reload_doc("healthcare", "doctype", "Patient History Standard Document Type")
frappe.reload_doc("healthcare", "doctype", "Patient History Custom Document Type")
setup_patient_history_settings()