Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production Release v24.38.0 #2459

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")

Check warning on line 25 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L25

Added line #L25 was not covered by tests

instance = self.queryset.filter(

Check warning on line 27 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L27

Added line #L27 was not covered by tests
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

Check warning on line 34 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L34

Added line #L34 was not covered by tests

self.check_object_permissions(self.request, instance)

Check warning on line 36 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L36

Added line #L36 was not covered by tests

return instance

Check warning on line 38 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L38

Added line #L38 was not covered by tests

@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)

Check warning on line 45 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L42-L45

Added lines #L42 - L45 were not covered by tests

@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)

Check warning on line 52 in care/abdm/api/viewsets/abha_number.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/abha_number.py#L49-L52

Added lines #L49 - L52 were not covered by tests
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 @@
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"])

Check warning on line 28 in care/abdm/api/viewsets/auth.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/auth.py#L28

Added line #L28 was not covered by tests

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

Expand Down Expand Up @@ -337,38 +327,26 @@
}
)

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 @@
)
)
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 @@

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)

Check warning on line 72 in care/abdm/api/viewsets/consent.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/consent.py#L72

Added line #L72 was not covered by tests
if response.status_code != 202:
return Response(response.json(), status=response.status_code)

Check warning on line 74 in care/abdm/api/viewsets/consent.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/consent.py#L74

Added line #L74 was not covered by tests

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 @@
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)

Check warning on line 145 in care/abdm/api/viewsets/health_information.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/health_information.py#L145

Added line #L145 was not covered by tests

return Response(status=status.HTTP_202_ACCEPTED)
Loading
Loading