Skip to content

Commit

Permalink
Add custom prefix and suffix to hip name (#1861)
Browse files Browse the repository at this point in the history
* add postfix and prefix and clean hip name before service registration

* set register to true if the  facility is already associated with the bridge id

* renamed postfix to suffix
  • Loading branch information
khavinshankar authored Feb 10, 2024
1 parent b26c849 commit 307a7c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions care/abdm/api/viewsets/health_facility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from celery import shared_task
from django.conf import settings
from dry_rest_permissions.generics import DRYPermissions
Expand Down Expand Up @@ -30,14 +32,17 @@ def register_health_facility_as_service(facility_external_id):
if health_facility.registered:
return [True, None]

clean_facility_name = re.sub(r"[^A-Za-z0-9 ]+", " ", health_facility.facility.name)
clean_facility_name = re.sub(r"\s+", " ", clean_facility_name).strip()
hip_name = settings.HIP_NAME_PREFIX + clean_facility_name + settings.HIP_NAME_SUFFIX
response = Facility().add_update_service(
{
"facilityId": health_facility.hf_id,
"facilityName": health_facility.facility.name,
"facilityName": hip_name,
"HRP": [
{
"bridgeId": settings.ABDM_CLIENT_ID,
"hipName": health_facility.facility.name,
"hipName": hip_name,
"type": "HIP",
"active": True,
"alias": ["CARE_HIP"],
Expand All @@ -50,7 +55,19 @@ def register_health_facility_as_service(facility_external_id):
data = response.json()[0]

if "error" in data:
return [False, data["error"]["message"]]
if (
data["error"].get("code") == "2500"
and settings.ABDM_CLIENT_ID in data["error"].get("message")
and "already associated" in data["error"].get("message")
):
health_facility.registered = True
health_facility.save()
return [True, None]

return [
False,
data["error"].get("message", "Error while registering HIP as service"),
]

if "servicesLinked" in data:
health_facility.registered = True
Expand Down Expand Up @@ -83,7 +100,7 @@ def register_service(self, request, facility__external_id):
[registered, error] = register_health_facility_as_service(facility__external_id)

if error:
return Response({"error": error}, status=400)
return Response({"detail": error}, status=400)

return Response({"registered": registered})

Expand Down
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@
"HEALTH_SERVICE_API_URL", default="https://healthidsbx.abdm.gov.in/api"
)
ABDM_FACILITY_URL = env("ABDM_FACILITY_URL", default="https://facilitysbx.abdm.gov.in")
HIP_NAME_PREFIX = env("HIP_NAME_PREFIX", default="")
HIP_NAME_SUFFIX = env("HIP_NAME_SUFFIX", default="")
ABDM_USERNAME = env("ABDM_USERNAME", default="abdm_user_internal")
X_CM_ID = env("X_CM_ID", default="sbx")
FIDELIUS_URL = env("FIDELIUS_URL", default="http://fidelius:8090")
Expand Down

0 comments on commit 307a7c5

Please sign in to comment.