From 9d0ff961bc41a6000fc78523a36b0a872a270c4e Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 7 Apr 2020 16:43:22 +0530 Subject: [PATCH] fix: patch and tests --- .../test_patient_appointment.py | 10 +- erpnext/patches.txt | 17 ++- .../update_healthcare_refactored_changes.py | 131 +++++++++--------- 3 files changed, 86 insertions(+), 72 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 2a2f0455f6..4668e81287 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -59,8 +59,9 @@ class TestPatientAppointment(unittest.TestCase): def create_healthcare_docs(): patient = get_random('Patient') - practitioner = get_random('Healthcare Practitioner') - medical_department = get_random('Medical Department') + practitioner = frappe.db.exists('Healthcare Practitioner', '_Test Healthcare Practitioner') + medical_department = frappe.db.exists('Medical Department', '_Test Medical Department') + if not patient: patient = frappe.new_doc('Patient') patient.first_name = '_Test Patient' @@ -80,6 +81,7 @@ def create_healthcare_docs(): practitioner.gender = 'Female' practitioner.department = medical_department practitioner.op_consulting_charge = 500 + practitioner.inpatient_visit_charge = 500 practitioner.save(ignore_permissions=True) practitioner = practitioner.name @@ -98,7 +100,9 @@ def create_encounter(appointment=None): return encounter def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0): - create_healthcare_service_items() + item = create_healthcare_service_items() + frappe.db.set_value('Healthcare Settings', None, 'inpatient_visit_charge_item', item) + frappe.db.set_value('Healthcare Settings', None, 'op_consulting_charge_item', item) appointment = frappe.new_doc('Patient Appointment') appointment.patient = patient appointment.practitioner = practitioner diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 3ebfd1454d..ed8d4216fa 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -581,7 +581,7 @@ erpnext.patches.v11_0.rename_bom_wo_fields erpnext.patches.v12_0.set_default_homepage_type erpnext.patches.v11_0.rename_additional_salary_component_additional_salary erpnext.patches.v11_0.renamed_from_to_fields_in_project -erpnext.patches.v11_0.add_permissions_in_gst_settings +erpnext.patches.v11_0.add_permissions_in_gst_settings #2020-04-04 erpnext.patches.v11_1.setup_guardian_role execute:frappe.delete_doc('DocType', 'Notification Control') erpnext.patches.v12_0.set_gst_category @@ -626,10 +626,11 @@ erpnext.patches.v12_0.update_ewaybill_field_position erpnext.patches.v12_0.create_accounting_dimensions_in_missing_doctypes erpnext.patches.v11_1.set_status_for_material_request_type_manufacture erpnext.patches.v12_0.move_plaid_settings_to_doctype -execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_link') -execute:frappe.reload_doc('desk', 'doctype','dashboard') -execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_source') -execute:frappe.reload_doc('desk', 'doctype','dashboard_chart') +execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_link') +execute:frappe.reload_doc('desk', 'doctype', 'dashboard') +execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_source') +execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart') +execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_field') erpnext.patches.v12_0.add_default_dashboards erpnext.patches.v12_0.remove_bank_remittance_custom_fields erpnext.patches.v12_0.generate_leave_ledger_entries @@ -660,4 +661,8 @@ 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 +erpnext.patches.v12_0.set_received_qty_in_material_request_as_per_stock_uom +erpnext.patches.v12_0.set_received_qty_in_material_request_as_per_stock_uom +erpnext.patches.v12_0.recalculate_requested_qty_in_bin +erpnext.patches.v12_0.update_healthcare_refactored_changes + diff --git a/erpnext/patches/v12_0/update_healthcare_refactored_changes.py b/erpnext/patches/v12_0/update_healthcare_refactored_changes.py index 1fd8668609..5f249e4d17 100644 --- a/erpnext/patches/v12_0/update_healthcare_refactored_changes.py +++ b/erpnext/patches/v12_0/update_healthcare_refactored_changes.py @@ -55,77 +55,82 @@ def execute(): 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]) + if frappe.db.exists('DocType', 'Patient'): + patients = frappe.db.sql("select name, patient_name from `tabPatient`", as_dict=1) + frappe.reload_doc('healthcare', '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}) + if frappe.db.exists('DocType', 'Healthcare Practitioner'): + 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_doc('healthcare', '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) - """) + if frappe.db.exists('DocType', 'Clinical Procedure'): + frappe.reload_doc('healthcare', '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') + if frappe.db.exists('DocType', '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 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() + 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 = 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 - }).insert() - row = doc.append('diagnosis', { - 'diagnosis': d - }) - row.db_update() - doc.db_update() + }) + 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 + if frappe.db.exists('DocType', 'Fee Validity'): + # 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