From 0f23a304bca1ffd886f53302b999d62fa9eb433e Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 6 Apr 2020 19:00:17 +0530 Subject: [PATCH] fix: added patch for refactored changes --- .../healthcare_practitioner.json | 5 +- .../healthcare/doctype/patient/patient.json | 22 ++- erpnext/patches.txt | 1 + .../update_healthcare_refactored_changes.py | 131 ++++++++++++++++++ 4 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 erpnext/patches/v12_0/update_healthcare_refactored_changes.py diff --git a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json index 9860a21ea7..fd5b6e12f6 100644 --- a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json +++ b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json @@ -241,8 +241,7 @@ "fieldname": "gender", "fieldtype": "Link", "label": "Gender", - "options": "Gender", - "reqd": 1 + "options": "Gender" }, { "fieldname": "employee_and_user_details_section", @@ -277,7 +276,7 @@ ], "image_field": "image", "links": [], - "modified": "2020-03-24 17:25:55.128808", + "modified": "2020-04-06 13:44:24.759623", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare Practitioner", diff --git a/erpnext/healthcare/doctype/patient/patient.json b/erpnext/healthcare/doctype/patient/patient.json index c80efd3f20..4258e4011d 100644 --- a/erpnext/healthcare/doctype/patient/patient.json +++ b/erpnext/healthcare/doctype/patient/patient.json @@ -266,31 +266,27 @@ }, { "fieldname": "tobacco_past_use", - "fieldtype": "Select", + "fieldtype": "Data", "ignore_xss_filter": 1, - "label": "Tobacco Consumption (Past)", - "options": "\nYes\nNo" + "label": "Tobacco Consumption Habbits (Past)" }, { "fieldname": "tobacco_current_use", - "fieldtype": "Select", + "fieldtype": "Data", "ignore_xss_filter": 1, - "label": "Tobacco Consumption (Present)", - "options": "\nYes\nNo" + "label": "Tobacco Consumption Habbits (Present)" }, { "fieldname": "alcohol_past_use", - "fieldtype": "Select", + "fieldtype": "Data", "ignore_xss_filter": 1, - "label": "Alcohol Consumption (Past)", - "options": "\nYes\nNo" + "label": "Alcohol Consumption Habbits (Past)" }, { "fieldname": "alcohol_current_use", - "fieldtype": "Select", + "fieldtype": "Data", "ignore_user_permissions": 1, - "label": "Alcohol Consumption (Present)", - "options": "\nYes\nNo" + "label": "Alcohol Consumption Habbits (Present)" }, { "fieldname": "column_break_32", @@ -361,7 +357,7 @@ "image_field": "image", "links": [], "max_attachments": 50, - "modified": "2020-03-20 14:59:53.945849", + "modified": "2020-04-06 12:55:30.807744", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8aec8bddb9..3ebfd1454d 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -660,3 +660,4 @@ erpnext.patches.v12_0.set_job_offer_applicant_email erpnext.patches.v12_0.create_irs_1099_field_united_states erpnext.patches.v12_0.move_bank_account_swift_number_to_bank erpnext.patches.v12_0.rename_bank_reconciliation_fields # 2020-01-22 +erpnext.patches.v12_0.update_healthcare_refactored_changes \ No newline at end of file diff --git a/erpnext/patches/v12_0/update_healthcare_refactored_changes.py b/erpnext/patches/v12_0/update_healthcare_refactored_changes.py new file mode 100644 index 0000000000..1fd8668609 --- /dev/null +++ b/erpnext/patches/v12_0/update_healthcare_refactored_changes.py @@ -0,0 +1,131 @@ +from __future__ import unicode_literals +import frappe +from frappe.model.utils.rename_field import rename_field +from frappe.modules import scrub, get_doctype_module + +field_rename_map = { + 'Healthcare Settings': [ + ['patient_master_name', 'patient_name_by'], + ['max_visit', 'max_visits'], + ['reg_sms', 'send_registration_msg'], + ['reg_msg', 'registration_msg'], + ['app_con', 'send_appointment_confirmation'], + ['app_con_msg', 'appointment_confirmation_msg'], + ['no_con', 'avoid_confirmation'], + ['app_rem', 'send_appointment_reminder'], + ['app_rem_msg', 'appointment_reminder_msg'], + ['rem_before', 'remind_before'], + ['manage_customer', 'link_customer_to_patient'], + ['create_test_on_si_submit', 'create_lab_test_on_si_submit'], + ['require_sample_collection', 'create_sample_collection_for_lab_test'], + ['require_test_result_approval', 'lab_test_approval_required'], + ['manage_appointment_invoice_automatically', 'automate_appointment_invoicing'] + ], + 'Drug Prescription':[ + ['use_interval', 'usage_interval'], + ['in_every', 'interval_uom'] + ], + 'Lab Test Template':[ + ['sample_quantity', 'sample_qty'], + ['sample_collection_details', 'sample_details'] + ], + 'Sample Collection':[ + ['sample_quantity', 'sample_qty'], + ['sample_collection_details', 'sample_details'] + ], + 'Fee Validity': [ + ['max_visit', 'max_visits'] + ] +} + +def execute(): + for dn in field_rename_map: + if frappe.db.exists('DocType', dn): + if dn == 'Healthcare Settings': + frappe.reload_doctype('Healthcare Settings') + else: + 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 dt == 'Healthcare Settings': + rename_field(dt, field[0], field[1]) + elif frappe.db.has_column(dt, field[0]): + rename_field(dt, field[0], field[1]) + + # first name mandatory in Patient + patients = frappe.get_all('Patient', fields=['name', 'patient_name']) + frappe.reload_doctype('Patient') + for entry in patients: + name = entry.patient_name.split(' ') + frappe.db.set_value('Patient', entry.name, 'first_name', name[0]) + + # mark Healthcare Practitioner status as Disabled + practitioners = frappe.db.sql("select name from `tabHealthcare Practitioner` where 'active'= 0", as_dict=1) + practitioners_lst = [p.name for p in practitioners] + frappe.reload_doctype('Healthcare Practitioner') + frappe.db.sql("update `tabHealthcare Practitioner` set status = 'Disabled' where name IN %(practitioners)s""", {"practitioners": practitioners_lst}) + + # set Clinical Procedure status + frappe.reload_doctype('Clinical Procedure') + frappe.db.sql(""" + UPDATE + `tabClinical Procedure` + SET + docstatus = (CASE WHEN status = 'Cancelled' THEN 2 + WHEN status = 'Draft' THEN 0 + ELSE 1 + END) + """) + + # set complaints and diagnosis in table multiselect in Patient Encounter + field_list = [ + ['visit_department', 'medical_department'], + ['type', 'appointment_type'] + ] + encounter_details = frappe.db.sql("""select symptoms, diagnosis, name from `tabPatient Encounter`""", as_dict=True) + frappe.reload_doc('healthcare', 'doctype', 'patient_encounter') + frappe.reload_doc('healthcare', 'doctype', 'patient_encounter_symptom') + frappe.reload_doc('healthcare', 'doctype', 'patient_encounter_diagnosis') + + for field in field_list: + if frappe.db.has_column(dt, field[0]): + rename_field(dt, field[0], field[1]) + + for entry in encounter_details: + doc = frappe.get_doc('Patient Encounter', entry.name) + symptoms = entry.symptoms.split('\n') + for symptom in symptoms: + if not frappe.db.exists('Complaint', symptom): + frappe.get_doc({ + 'doctype': 'Complaint', + 'complaints': symptom + }).insert() + row = doc.append('symptoms', { + 'complaint': symptom + }) + row.db_update() + + diagnosis = entry.diagnosis.split('\n') + for d in diagnosis: + if not frappe.db.exists('Diagnosis', d): + frappe.get_doc({ + 'doctype': 'Diagnosis', + 'diagnosis': d + }).insert() + row = doc.append('diagnosis', { + 'diagnosis': d + }) + row.db_update() + doc.db_update() + + # update fee validity status + frappe.db.sql(""" + UPDATE + `tabFee Validity` + SET + status = (CASE WHEN visited >= max_visits THEN 'Completed' + ELSE 'Pending' + END) + """) \ No newline at end of file