Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: db.get_single_value and db.set_single_value #248

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def get_sms_text(doc):
doc = frappe.get_doc("Lab Test", doc)
context = {"doc": doc, "alert": doc, "comments": None}

emailed = frappe.db.get_value("Healthcare Settings", None, "sms_emailed")
emailed = frappe.db.get_single_value("Healthcare Settings", "sms_emailed")
sms_text["emailed"] = frappe.render_template(emailed, context)

printed = frappe.db.get_value("Healthcare Settings", None, "sms_printed")
printed = frappe.db.get_single_value("Healthcare Settings", "sms_printed")
sms_text["printed"] = frappe.render_template(printed, context)

return sms_text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):

def test_status(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 0)
appointment = create_appointment(patient, practitioner, nowdate())
self.assertEqual(appointment.status, "Open")
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 2))
Expand All @@ -45,7 +45,7 @@ def test_status(self):

def test_start_encounter(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), invoice=1)
appointment.reload()
self.assertEqual(appointment.invoiced, 1)
Expand All @@ -61,12 +61,12 @@ def test_start_encounter(self):

def test_auto_invoicing(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 0)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 0)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 0)
appointment = create_appointment(patient, practitioner, nowdate())
self.assertEqual(frappe.db.get_value("Patient Appointment", appointment.name, "invoiced"), 0)

frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 2), invoice=1)
self.assertEqual(frappe.db.get_value("Patient Appointment", appointment.name, "invoiced"), 1)
sales_invoice_name = frappe.db.get_value(
Expand All @@ -86,8 +86,8 @@ def test_auto_invoicing(self):
def test_auto_invoicing_based_on_department(self):
patient, practitioner = create_healthcare_docs()
medical_department = create_medical_department()
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 0)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
appointment_type = create_appointment_type({"medical_department": medical_department})

appointment = create_appointment(
Expand All @@ -114,8 +114,8 @@ def test_auto_invoicing_based_on_department(self):

def test_auto_invoicing_according_to_appointment_type_charge(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 0)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)

item = create_healthcare_service_items()
items = [{"op_consulting_charge_item": item, "op_consulting_charge": 300}]
Expand All @@ -139,7 +139,7 @@ def test_auto_invoicing_according_to_appointment_type_charge(self):

def test_appointment_cancel(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 1)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 1)
appointment = create_appointment(patient, practitioner, nowdate())
fee_validity = frappe.db.get_value(
"Fee Validity", {"patient": patient, "practitioner": practitioner}
Expand All @@ -155,8 +155,8 @@ def test_appointment_cancel(self):
# check fee validity updated
self.assertEqual(frappe.db.get_value("Fee Validity", fee_validity, "visited"), 0)

frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 0)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 1), invoice=1)
update_status(appointment.name, "Cancelled")
# check invoice cancelled
Expand Down Expand Up @@ -237,10 +237,10 @@ def test_invalid_healthcare_service_unit_validation(self):
discharge_patient(ip_record1)

def test_payment_should_be_mandatory_for_new_patient_appointment(self):
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 1)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_value("Healthcare Settings", None, "max_visits", 3)
frappe.db.set_value("Healthcare Settings", None, "valid_days", 30)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 1)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "max_visits", 3)
frappe.db.set_single_value("Healthcare Settings", "valid_days", 30)

patient = create_patient()
assert check_is_new_patient(patient)
Expand All @@ -249,7 +249,7 @@ def test_payment_should_be_mandatory_for_new_patient_appointment(self):

def test_sales_invoice_should_be_generated_for_new_patient_appointment(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
invoice_count = frappe.db.count("Sales Invoice")

assert check_is_new_patient(patient)
Expand Down Expand Up @@ -449,8 +449,8 @@ def create_appointment(
department=None,
):
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)
frappe.db.set_single_value("Healthcare Settings", "inpatient_visit_charge_item", item)
frappe.db.set_single_value("Healthcare Settings", "op_consulting_charge_item", item)
appointment = frappe.new_doc("Patient Appointment")
appointment.patient = patient
appointment.practitioner = practitioner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

class TestPatientMedicalRecord(FrappeTestCase):
def setUp(self):
frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 0)
frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1)
frappe.db.set_single_value("Healthcare Settings", "enable_free_follow_ups", 0)
frappe.db.set_single_value("Healthcare Settings", "automate_appointment_invoicing", 1)
make_pos_profile()

def test_medical_record(self):
Expand Down
Loading