def test_patient_contact(self): frappe.db.sql( """delete from `tabPatient` where name like '_Test Patient%'""") frappe.db.sql( """delete from `tabCustomer` where name like '_Test Patient%'""") frappe.db.sql( """delete from `tabContact` where name like'_Test Patient%'""") frappe.db.sql( """delete from `tabDynamic Link` where parent like '_Test Patient%'""" ) patient = create_patient(patient_name='_Test Patient Contact', email='*****@*****.**', mobile='+91 0000000001') customer = frappe.db.get_value('Patient', patient, 'customer') self.assertTrue(customer) self.assertTrue( frappe.db.exists( 'Dynamic Link', { 'parenttype': 'Contact', 'link_doctype': 'Patient', 'link_name': patient })) self.assertTrue( frappe.db.exists( 'Dynamic Link', { 'parenttype': 'Contact', 'link_doctype': 'Customer', 'link_name': customer })) # a second patient linking with same customer new_patient = create_patient(email='*****@*****.**', mobile='+91 0000000009', customer=customer) self.assertTrue( frappe.db.exists( 'Dynamic Link', { 'parenttype': 'Contact', 'link_doctype': 'Patient', 'link_name': new_patient })) self.assertTrue( frappe.db.exists( 'Dynamic Link', { 'parenttype': 'Contact', 'link_doctype': 'Customer', 'link_name': customer }))
def test_patient_contact(self): frappe.db.sql( """delete from `tabPatient` where name like '_Test Patient%'""") frappe.db.sql( """delete from `tabCustomer` where name like '_Test Patient%'""") frappe.db.sql( """delete from `tabContact` where name like'_Test Patient%'""") frappe.db.sql( """delete from `tabDynamic Link` where parent like '_Test Patient%'""" ) patient = create_patient(patient_name="_Test Patient Contact", email="*****@*****.**", mobile="+91 0000000001") customer = frappe.db.get_value("Patient", patient, "customer") self.assertTrue(customer) self.assertTrue( frappe.db.exists( "Dynamic Link", { "parenttype": "Contact", "link_doctype": "Patient", "link_name": patient })) self.assertTrue( frappe.db.exists( "Dynamic Link", { "parenttype": "Contact", "link_doctype": "Customer", "link_name": customer })) # a second patient linking with same customer new_patient = create_patient(email="*****@*****.**", mobile="+91 0000000009", customer=customer) self.assertTrue( frappe.db.exists( "Dynamic Link", { "parenttype": "Contact", "link_doctype": "Patient", "link_name": new_patient })) self.assertTrue( frappe.db.exists( "Dynamic Link", { "parenttype": "Contact", "link_doctype": "Customer", "link_name": customer }))
def create_sales_invoice(): patient = create_patient() medical_department = create_medical_department() insulin_resistance_template = create_lab_test_template() blood_test_template = create_blood_test_template(medical_department) sales_invoice = frappe.new_doc('Sales Invoice') sales_invoice.patient = patient sales_invoice.customer = frappe.db.get_value('Patient', patient, 'customer') sales_invoice.due_date = getdate() sales_invoice.company = '_Test Company' sales_invoice.debit_to = get_receivable_account('_Test Company') tests = [insulin_resistance_template, blood_test_template] for entry in tests: sales_invoice.append( 'items', { 'item_code': entry.item, 'item_name': entry.lab_test_name, 'description': entry.lab_test_description, 'qty': 1, 'uom': 'Nos', 'conversion_factor': 1, 'income_account': get_income_account(None, '_Test Company'), 'rate': entry.lab_test_rate, 'amount': entry.lab_test_rate }) sales_invoice.set_missing_values() sales_invoice.submit() return sales_invoice
def test_patient_user(self): frappe.db.sql( """delete from `tabUser` where email='*****@*****.**'""" ) frappe.db.sql( """delete from `tabDynamic Link` where parent like '_Test Patient%'""" ) frappe.db.sql( """delete from `tabPatient` where name like '_Test Patient%'""") patient = create_patient( patient_name="_Test Patient User", email="*****@*****.**", mobile="+91 0000000009", create_user=True, ) user = frappe.db.get_value("Patient", patient, "user_id") self.assertTrue(frappe.db.exists("User", user)) new_patient = frappe.get_doc({ "doctype": "Patient", "first_name": "_Test Patient Duplicate User", "sex": "Male", "email": "*****@*****.**", "mobile": "+91 0000000009", "invite_user": 1, }) self.assertRaises(frappe.exceptions.DuplicateEntryError, new_patient.insert)
def test_patient_user(self): frappe.db.sql( """delete from `tabUser` where email='*****@*****.**'""" ) frappe.db.sql( """delete from `tabDynamic Link` where parent like '_Test Patient%'""" ) frappe.db.sql( """delete from `tabPatient` where name like '_Test Patient%'""") patient = create_patient(patient_name='_Test Patient User', email='*****@*****.**', mobile='+91 0000000009', create_user=True) user = frappe.db.get_value('Patient', patient, 'user_id') self.assertTrue(frappe.db.exists('User', user)) new_patient = frappe.get_doc({ 'doctype': 'Patient', 'first_name': '_Test Patient Duplicate User', 'sex': 'Male', 'email': '*****@*****.**', 'mobile': '+91 0000000009', 'invite_user': 1 }) self.assertRaises(frappe.exceptions.DuplicateEntryError, new_patient.insert)
def create_lab_test(lab_template): patient = create_patient() lab_test = frappe.new_doc('Lab Test') lab_test.template = lab_template.name lab_test.patient = patient lab_test.patient_sex = 'Female' lab_test.save() return lab_test
def create_therapy_plan(): patient = create_patient() therapy_type = create_therapy_type() plan = frappe.new_doc('Therapy Plan') plan.patient = patient plan.start_date = getdate() plan.append('therapy_plan_details', { 'therapy_type': therapy_type.name, 'no_of_sessions': 2 }) plan.save() return plan
def test_therapy_plan_from_template(self): patient = create_patient() template = create_therapy_plan_template() # check linked item self.assertTrue(frappe.db.exists('Therapy Plan Template', {'linked_item': 'Complete Rehab'})) plan = create_therapy_plan(template) # invoice si = make_sales_invoice(plan.name, patient, '_Test Company', template) si.save() therapy_plan_template_amt = frappe.db.get_value('Therapy Plan Template', template, 'total_amount') self.assertEqual(si.items[0].amount, therapy_plan_template_amt)
def test_custom_doctype_medical_record(self): # tests for medical record creation of standard doctypes in test_patient_medical_record.py patient = create_patient() doc = create_doc(patient) # check for medical record medical_rec = frappe.db.exists("Patient Medical Record", { "status": "Open", "reference_name": doc.name}) self.assertTrue(medical_rec) medical_rec = frappe.get_doc("Patient Medical Record", medical_rec) expected_subject = "<b>Date: </b>{0}<br><b>Rating: </b>3<br><b>Feedback: </b>Test Patient History Settings<br>".format( frappe.utils.format_date(getdate())) self.assertEqual(medical_rec.subject, expected_subject) self.assertEqual(medical_rec.patient, patient) self.assertEqual(medical_rec.communication_date, getdate())
def create_therapy_plan(template=None): patient = create_patient() therapy_type = create_therapy_type() plan = frappe.new_doc('Therapy Plan') plan.patient = patient plan.start_date = getdate() if template: plan.therapy_plan_template = template plan = plan.set_therapy_details_from_template() else: plan.append('therapy_plan_details', { 'therapy_type': therapy_type.name, 'no_of_sessions': 2 }) plan.save() return plan
def test_patient_registration(self): frappe.db.sql("""delete from `tabPatient`""") settings = frappe.get_single('Healthcare Settings') settings.collect_registration_fee = 1 settings.registration_fee = 500 settings.save() patient = create_patient() patient = frappe.get_doc('Patient', patient) self.assertEqual(patient.status, 'Disabled') # check sales invoice and patient status result = patient.invoice_patient_registration() self.assertTrue(frappe.db.exists('Sales Invoice', result.get('invoice'))) self.assertTrue(patient.status, 'Active') settings.collect_registration_fee = 0 settings.save()
def test_patient_registration(self): frappe.db.sql("""delete from `tabPatient`""") settings = frappe.get_single("Healthcare Settings") settings.collect_registration_fee = 1 settings.registration_fee = 500 settings.save() patient = create_patient() patient = frappe.get_doc("Patient", patient) self.assertEqual(patient.status, "Disabled") # check sales invoice and patient status result = patient.invoice_patient_registration() self.assertTrue( frappe.db.exists("Sales Invoice", result.get("invoice"))) self.assertTrue(patient.status, "Active") settings.collect_registration_fee = 0 settings.save()
def create_patient_encounter(): patient = create_patient() medical_department = create_medical_department() insulin_resistance_template = create_lab_test_template() blood_test_template = create_blood_test_template(medical_department) patient_encounter = frappe.new_doc('Patient Encounter') patient_encounter.patient = patient patient_encounter.practitioner = create_practitioner() patient_encounter.encounter_date = getdate() patient_encounter.encounter_time = nowtime() tests = [insulin_resistance_template, blood_test_template] for entry in tests: patient_encounter.append('lab_test_prescription', { 'lab_test_code': entry.item, 'lab_test_name': entry.lab_test_name }) patient_encounter.submit() return patient_encounter
def create_sales_invoice(): patient = create_patient() medical_department = create_medical_department() insulin_resistance_template = create_lab_test_template() blood_test_template = create_blood_test_template(medical_department) sales_invoice = frappe.new_doc("Sales Invoice") sales_invoice.patient = patient sales_invoice.customer = frappe.db.get_value("Patient", patient, "customer") sales_invoice.due_date = getdate() sales_invoice.company = "_Test Company" sales_invoice.currency = "INR" sales_invoice.debit_to = get_receivable_account("_Test Company") tests = [insulin_resistance_template, blood_test_template] for entry in tests: sales_invoice.append( "items", { "item_code": entry.item, "item_name": entry.lab_test_name, "description": entry.lab_test_description, "qty": 1, "uom": "Nos", "conversion_factor": 1, "income_account": get_income_account(None, "_Test Company"), "rate": entry.lab_test_rate, "amount": entry.lab_test_rate, }, ) sales_invoice.set_missing_values() sales_invoice.submit() return sales_invoice
def test_customer_created(self): frappe.db.sql("""delete from `tabPatient`""") frappe.db.set_value('Healthcare Settings', None, 'link_customer_to_patient', 1) patient = create_patient() self.assertTrue(frappe.db.get_value('Patient', patient, 'customer'))
def test_customer_created(self): frappe.db.sql("""delete from `tabPatient`""") frappe.db.set_value("Healthcare Settings", None, "link_customer_to_patient", 1) patient = create_patient() self.assertTrue(frappe.db.get_value("Patient", patient, "customer"))