diff --git a/healthcare/healthcare/doctype/abdm_request/__init__.py b/healthcare/healthcare/doctype/abdm_request/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/healthcare/healthcare/doctype/abdm_request/abdm_request.js b/healthcare/healthcare/doctype/abdm_request/abdm_request.js
new file mode 100644
index 0000000000..c071c50148
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_request/abdm_request.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2022, healthcare and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('ABDM Request', {
+ // refresh: function(frm) {
+
+ // }
+});
diff --git a/healthcare/healthcare/doctype/abdm_request/abdm_request.json b/healthcare/healthcare/doctype/abdm_request/abdm_request.json
new file mode 100644
index 0000000000..ab90fa1f3f
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_request/abdm_request.json
@@ -0,0 +1,107 @@
+{
+ "actions": [],
+ "allow_rename": 1,
+ "creation": "2022-03-15 18:16:17.060579",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "request_name",
+ "request_date",
+ "column_break_3",
+ "status",
+ "url",
+ "section_break_4",
+ "request",
+ "traceback",
+ "column_break_6",
+ "response"
+ ],
+ "fields": [
+ {
+ "fieldname": "request_name",
+ "fieldtype": "Data",
+ "in_list_view": 1,
+ "label": "Request Name",
+ "read_only": 1
+ },
+ {
+ "default": "Now",
+ "fieldname": "request_date",
+ "fieldtype": "Datetime",
+ "label": "Request Date",
+ "read_only": 1
+ },
+ {
+ "fieldname": "status",
+ "fieldtype": "Select",
+ "in_list_view": 1,
+ "in_standard_filter": 1,
+ "label": "Status",
+ "options": "Requested\nGranted\nRevoked\nExpired\nDenied",
+ "read_only": 1
+ },
+ {
+ "fieldname": "section_break_4",
+ "fieldtype": "Section Break"
+ },
+ {
+ "fieldname": "request",
+ "fieldtype": "Code",
+ "label": "Request",
+ "read_only": 1
+ },
+ {
+ "fieldname": "column_break_6",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "response",
+ "fieldtype": "Code",
+ "label": "Response",
+ "read_only": 1
+ },
+ {
+ "fieldname": "column_break_3",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "url",
+ "fieldtype": "Data",
+ "label": "URL"
+ },
+ {
+ "fieldname": "traceback",
+ "fieldtype": "Code",
+ "label": "Traceback",
+ "read_only": 1
+ }
+ ],
+ "in_create": 1,
+ "index_web_pages_for_search": 1,
+ "links": [],
+ "modified": "2022-03-24 11:11:01.555036",
+ "modified_by": "Administrator",
+ "module": "Healthcare",
+ "name": "ABDM Request",
+ "owner": "Administrator",
+ "permissions": [
+ {
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "System Manager",
+ "share": 1,
+ "write": 1
+ }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "states": [],
+ "track_changes": 1,
+ "track_seen": 1
+}
\ No newline at end of file
diff --git a/healthcare/healthcare/doctype/abdm_request/abdm_request.py b/healthcare/healthcare/doctype/abdm_request/abdm_request.py
new file mode 100644
index 0000000000..36cf999d95
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_request/abdm_request.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2022, healthcare and contributors
+# For license information, please see license.txt
+
+# import frappe
+from frappe.model.document import Document
+
+
+class ABDMRequest(Document):
+ pass
diff --git a/healthcare/healthcare/doctype/abdm_request/test_abdm_request.py b/healthcare/healthcare/doctype/abdm_request/test_abdm_request.py
new file mode 100644
index 0000000000..3bd4bc5cc8
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_request/test_abdm_request.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2022, healthcare and Contributors
+# See license.txt
+
+# import frappe
+import unittest
+
+
+class TestABDMRequest(unittest.TestCase):
+ pass
diff --git a/healthcare/healthcare/doctype/abdm_settings/__init__.py b/healthcare/healthcare/doctype/abdm_settings/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/healthcare/healthcare/doctype/abdm_settings/abdm_settings.js b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.js
new file mode 100644
index 0000000000..9901933895
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2022, healthcare and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('ABDM Settings', {
+ // refresh: function(frm) {
+
+ // }
+});
diff --git a/healthcare/healthcare/doctype/abdm_settings/abdm_settings.json b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.json
new file mode 100644
index 0000000000..6dd37fbca2
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.json
@@ -0,0 +1,131 @@
+{
+ "actions": [],
+ "allow_rename": 1,
+ "autoname": "format:{gateway_name}-{company}",
+ "creation": "2022-03-14 20:32:55.651045",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "gateway_name",
+ "default",
+ "column_break_2",
+ "company",
+ "authorization_section",
+ "auth_base_url",
+ "column_break_7",
+ "client_id",
+ "client_secret",
+ "consent_section_section",
+ "patient_aadhaar_consent",
+ "health_id_service_section",
+ "health_id_base_url",
+ "consent_management_section",
+ "consent_base_url"
+ ],
+ "fields": [
+ {
+ "fieldname": "column_break_2",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "company",
+ "fieldtype": "Link",
+ "label": "Company",
+ "options": "Company"
+ },
+ {
+ "default": "0",
+ "fieldname": "default",
+ "fieldtype": "Check",
+ "label": "Default"
+ },
+ {
+ "fieldname": "client_id",
+ "fieldtype": "Data",
+ "label": "Client ID"
+ },
+ {
+ "fieldname": "client_secret",
+ "fieldtype": "Data",
+ "label": "Client Secret"
+ },
+ {
+ "fieldname": "auth_base_url",
+ "fieldtype": "Data",
+ "label": "Base URL"
+ },
+ {
+ "fieldname": "gateway_name",
+ "fieldtype": "Data",
+ "label": "Gateway Name"
+ },
+ {
+ "fieldname": "authorization_section",
+ "fieldtype": "Section Break",
+ "label": "Authorization"
+ },
+ {
+ "fieldname": "column_break_7",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "health_id_service_section",
+ "fieldtype": "Section Break",
+ "label": "Health ID Service"
+ },
+ {
+ "fieldname": "health_id_base_url",
+ "fieldtype": "Data",
+ "label": "Base URL"
+ },
+ {
+ "fieldname": "consent_management_section",
+ "fieldtype": "Section Break",
+ "label": "Consent Management"
+ },
+ {
+ "fieldname": "consent_base_url",
+ "fieldtype": "Data",
+ "label": "Base URL"
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "consent_section_section",
+ "fieldtype": "Section Break",
+ "label": "Consent Section"
+ },
+ {
+ "description": "Patient Consent To Use Aadhaar For ABHA Creation",
+ "fieldname": "patient_aadhaar_consent",
+ "fieldtype": "Link",
+ "label": "Patient Aadhaar Consent",
+ "options": "Terms and Conditions"
+ }
+ ],
+ "index_web_pages_for_search": 1,
+ "links": [],
+ "modified": "2022-04-18 14:59:24.279125",
+ "modified_by": "Administrator",
+ "module": "Healthcare",
+ "name": "ABDM Settings",
+ "naming_rule": "By fieldname",
+ "owner": "Administrator",
+ "permissions": [
+ {
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "System Manager",
+ "share": 1,
+ "write": 1
+ }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "states": []
+}
\ No newline at end of file
diff --git a/healthcare/healthcare/doctype/abdm_settings/abdm_settings.py b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.py
new file mode 100644
index 0000000000..9bdd8bc5b1
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_settings/abdm_settings.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2022, healthcare and contributors
+# For license information, please see license.txt
+
+# import frappe
+from frappe.model.document import Document
+
+
+class ABDMSettings(Document):
+ pass
diff --git a/healthcare/healthcare/doctype/abdm_settings/test_abdm_settings.py b/healthcare/healthcare/doctype/abdm_settings/test_abdm_settings.py
new file mode 100644
index 0000000000..1e81c1ac95
--- /dev/null
+++ b/healthcare/healthcare/doctype/abdm_settings/test_abdm_settings.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2022, healthcare and Contributors
+# See license.txt
+
+# import frappe
+import unittest
+
+
+class TestABDMSettings(unittest.TestCase):
+ pass
diff --git a/healthcare/healthcare/doctype/patient/patient.js b/healthcare/healthcare/doctype/patient/patient.js
index 9bef27b2e3..ab78fca03c 100644
--- a/healthcare/healthcare/doctype/patient/patient.js
+++ b/healthcare/healthcare/doctype/patient/patient.js
@@ -1,5 +1,6 @@
// Copyright (c) 2016, ESS LLP and contributors
// For license information, please see license.txt
+{% include 'healthcare/regional/india/abdm/js/patient.js' %}
frappe.ui.form.on('Patient', {
refresh: function (frm) {
diff --git a/healthcare/hooks.py b/healthcare/hooks.py
index 97a5c58363..830adc954c 100644
--- a/healthcare/hooks.py
+++ b/healthcare/hooks.py
@@ -111,9 +111,17 @@
"on_submit": "healthcare.healthcare.utils.manage_invoice_submit_cancel",
"on_cancel": "healthcare.healthcare.utils.manage_invoice_submit_cancel",
},
+ "Payment Entry": {
+ "on_submit": "healthcare.healthcare.doctype.insurance_claim.insurance_claim.validate_payment_entry_and_set_claim_fields",
+ "on_submit": "healthcare.healthcare.doctype.insurance_claim.insurance_claim.update_claim_paid_amount",
+ "on_cancel": "healthcare.healthcare.doctype.insurance_claim.insurance_claim.update_claim_paid_amount",
+ },
"Company": {
"after_insert": "healthcare.healthcare.utils.create_healthcare_service_unit_tree_root"
},
+ "Patient": {
+ "after_insert": "healthcare.regional.india.abdm.utils.set_consent_attachment_details"
+ },
}
scheduler_events = {
diff --git a/healthcare/modules.txt b/healthcare/modules.txt
index 915d8d2745..6be675a39a 100644
--- a/healthcare/modules.txt
+++ b/healthcare/modules.txt
@@ -1 +1 @@
-Healthcare
\ No newline at end of file
+Healthcare
diff --git a/healthcare/patches.txt b/healthcare/patches.txt
index e69de29bb2..1b72a66fd3 100644
--- a/healthcare/patches.txt
+++ b/healthcare/patches.txt
@@ -0,0 +1 @@
+healthcare.patches.v0_0.setup_abdm_custom_fields
\ No newline at end of file
diff --git a/healthcare/patches/v0_0/setup_abdm_custom_fields.py b/healthcare/patches/v0_0/setup_abdm_custom_fields.py
new file mode 100644
index 0000000000..69b1508567
--- /dev/null
+++ b/healthcare/patches/v0_0/setup_abdm_custom_fields.py
@@ -0,0 +1,11 @@
+import frappe
+
+
+def execute():
+ company = frappe.get_all("Company", filters={"country": "India"})
+ if not company:
+ return
+
+ from healthcare.regional.india.abdm.setup import setup
+
+ setup()
diff --git a/healthcare/regional/__init__.py b/healthcare/regional/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/healthcare/regional/india/__init__.py b/healthcare/regional/india/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/healthcare/regional/india/abdm/__init__.py b/healthcare/regional/india/abdm/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/healthcare/regional/india/abdm/abdm_config.py b/healthcare/regional/india/abdm/abdm_config.py
new file mode 100644
index 0000000000..622a441ccb
--- /dev/null
+++ b/healthcare/regional/india/abdm/abdm_config.py
@@ -0,0 +1,92 @@
+config = {
+ "authorization": {"method": "POST", "url": "/v0.5/sessions", "encrypted": False},
+ "exists_by_health_id": {
+ "method": "POST",
+ "url": "/v1/search/existsByHealthId",
+ "encrypted": False,
+ },
+ "verify_health_id": {"method": "POST", "url": "/v1/search/searchByHealthId", "encrypted": False},
+ "generate_aadhaar_otp": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/generateOtp",
+ "encrypted": False,
+ },
+ "generate_mobile_otp": {
+ "method": "POST",
+ "url": "/v2/registration/mobile/generateOtp",
+ "encrypted": False,
+ },
+ "verify_mobile_otp": {
+ "method": "POST",
+ "url": "/v2/registration/mobile/verifyOtp",
+ "encrypted": True,
+ },
+ "resend_mobile_otp": {
+ "method": "POST",
+ "url": "/v2/registration/mobile/resendOtp",
+ "encrypted": False,
+ },
+ "resend_aadhaar_otp": {
+ "method": "POST",
+ "url": "/v2/registration/aadhaar/resendAadhaarOtp",
+ "encrypted": False,
+ },
+ "create_abha_w_aadhaar": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/createHealthIdWithAadhaarOtp",
+ "encrypted": False,
+ },
+ "create_abha_w_mobile": {
+ "method": "POST",
+ "url": "/v2/registration/mobile/createHidViaMobile",
+ "encrypted": False,
+ },
+ "auth_cert": {"method": "GET", "url": "/v2/auth/cert", "encrypted": False},
+ "auth_init": {"method": "POST", "url": "/v2/auth/init", "encrypted": False},
+ "confirm_w_aadhaar_otp": {
+ "method": "POST",
+ "url": "/v2/auth/confirmWithAadhaarOtp",
+ "encrypted": True,
+ },
+ "confirm_w_mobile_otp": {
+ "method": "POST",
+ "url": "/v2/auth/confirmWithMobileOTP",
+ "encrypted": True,
+ },
+ "get_acc_info": {"method": "GET", "url": "/v2/account/profile", "encrypted": False},
+ "resend_aadhaar_otp": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/resendAadhaarOtp",
+ "encrypted": False,
+ },
+ "generate_aadhaar_mobile_otp": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/generateMobileOTP",
+ "encrypted": False,
+ },
+ "verify_aadhaar_mobile_otp": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/verifyMobileOTP",
+ "encrypted": False,
+ },
+ "verify_aadhaar_otp": {
+ "method": "POST",
+ "url": "/v1/registration/aadhaar/verifyOTP",
+ "encrypted": False,
+ },
+ "generate_mobile_otp_for_linking": {
+ "method": "POST",
+ "url": "/v2/document/generate/mobile/otp",
+ "encrypted": False,
+ },
+ "verify_mobile_otp_for_linking": {
+ "method": "POST",
+ "url": "/v2/document/verify/mobile/otp",
+ "encrypted": True,
+ },
+ "get_card": {"method": "GET", "url": "/v1/account/getPngCard", "encrypted": False},
+}
+
+
+def get_url(key):
+ return config.get(key)
diff --git a/healthcare/regional/india/abdm/js/patient.js b/healthcare/regional/india/abdm/js/patient.js
new file mode 100644
index 0000000000..a61ad261e1
--- /dev/null
+++ b/healthcare/regional/india/abdm/js/patient.js
@@ -0,0 +1,960 @@
+frappe.ui.form.on('Patient', {
+ refresh: function (frm) {
+ if (frappe.boot.sysdefaults.country == 'India') {
+ unhide_field(['abha_number', 'abha_address']);
+ if (!frm.doc.abha_address && !frm.doc.abha_number) {
+ frm.add_custom_button(__('Verify ABHA'), function () {
+ search_by_abha_address(frm)
+ }, 'ABDM');
+ }
+ if (frm.doc.abha_number) {
+ frm.add_custom_button(__('Verify ABHA Number'), function () {
+ verify_health_id(frm)
+ }, 'ABDM');
+ }
+ if (!(frm.doc.abha_address || frm.doc.abha_number)) {
+ frm.add_custom_button(__('Create ABHA'), function () {
+ create_abha(frm)
+ }, 'ABDM');
+ }
+ } else {
+ hide_field(['abha_number', 'abha_address']);
+ }
+ }
+});
+
+// search by ABHA address. If know ABHA number, can be verified
+let search_by_abha_address = function (frm) {
+ let dialog = new frappe.ui.Dialog({
+ title: 'Enter ABHA Address / Number',
+ fields: [
+ {
+ label: 'ABHA Address / Number',
+ fieldname: 'abha_address',
+ fieldtype: 'Data'
+ },
+ {
+ label: 'ABHA Number',
+ fieldname: 'abha_number',
+ fieldtype: 'Data',
+ hidden: 1
+ }
+ ],
+ secondary_action_label: 'Search ABHA',
+ secondary_action(values) {
+ if (!dialog.get_value('abha_address')) {
+ frappe.throw({
+ message: __(`ABHA Address is required to search`),
+ title: __("ABHA Addressent Required")
+ });
+ } else {
+ show_message(dialog, 'Searching...', 'black', '', 'abha_address')
+ frappe.call({
+ method: 'healthcare.regional.india.abdm.utils.abdm_request',
+ args: {
+ 'payload': {
+ "healthId": dialog.get_value('abha_address')
+ },
+ 'url_key': 'verify_health_id',
+ 'req_type': 'Health ID'
+ },
+ freeze: true,
+ freeze_message: __('
Searching...'),
+ callback: function (data) {
+ if (data.message['healthIdNumber']) {
+ show_message(dialog, 'Status:' + data.message['status'], 'green', '', 'abha_address')
+ dialog.set_values ({
+ 'abha_number': data.message['healthIdNumber']
+ })
+ dialog.hide();
+ if (data.message['healthIdNumber']) {
+ verify_health_id(frm, data.message['healthIdNumber'])
+ }
+ } else {
+ show_message(dialog, data.message.message, '#fa6969',
+ data.message.details[0]['message'], 'abha_address')
+ }
+ }
+ });
+ }
+ },
+ });
+ dialog.show();
+}
+
+
+let verify_health_id = function (frm, recieved_abha_number = '') {
+ let d = new frappe.ui.Dialog({
+ title: 'Verify ABHA',
+ fields: [
+ {
+ label: 'ABHA Number',
+ fieldname: 'healthid',
+ fieldtype: 'Data'
+ },
+ {
+ label: 'Authentication Method',
+ fieldname: 'auth_method',
+ fieldtype: 'Select',
+ options: ['AADHAAR_OTP', 'MOBILE_OTP'],
+ default: 'AADHAAR_OTP'
+ },
+ {
+ label: 'Mobile number to save patient',
+ fieldname: 'sb1',
+ fieldtype: 'Section Break',
+ collapsible: 1
+ },
+ {
+ label: 'Mobile',
+ fieldname: 'mobile',
+ fieldtype: 'Data',
+ },
+ {
+ fieldname: 'sb2',
+ fieldtype: 'Section Break'
+ },
+ {
+ fieldname: 'qr_data',
+ fieldtype: 'HTML'
+ },
+ {
+ fieldname: 'scanned_data',
+ fieldtype: 'Small Text',
+ hidden: 1
+ },
+ {
+ fieldname: 'abha_card',
+ fieldtype: 'Attach',
+ hidden: 1
+ }
+ ],
+ primary_action_label: 'Send Auth OTP',
+ primary_action(values) {
+ d.get_primary_btn().attr('disabled', true);
+ show_message(d, '', '', '', 'auth_method')
+ frappe.run_serially([
+ () =>frappe.db.get_value('Patient', {abha_number: d.get_value('healthid'), name: ['!=', frm.doc.name] }, ['name', 'abha_card'])
+ .then(r =>{
+ if (r.message.name) {
+ frappe.set_route("Form", "Patient", r.message.name);
+ if (r.message.abha_card) {
+ frappe.throw({
+ message: __(`{0}`,
+ [""]),
+ title: __("Patient already exist")
+ });
+ } else {
+ frappe.throw({
+ message: __(`{0}`,
+ ['' + r.message.name + '']),
+ title: __("Patient already exist")
+ });
+ }
+ }
+ }),
+ () => {show_message(d, 'Sending Auth OTP...', 'black', '', 'auth_method')
+ frappe.call({
+ method: 'healthcare.regional.india.abdm.utils.abdm_request',
+ args: {
+ 'payload': {
+ "authMethod": d.get_value('auth_method'),
+ "healthid": d.get_value('healthid')
+ },
+ 'url_key': 'auth_init',
+ 'req_type': 'Health ID'
+ },
+ freeze: true,
+ freeze_message: __('Generating OTP...'),
+ callback: function (r) {
+ let txn_id = r.message['txnId'];
+ if (txn_id) {
+ show_message(d, 'Successfully Sent OTP', 'green', '', 'auth_method')
+ verify_auth_otp(r, d)
+ } else {
+ if (r.message.message && r.message.details[0]['message']) {
+ show_message(d, r.message.message, 'red', r.message.details[0]['message'], 'auth_method')
+ }
+ frappe.show_alert({
+ message:__('OTP Generation Failed, Please try again later'),
+ indicator:'red'
+ }, 10);
+ d.get_primary_btn().attr('disabled', false);
+ }
+ }
+ });
+ }
+ ])
+ },
+ secondary_action_label: 'Save',
+ secondary_action(values) {
+ // save data from qr_scan/api fetch, save to form
+ var scanned_data = JSON.parse(d.get_value('scanned_data'));
+ set_data_to_form(frm, scanned_data, d, '')
+ frm.save();
+ d.hide();
+ }
+ });
+
+ // QR scanner field
+ setup_qr_scanner(d)
+ //verify btn
+ setup_send_otp_btn(d)
+ if (recieved_abha_number) {
+ d.set_values({
+ 'healthid': recieved_abha_number
+ });
+ }
+ d.get_secondary_btn().attr('disabled', true);
+ d.fields_dict['scanned_data'].df.onchange = () => {
+ if (d.get_value('scanned_data')) {
+ d.get_secondary_btn().attr('disabled', false);
+ }
+ }
+ d.fields_dict['healthid'].df.onchange = () => {
+ d.get_primary_btn().attr('disabled', false);
+ }
+
+ d.show();
+}
+
+// authorization otp verification
+let verify_auth_otp = function(r, d) {
+ let dialog = new frappe.ui.Dialog({
+ title: 'Authentication OTP',
+ fields: [
+ {
+ label: 'OTP',
+ fieldname: 'otp',
+ fieldtype: 'Data',
+ reqd: 1
+ }
+ ],
+ primary_action_label: 'Verify',
+ primary_action(values) {
+ // sending otp received to call 2 apis and receive health_data
+ show_message(d, 'Verifying...', 'black', '', 'auth_method')
+ frappe.call({
+ method: 'healthcare.regional.india.abdm.utils.get_health_data',
+ args: {
+ 'otp': dialog.get_value('otp'),
+ 'txnId': r.message['txnId'],
+ 'auth_method': d.get_value('auth_method')
+ },
+ freeze: true,
+ freeze_message: __(`
Verifying OTP...
+ Please note, this may take a while`),
+ callback: function (data) {
+ if (data.message) {
+ if (data.message[0] && data.message[0]['healthIdNumber']) {
+ d.get_primary_btn().attr('hidden', true);
+ if (!data.message[1] && !data.message[1]['file_url']) {
+ set_qr_scanned_data(d, data.message[0])
+ }
+ d.set_values({
+ 'scanned_data': JSON.stringify(data.message[0])
+ });
+ show_message(d, '', '', '', 'auth_method')
+ } else {
+ if (data.message[0].details[0]['message']) {
+ show_message(d, data.message[0].message, 'red', data.message[0].details[0]['message'], 'auth_method')
+ }
+ frappe.show_alert({
+ message:__('Failed to fetch health Data, Please try again later'),
+ indicator:'red'
+ }, 10);
+ }
+ if (data.message[1]) {
+ $(d.fields_dict.qr_data.$wrapper).html("")
+ d.set_values({
+ 'abha_card': data.message[1]
+ });
+ show_message(d, '', '', '', 'auth_method')
+ }
+ }
+ }
+ });
+ dialog.hide();
+ }
+ });
+ dialog.show();
+}
+
+
+let create_abha = function (frm) {
+ let d = new frappe.ui.Dialog({
+ title: 'Create ABHA',
+ fields: [
+ {
+ label: 'Enter Aadhaar',
+ fieldname: 'aadhaar',
+ fieldtype: 'Data',
+ mandatory: 1
+ },
+ {
+ label:'Patient Consent',
+ fieldname: 'patient_consent',
+ fieldtype: 'Section Break'
+ },
+ {
+ fieldname: 'patient_consent',
+ fieldtype: 'Link',
+ options: 'Terms and Conditions',
+ read_only: 0
+ },
+ {
+ fieldname: 'cb1',
+ fieldtype: 'Column Break',
+ },
+ {
+ label: 'Button',
+ fieldname: 'print_btn',
+ fieldtype: 'HTML'
+ },
+ {
+ fieldname: 'sb2',
+ fieldtype: 'Section Break',
+ hide_border: 1
+ },
+ {
+ fieldname: 'patient_consent_attach',
+ fieldtype: 'Attach',
+ description: `Please attach patient's signed consent for using
+ their Aadhaar for ABHA creation`
+ },
+ {
+ label: 'OR',
+ fieldname: 'or',
+ fieldtype: 'Heading',
+ hidden: 1
+ },
+ {
+ label: 'Received Consent',
+ fieldname: 'received_consent',
+ fieldtype: 'Check',
+ default: 0,
+ description: `Check this to confirm that patient has
+ provided consent to use Aadhaar for ABHA Registration`,
+ hidden: 1
+ },
+ ],
+ primary_action_label: 'Send OTP',
+ primary_action(values) {
+ if (!d.get_value('received_consent') && !d.get_value('patient_consent_attach')) {
+ frappe.throw({
+ message: __(`Patient Consent is required for ABHA creation`),
+ title: __("Consent Required")
+ });
+ } else {
+ create_abha_with_aadhaar(frm, d)
+ d.hide();
+ }
+ }
+ });
+
+ let print_button = d.fields_dict.print_btn.$wrapper;
+
+ print_button.html(
+ `
`
+ );
+
+ print_button.on('click', 'button', function() {
+ frappe.db.get_value('Terms and Conditions', d.get_value('patient_consent'), 'terms')
+ .then(r => {
+ let result = frappe.render_template(r.message.terms, {"doc" : {}})
+ frappe.render_pdf(result, {orientation:"Portrait"});
+ })
+ })
+
+ frappe.db.get_value('ABDM Settings', {
+ company: frappe.defaults.get_user_default("Company"),
+ default: 1
+ }, 'patient_aadhaar_consent')
+ .then(r => {
+ if (r.message.patient_aadhaar_consent) {
+ d.set_values({
+ 'patient_consent': r.message.patient_aadhaar_consent
+ });
+ }
+ })
+ d.show();
+}
+
+
+// to create html table
+let set_qr_scanned_data = function(d, scanned_data) {
+ let wrapper = $(d.fields_dict['qr_data'].wrapper).empty();
+ let dob = '';
+ if (scanned_data['dob']) {
+ dob = scanned_data['dob']
+ } else {
+ dob = `${scanned_data['dayOfBirth'] ? scanned_data['dayOfBirth'] : '-'} -
+ ${scanned_data['monthOfBirth'] ? scanned_data['monthOfBirth'] : '-'} -
+ ${scanned_data['yearOfBirth']}`;
+ }
+
+ let qr_table = $(`
Name | +${scanned_data['name']} | +
Gender | +${scanned_data['gender'] || '-'} | +
Mobile | +${scanned_data['mobile'] || '-'} | +
DOB | +${dob} | +
ABHA Address | +${scanned_data['healthId'] || scanned_data['hid'] || '-'} | +