test: verify that all patches exist in patches.txt (#31371)

* chore: delete orphaned patches

* test: orphan/missing entries in patches.txt


[skip ci]
This commit is contained in:
Ankush Menat 2022-06-16 22:15:06 +05:30 committed by GitHub
parent b4a93da9f3
commit 6f2086d770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 267 deletions

View File

@ -1,131 +0,0 @@
import frappe
from frappe.model.utils.rename_field import rename_field
from frappe.modules import get_doctype_module, scrub
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
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
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")
if practitioners_lst:
frappe.db.sql(
"update `tabHealthcare Practitioner` set status = 'Disabled' where name IN %(practitioners)s"
"",
{"practitioners": practitioners_lst},
)
# set Clinical Procedure status
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
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 entry in encounter_details:
doc = frappe.get_doc("Patient Encounter", entry.name)
symptoms = entry.symptoms.split("\n") if entry.symptoms else []
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") if entry.diagnosis else []
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()
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)
"""
)

View File

@ -1,94 +0,0 @@
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
if frappe.db.exists("DocType", "Lab Test") and frappe.db.exists("DocType", "Lab Test Template"):
# rename child doctypes
doctypes = {
"Lab Test Groups": "Lab Test Group Template",
"Normal Test Items": "Normal Test Result",
"Sensitivity Test Items": "Sensitivity Test Result",
"Special Test Items": "Descriptive Test Result",
"Special Test Template": "Descriptive Test Template",
}
frappe.reload_doc("healthcare", "doctype", "lab_test")
frappe.reload_doc("healthcare", "doctype", "lab_test_template")
for old_dt, new_dt in doctypes.items():
frappe.flags.link_fields = {}
should_rename = frappe.db.table_exists(old_dt) and not frappe.db.table_exists(new_dt)
if should_rename:
frappe.reload_doc("healthcare", "doctype", frappe.scrub(old_dt))
frappe.rename_doc("DocType", old_dt, new_dt, force=True)
frappe.reload_doc("healthcare", "doctype", frappe.scrub(new_dt))
frappe.delete_doc_if_exists("DocType", old_dt)
parent_fields = {
"Lab Test Group Template": "lab_test_groups",
"Descriptive Test Template": "descriptive_test_templates",
"Normal Test Result": "normal_test_items",
"Sensitivity Test Result": "sensitivity_test_items",
"Descriptive Test Result": "descriptive_test_items",
}
for doctype, parentfield in parent_fields.items():
frappe.db.sql(
"""
UPDATE `tab{0}`
SET parentfield = %(parentfield)s
""".format(
doctype
),
{"parentfield": parentfield},
)
# copy renamed child table fields (fields were already renamed in old doctype json, hence sql)
rename_fields = {
"lab_test_name": "test_name",
"lab_test_event": "test_event",
"lab_test_uom": "test_uom",
"lab_test_comment": "test_comment",
}
for new, old in rename_fields.items():
if frappe.db.has_column("Normal Test Result", old):
frappe.db.sql("""UPDATE `tabNormal Test Result` SET {} = {}""".format(new, old))
if frappe.db.has_column("Normal Test Template", "test_event"):
frappe.db.sql("""UPDATE `tabNormal Test Template` SET lab_test_event = test_event""")
if frappe.db.has_column("Normal Test Template", "test_uom"):
frappe.db.sql("""UPDATE `tabNormal Test Template` SET lab_test_uom = test_uom""")
if frappe.db.has_column("Descriptive Test Result", "test_particulars"):
frappe.db.sql(
"""UPDATE `tabDescriptive Test Result` SET lab_test_particulars = test_particulars"""
)
rename_fields = {
"lab_test_template": "test_template",
"lab_test_description": "test_description",
"lab_test_rate": "test_rate",
}
for new, old in rename_fields.items():
if frappe.db.has_column("Lab Test Group Template", old):
frappe.db.sql("""UPDATE `tabLab Test Group Template` SET {} = {}""".format(new, old))
# rename field
frappe.reload_doc("healthcare", "doctype", "lab_test")
if frappe.db.has_column("Lab Test", "special_toggle"):
rename_field("Lab Test", "special_toggle", "descriptive_toggle")
if frappe.db.exists("DocType", "Lab Test Group Template"):
# fix select field option
frappe.reload_doc("healthcare", "doctype", "lab_test_group_template")
frappe.db.sql(
"""
UPDATE `tabLab Test Group Template`
SET template_or_new_line = 'Add New Line'
WHERE template_or_new_line = 'Add new line'
"""
)

View File

@ -1,9 +0,0 @@
# Copyright (c) 2019, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from erpnext.setup.install import create_print_uom_after_qty_custom_field
def execute():
create_print_uom_after_qty_custom_field()

View File

@ -1,8 +0,0 @@
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
frappe.reload_doc("Healthcare", "doctype", "Inpatient Record")
if frappe.db.has_column("Inpatient Record", "discharge_date"):
rename_field("Inpatient Record", "discharge_date", "discharge_datetime")

View File

@ -1,25 +0,0 @@
import frappe
def execute():
company = frappe.db.get_single_value("Global Defaults", "default_company")
doctypes = [
"Clinical Procedure",
"Inpatient Record",
"Lab Test",
"Sample Collection",
"Patient Appointment",
"Patient Encounter",
"Vital Signs",
"Therapy Session",
"Therapy Plan",
"Patient Assessment",
]
for entry in doctypes:
if frappe.db.exists("DocType", entry):
frappe.reload_doc("Healthcare", "doctype", entry)
frappe.db.sql(
"update `tab{dt}` set company = {company} where ifnull(company, '') = ''".format(
dt=entry, company=frappe.db.escape(company)
)
)

View File

@ -45,3 +45,8 @@ class TestInit(unittest.TestCase):
from frappe.tests.test_translate import verify_translation_files
verify_translation_files("erpnext")
def test_patches(self):
from frappe.tests.test_patches import check_patch_files
check_patch_files("erpnext")