Skip to content

Commit

Permalink
fix: Primary btn disables on error message, Route to patient form if …
Browse files Browse the repository at this point in the history
…already exist, Rename Sandbox_config to abdm_config, clean up utils
  • Loading branch information
akashkrishna619 authored and akashkrishna619 committed Aug 25, 2022
1 parent 66b1de1 commit 11bdba0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions healthcare/regional/india/abdm/js/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ let verify_health_id = function (frm, recieved_abha_number = '') {
() =>frappe.db.get_value('Patient', {abha_number: d.get_value('healthid'), name: ['!=', frm.doc.name] }, 'name')
.then(r =>{
if (r.message.name) {
frappe.set_route("Form", "Patient", r.message.name);
frappe.throw({
message: __(`Patient with ABHA number <b>${d.get_value('healthid')}</b> already exists {0}`,
['<a href="/app/patient/'+r.message.name+'">' + r.message.name + '</a>']),
Expand Down Expand Up @@ -195,6 +196,7 @@ let verify_health_id = function (frm, recieved_abha_number = '') {
message:__('OTP Generation Failed, Please try again later'),
indicator:'red'
}, 10);
d.get_primary_btn().attr('disabled', false);
}
}
});
Expand Down Expand Up @@ -225,6 +227,9 @@ let verify_health_id = function (frm, recieved_abha_number = '') {
d.get_secondary_btn().attr('disabled', false);
}
}
d.fields_dict['healthid'].df.onchange = () => {
d.get_primary_btn().attr('disabled', false);
}

d.show();
}
Expand Down Expand Up @@ -566,6 +571,7 @@ let create_abha_with_aadhaar = function(frm, d) {
name: ['!=', frm.doc.name] }, 'name')
.then(r =>{
if (r.message.name) {
frappe.set_route("Form", "Patient", r.message.name);
frappe.throw({
message: __(`Patient with ABHA number
<b>${data.message['healthIdNumber']}</b> already exists {0}`,
Expand Down
31 changes: 21 additions & 10 deletions healthcare/regional/india/abdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import frappe
import requests
from healthcare.regional.india.abdm.sandbox_config import get_url
from healthcare.regional.india.abdm.abdm_config import get_url


@frappe.whitelist()
def get_authorization_token():
client_id, client_secret, base_url = frappe.db.get_value(
'ABDM Integration',
{'company': frappe.defaults.get_user_default("Company"), 'default': 1},
{
'company': frappe.defaults.get_user_default("Company"),
'default': 1
},
['client_id', 'client_secret', 'auth_base_url']
)

Expand Down Expand Up @@ -38,8 +41,8 @@ def get_authorization_token():
data=json.dumps(payload)
)
response.raise_for_status()
req.response = json.dumps(response.json(), indent=4)
response = json.loads(json.dumps(response.json()))
response = response.json()
req.response = json.dumps(response, indent=4)
req.status = 'Granted'
req.insert(ignore_permissions=True)
return response.get('accessToken'), response.get('tokenType')
Expand All @@ -63,18 +66,23 @@ def abdm_request(payload, url_key, req_type, rec_headers=None, to_be_enc=None):

base_url = frappe.db.get_value(
'ABDM Integration',
{'company': frappe.defaults.get_user_default("Company"), 'default': 1},
{
'company': frappe.defaults.get_user_default("Company"),
'default': 1
},
[url_type]
)
if not base_url:
frappe.throw(title='Not Configured',
msg='Base URL not configured in ABDM Integration!')
frappe.throw(
title='Not Configured',
msg='Base URL not configured in ABDM Integration!'
)

config = get_url(url_key)
base_url = base_url.rstrip('/') if base_url.endswith('/') else base_url
base_url = base_url.rstrip('/')
url = base_url + config.get('url')

# Check the sandbox_config, if the data need to be encypted, encrypts message
# Check the abdm_config, if the data need to be encypted, encrypts message
# Build payload with encrypted message
if config.get('encrypted'):
message = payload.get('to_encrypt')
Expand Down Expand Up @@ -134,7 +142,10 @@ def abdm_request(payload, url_key, req_type, rec_headers=None, to_be_enc=None):
def get_encrypted_message(message):
base_url = frappe.db.get_value(
'ABDM Integration',
{'company': frappe.defaults.get_user_default("Company"), 'default': 1},
{
'company': frappe.defaults.get_user_default("Company"),
'default': 1
},
['health_id_base_url']
)

Expand Down

0 comments on commit 11bdba0

Please sign in to comment.