Skip to content

Commit

Permalink
Merge pull request #2459 from ohcnetwork/staging
Browse files Browse the repository at this point in the history
Production Release v24.38.0
  • Loading branch information
sainak authored Sep 17, 2024
2 parents da84617 + 1a3c4d3 commit 9343820
Show file tree
Hide file tree
Showing 26 changed files with 8,732 additions and 8,694 deletions.
4 changes: 4 additions & 0 deletions aws/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"name": "CORS_ALLOWED_ORIGINS",
"value": "[\"https://care.coronasafe.in\", \"https://careapi.coronasafe.in\", \"https://care.ohc.network\", \"https://careapi.ohc.network\", \"https://status.10bedicu.org\", \"http://localhost:4000\"]"
},
{
"name": "CORS_ALLOWED_ORIGIN_REGEXES",
"value": "[\"^https://[a-zA-Z0-9-]+--care-ohc\\\\.netlify\\\\.app$\"]"
},
{
"name": "CURRENT_DOMAIN",
"value": "https://care.ohc.network"
Expand Down
9 changes: 0 additions & 9 deletions care/abdm/api/serializers/abha.py

This file was deleted.

20 changes: 20 additions & 0 deletions care/abdm/api/serializers/abha_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ModelSerializer
from rest_framework import serializers

from care.abdm.models import AbhaNumber
from care.facility.api.serializers.patient import PatientDetailSerializer
from care.facility.models import PatientRegistration
from care.utils.serializer.external_id_field import ExternalIdSerializerField


class AbhaNumberSerializer(serializers.ModelSerializer):
id = serializers.CharField(source="external_id", read_only=True)
patient = ExternalIdSerializerField(
queryset=PatientRegistration.objects.all(), required=False, allow_null=True
)
patient_object = PatientDetailSerializer(source="patient", read_only=True)
new = serializers.BooleanField(read_only=True)

class Meta:
model = AbhaNumber
exclude = ("deleted", "access_token", "refresh_token", "txn_id")
10 changes: 0 additions & 10 deletions care/abdm/api/serializers/abhanumber.py

This file was deleted.

2 changes: 1 addition & 1 deletion care/abdm/api/serializers/consent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from care.abdm.api.serializers.abhanumber import AbhaNumberSerializer
from care.abdm.api.serializers.abha_number import AbhaNumberSerializer
from care.abdm.models.consent import ConsentArtefact, ConsentRequest
from care.users.api.serializers.user import UserBaseMinimumSerializer

Expand Down
5 changes: 5 additions & 0 deletions care/abdm/api/serializers/healthid.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ class CreateHealthIdSerializer(Serializer):
healthId = CharField(max_length=64, min_length=1, required=False)
txnId = CharField(max_length=64, min_length=1, required=True)
patientId = UUIDField(required=False)


class LinkPatientSerializer(Serializer):
abha_number = UUIDField(required=True)
patient = UUIDField(required=True)
38 changes: 0 additions & 38 deletions care/abdm/api/viewsets/abha.py

This file was deleted.

52 changes: 52 additions & 0 deletions care/abdm/api/viewsets/abha_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from django.db.models import Q
from django.http import Http404
from rest_framework.decorators import action
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from care.abdm.api.serializers.abha_number import AbhaNumberSerializer
from care.abdm.models import AbhaNumber
from care.abdm.utils.api_call import HealthIdGateway
from care.utils.queryset.patient import get_patient_queryset


class AbhaNumberViewSet(
GenericViewSet,
RetrieveModelMixin,
):
serializer_class = AbhaNumberSerializer
model = AbhaNumber
queryset = AbhaNumber.objects.all()
permission_classes = (IsAuthenticated,)

def get_object(self):
id = self.kwargs.get("pk")

instance = self.queryset.filter(
Q(abha_number=id) | Q(health_id=id) | Q(patient__external_id=id)
).first()

if not instance or not get_patient_queryset(self.request.user).contains(
instance.patient
):
raise Http404

self.check_object_permissions(self.request, instance)

return instance

@action(detail=True, methods=["GET"])
def qr_code(self, request, *args, **kwargs):
obj = self.get_object()
serializer = self.get_serializer(obj)
response = HealthIdGateway().get_qr_code(serializer.data)
return Response(response)

@action(detail=True, methods=["GET"])
def profile(self, request, *args, **kwargs):
obj = self.get_object()
serializer = self.get_serializer(obj)
response = HealthIdGateway().get_profile(serializer.data)
return Response(response)
62 changes: 20 additions & 42 deletions care/abdm/api/viewsets/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,7 @@ class OnFetchView(GenericAPIView):
def post(self, request, *args, **kwargs):
data = request.data

try:
AbdmGateway().init(data["resp"]["requestId"])
except Exception as e:
logger.warning(
f"Error: OnFetchView::post failed while initialising ABDM Gateway, Reason: {e}",
exc_info=True,
)
return Response(
{"detail": "Error: Initialising ABDM Gateway failed."},
status=status.HTTP_400_BAD_REQUEST,
)
AbdmGateway().init(data["resp"]["requestId"])

return Response({}, status=status.HTTP_202_ACCEPTED)

Expand Down Expand Up @@ -337,38 +327,26 @@ def post(self, request, *args, **kwargs):
}
)

try:
AbdmGateway().data_notify(
{
"health_id": consent["notification"]["consentDetail"]["patient"][
"id"
],
"consent_id": data["hiRequest"]["consent"]["id"],
"transaction_id": data["transactionId"],
"session_status": "TRANSFERRED"
AbdmGateway().data_notify(
{
"health_id": consent["notification"]["consentDetail"]["patient"]["id"],
"consent_id": data["hiRequest"]["consent"]["id"],
"transaction_id": data["transactionId"],
"session_status": (
"TRANSFERRED"
if data_transfer_response
and data_transfer_response.status_code == 202
else "FAILED",
"care_contexts": list(
map(
lambda context: {"id": context["careContextReference"]},
consent["notification"]["consentDetail"]["careContexts"][
:-2:-1
],
)
),
}
)
except Exception as e:
logger.warning(
f"Error: RequestDataView::post failed to notify (health-information/notify). Reason: {e}",
exc_info=True,
)
return Response(
{
"detail": "Failed to notify (health-information/notify)",
},
status=status.HTTP_400_BAD_REQUEST,
)
else "FAILED"
),
"care_contexts": list(
map(
lambda context: {"id": context["careContextReference"]},
consent["notification"]["consentDetail"]["careContexts"][
:-2:-1
],
)
),
}
)

return Response({}, status=status.HTTP_202_ACCEPTED)
22 changes: 5 additions & 17 deletions care/abdm/api/viewsets/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@


class ConsentRequestFilter(filters.FilterSet):
patient = filters.UUIDFilter(
field_name="patient_abha__patientregistration__external_id"
)
patient = filters.UUIDFilter(field_name="patient_abha__patient__external_id")
health_id = filters.CharFilter(field_name="patient_abha__health_id")
ordering = filters.OrderingFilter(
fields=(
Expand All @@ -33,7 +31,7 @@ class ConsentRequestFilter(filters.FilterSet):
)
)
facility = filters.UUIDFilter(
field_name="patient_abha__patientregistration__facility__external_id"
field_name="patient_abha__patient__facility__external_id"
)

class Meta:
Expand Down Expand Up @@ -71,19 +69,9 @@ def create(self, request):

consent = ConsentRequest(**serializer.validated_data, requester=request.user)

try:
response = Gateway().consent_requests__init(consent)
if response.status_code != 202:
return Response(response.json(), status=response.status_code)
except Exception as e:
logger.warning(
f"Error: ConsentViewSet::create failed to notify (consent_requests__init). Reason: {e}",
exc_info=True,
)
return Response(
{"detail": "Failed to initialize consent request"},
status=status.HTTP_400_BAD_REQUEST,
)
response = Gateway().consent_requests__init(consent)
if response.status_code != 202:
return Response(response.json(), status=response.status_code)

consent.save()
return Response(
Expand Down
12 changes: 1 addition & 11 deletions care/abdm/api/viewsets/health_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ def health_information__transfer(self, request):
file.upload_completed = True
file.save()

try:
Gateway().health_information__notify(artefact)
except Exception as e:
logger.warning(
f"Error: health_information__transfer::post failed to notify (health-information/notify). Reason: {e}",
exc_info=True,
)
return Response(
{"detail": "Failed to notify (health-information/notify)"},
status=status.HTTP_400_BAD_REQUEST,
)
Gateway().health_information__notify(artefact)

return Response(status=status.HTTP_202_ACCEPTED)
Loading

0 comments on commit 9343820

Please sign in to comment.