Skip to content

Commit

Permalink
fix ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Sep 12, 2023
1 parent aebaa5a commit 8a8a49f
Show file tree
Hide file tree
Showing 217 changed files with 3,688 additions and 2,822 deletions.
2 changes: 1 addition & 1 deletion care/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
]
],
)
Empty file.
1 change: 1 addition & 0 deletions care/abdm/api/serializers/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: N815
from rest_framework.serializers import CharField, IntegerField, Serializer


Expand Down
1 change: 1 addition & 0 deletions care/abdm/api/serializers/healthid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: N815
from rest_framework.serializers import CharField, Serializer, UUIDField


Expand Down
1 change: 1 addition & 0 deletions care/abdm/api/serializers/hip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: N815
from rest_framework.serializers import CharField, IntegerField, Serializer


Expand Down
Empty file.
2 changes: 1 addition & 1 deletion care/abdm/api/viewsets/abha.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AbhaViewSet(GenericViewSet):
def get_abha_object(self):
queryset = get_patient_queryset(self.request.user)
patient_obj = get_object_or_404(
queryset.filter(external_id=self.kwargs.get("patient_external_id"))
queryset.filter(external_id=self.kwargs.get("patient_external_id")),
)
return patient_obj.abha_number

Expand Down
92 changes: 46 additions & 46 deletions care/abdm/api/viewsets/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from datetime import datetime, timedelta
from datetime import timedelta

from django.core.cache import cache
from django.utils import timezone
from rest_framework import status
from rest_framework.generics import GenericAPIView, get_object_or_404
from rest_framework.permissions import IsAuthenticated
Expand Down Expand Up @@ -113,29 +114,28 @@ def post(self, request, *args, **kwargs):
"No matching records found, need more data",
status=status.HTTP_404_NOT_FOUND,
)
else:
for identifier in verified_identifiers:
if identifier["value"] is None:
continue

# if identifier["type"] == "MOBILE":
# matched_by.append(identifier["value"])
# mobile = identifier["value"].replace("+91", "").replace("-", "")
# patients = patients.filter(
# Q(phone_number=f"+91{mobile}") | Q(phone_number=mobile)
# )

if identifier["type"] == "NDHM_HEALTH_NUMBER":
matched_by.append(identifier["value"])
patients = patients.filter(
abha_number__abha_number=identifier["value"]
)

if identifier["type"] == "HEALTH_ID":
matched_by.append(identifier["value"])
patients = patients.filter(
abha_number__health_id=identifier["value"]
)
for identifier in verified_identifiers:
if identifier["value"] is None:
continue

# if identifier["type"] == "MOBILE":
# matched_by.append(identifier["value"])
# mobile = identifier["value"].replace("+91", "").replace("-", "")
# patients = patients.filter(
# Q(phone_number=f"+91{mobile}") | Q(phone_number=mobile)
# )

if identifier["type"] == "NDHM_HEALTH_NUMBER":
matched_by.append(identifier["value"])
patients = patients.filter(
abha_number__abha_number=identifier["value"],
)

if identifier["type"] == "HEALTH_ID":
matched_by.append(identifier["value"])
patients = patients.filter(
abha_number__health_id=identifier["value"],
)

# TODO: also filter by demographics
patient = patients.last()
Expand All @@ -159,10 +159,10 @@ def post(self, request, *args, **kwargs):
"name": f"Encounter: {str(consultation.created_date.date())}",
},
PatientConsultation.objects.filter(patient=patient),
)
),
),
"matched_by": matched_by,
}
},
)
return Response({}, status=status.HTTP_202_ACCEPTED)

Expand All @@ -182,7 +182,7 @@ def post(self, request, *args, **kwargs):
"transaction_id": data["transactionId"],
"patient_id": data["patient"]["referenceNumber"],
"phone": "7639899448",
}
},
)
return Response({}, status=status.HTTP_202_ACCEPTED)

Expand All @@ -198,8 +198,8 @@ def post(self, request, *args, **kwargs):

patient = get_object_or_404(
PatientRegistration.objects.filter(
external_id=data["confirmation"]["linkRefNumber"]
)
external_id=data["confirmation"]["linkRefNumber"],
),
)
AbdmGateway().on_link_confirm(
{
Expand All @@ -213,9 +213,9 @@ def post(self, request, *args, **kwargs):
"name": f"Encounter: {str(consultation.created_date.date())}",
},
PatientConsultation.objects.filter(patient=patient),
)
),
),
}
},
)

return Response({}, status=status.HTTP_202_ACCEPTED)
Expand All @@ -234,7 +234,7 @@ def post(self, request, *args, **kwargs):
{
"request_id": data["requestId"],
"consent_id": data["notification"]["consentId"],
}
},
)
return Response({}, status=status.HTTP_202_ACCEPTED)

Expand All @@ -248,7 +248,7 @@ def post(self, request, *args, **kwargs):

consent_id = data["hiRequest"]["consent"]["id"]
consent = json.loads(cache.get(consent_id)) if consent_id in cache else None
if not consent or not consent["notification"]["status"] == "GRANTED":
if not consent or consent["notification"]["status"] != "GRANTED":
return Response({}, status=status.HTTP_401_UNAUTHORIZED)

# TODO: check if from and to are in range and consent expiry is greater than today
Expand All @@ -263,13 +263,13 @@ def post(self, request, *args, **kwargs):
# return Response({}, status=status.HTTP_403_FORBIDDEN)

on_data_request_response = AbdmGateway().on_data_request(
{"request_id": data["requestId"], "transaction_id": data["transactionId"]}
{"request_id": data["requestId"], "transaction_id": data["transactionId"]},
)

if not on_data_request_response.status_code == 202:
return Response({}, status=status.HTTP_202_ACCEPTED)
if on_data_request_response.status_code != status.HTTP_202_ACCEPTED:
return Response(
on_data_request_response, status=status.HTTP_400_BAD_REQUEST
on_data_request_response,
status=status.HTTP_400_BAD_REQUEST,
)

cipher = Cipher(
Expand All @@ -296,32 +296,32 @@ def post(self, request, *args, **kwargs):
PatientConsultation.objects.get(
external_id=context[
"careContextReference"
]
)
).create_record(record)
],
),
).create_record(record),
)["data"],
},
consent["notification"]["consentDetail"]["hiTypes"],
)
),
),
consent["notification"]["consentDetail"]["careContexts"][
:-2:-1
],
)
),
),
[],
),
"key_material": {
"cryptoAlg": "ECDH",
"curve": "Curve25519",
"dhPublicKey": {
"expiry": (datetime.now() + timedelta(days=2)).isoformat(),
"expiry": (timezone.now() + timedelta(days=2)).isoformat(),
"parameters": "Curve25519/32byte random key",
"keyValue": cipher.key_to_share,
},
"nonce": cipher.sender_nonce,
},
}
},
)

AbdmGateway().data_notify(
Expand All @@ -335,9 +335,9 @@ def post(self, request, *args, **kwargs):
consent["notification"]["consentDetail"]["careContexts"][
:-2:-1
],
)
),
),
}
},
)

return Response({}, status=status.HTTP_202_ACCEPTED)
7 changes: 4 additions & 3 deletions care/abdm/api/viewsets/health_facility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from celery import shared_task
from dry_rest_permissions.generics import DRYPermissions
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.mixins import (
CreateModelMixin,
Expand All @@ -20,7 +21,7 @@
@shared_task
def register_health_facility_as_service(facility_external_id):
health_facility = HealthFacility.objects.filter(
facility__external_id=facility_external_id
facility__external_id=facility_external_id,
).first()

if not health_facility:
Expand All @@ -36,10 +37,10 @@ def register_health_facility_as_service(facility_external_id):
"type": "HIP",
"active": True,
"alias": ["CARE_HIP"],
}
},
)

if response.status_code == 200:
if response.status_code == status.HTTP_200_OK:
health_facility.registered = True
health_facility.save()
return True
Expand Down
Loading

0 comments on commit 8a8a49f

Please sign in to comment.