Skip to content

Commit

Permalink
Merge pull request #1793 from coronasafe/hfr_service_registration
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg authored Dec 29, 2023
2 parents 5360702 + e6de51b commit 1233794
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
4 changes: 4 additions & 0 deletions aws/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
"name": "HEALTH_SERVICE_API_URL",
"value": "https://healthidsbx.abdm.gov.in/api"
},
{
"name": "ABDM_FACILITY_URL",
"value": "https://facilitysbx.abdm.gov.in"
},
{
"name": "X_CM_ID",
"value": "sbx"
Expand Down
4 changes: 4 additions & 0 deletions aws/celery.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
"name": "HEALTH_SERVICE_API_URL",
"value": "https://healthidsbx.abdm.gov.in/api"
},
{
"name": "ABDM_FACILITY_URL",
"value": "https://facilitysbx.abdm.gov.in"
},
{
"name": "X_CM_ID",
"value": "sbx"
Expand Down
44 changes: 30 additions & 14 deletions care/abdm/api/viewsets/health_facility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from celery import shared_task
from django.conf import settings
from dry_rest_permissions.generics import DRYPermissions
from rest_framework.decorators import action
from rest_framework.mixins import (
Expand All @@ -13,7 +14,7 @@

from care.abdm.api.serializers.health_facility import HealthFacilitySerializer
from care.abdm.models import HealthFacility
from care.abdm.utils.api_call import Bridge
from care.abdm.utils.api_call import Facility
from care.utils.queryset.facility import get_facility_queryset


Expand All @@ -24,27 +25,39 @@ def register_health_facility_as_service(facility_external_id):
).first()

if not health_facility:
return False
return [False, "Health Facility Not Found"]

if health_facility.registered:
return True
return [True, None]

response = Bridge().add_update_service(
response = Facility().add_update_service(
{
"id": health_facility.hf_id,
"name": health_facility.facility.name,
"type": "HIP",
"active": True,
"alias": ["CARE_HIP"],
"facilityId": health_facility.hf_id,
"facilityName": health_facility.facility.name,
"HRP": [
{
"bridgeId": settings.ABDM_CLIENT_ID,
"hipName": health_facility.facility.name,
"type": "HIP",
"active": True,
"alias": ["CARE_HIP"],
}
],
}
)

if response.status_code == 200:
health_facility.registered = True
health_facility.save()
return True
data = response.json()[0]

return False
if "error" in data:
return [False, data["error"]["message"]]

if "servicesLinked" in data:
health_facility.registered = True
health_facility.save()
return [True, None]

return [False, None]


class HealthFacilityViewSet(
Expand All @@ -67,7 +80,10 @@ def get_queryset(self):

@action(detail=True, methods=["POST"])
def register_service(self, request, facility__external_id):
registered = register_health_facility_as_service(facility__external_id)
[registered, error] = register_health_facility_as_service(facility__external_id)

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

return Response({"registered": registered})

Expand Down
13 changes: 13 additions & 0 deletions care/abdm/utils/api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ABDM_GATEWAY_URL = GATEWAY_API_URL + "/gateway"
ABDM_TOKEN_URL = ABDM_GATEWAY_URL + "/v0.5/sessions"
ABDM_TOKEN_CACHE_KEY = "abdm_token"
ABDM_FACILITY_URL = settings.ABDM_FACILITY_URL

# TODO: Exception handling for all api calls, need to gracefully handle known exceptions

Expand All @@ -45,6 +46,8 @@ def __init__(self, gateway, token):
self.url = ABDM_GATEWAY_URL
elif gateway == "abdm_devservice":
self.url = ABDM_DEVSERVICE_URL
elif gateway == "facility":
self.url = ABDM_FACILITY_URL
else:
self.url = GATEWAY_API_URL
self.token = token
Expand Down Expand Up @@ -790,3 +793,13 @@ def add_update_service(self, data):
path = "/v1/bridges/addUpdateServices"
response = self.api.post(path, data, method="PUT")
return response


class Facility:
def __init__(self) -> None:
self.api = APIGateway("facility", None)

def add_update_service(self, data):
path = "/v1/bridges/MutipleHRPAddUpdateServices"
response = self.api.post(path, data, method="POST")
return response
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
HEALTH_SERVICE_API_URL = env(
"HEALTH_SERVICE_API_URL", default="https://healthidsbx.abdm.gov.in/api"
)
ABDM_FACILITY_URL = env("ABDM_FACILITY_URL", default="https://facilitysbx.abdm.gov.in")
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 1233794

Please sign in to comment.