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

Fixed abha linking issue #2456

Merged
merged 3 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
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)
2 changes: 1 addition & 1 deletion care/abdm/api/viewsets/abha_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_object(self):
Q(abha_number=id) | Q(health_id=id) | Q(patient__external_id=id)
).first()

if not instance or get_patient_queryset(self.request.user).contains(
if not instance or not get_patient_queryset(self.request.user).contains(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a relevant test case for this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't have any tests for ABDM, opened up an issue (ohcnetwork/care_abdm#12) to track it.

instance.patient
):
raise Http404
Expand Down
60 changes: 60 additions & 0 deletions care/abdm/api/viewsets/healthid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
GenerateMobileOtpRequestPayloadSerializer,
HealthIdAuthSerializer,
HealthIdSerializer,
LinkPatientSerializer,
QRContentSerializer,
VerifyDemographicsRequestPayloadSerializer,
VerifyOtpRequestPayloadSerializer,
Expand Down Expand Up @@ -415,6 +416,65 @@
status=status.HTTP_200_OK,
)

@extend_schema(
operation_id="search_by_health_id",
request=LinkPatientSerializer,
tags=["ABDM HealthID"],
)
@action(detail=False, methods=["post"])
def link_patient(self, request):
data = request.data

Check warning on line 426 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L426

Added line #L426 was not covered by tests

serializer = LinkPatientSerializer(data=data)
serializer.is_valid(raise_exception=True)

Check warning on line 429 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L428-L429

Added lines #L428 - L429 were not covered by tests

patient_queryset = get_patient_queryset(request.user)
patient = patient_queryset.filter(external_id=data.get("patient")).first()

Check warning on line 432 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L431-L432

Added lines #L431 - L432 were not covered by tests

if not patient:
return Response(

Check warning on line 435 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L435

Added line #L435 was not covered by tests
{
"detail": "Patient not found or you do not have permission to access the patient",
},
status=status.HTTP_400_BAD_REQUEST,
)

if hasattr(patient, "abha_number"):
return Response(

Check warning on line 443 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L443

Added line #L443 was not covered by tests
{
"detail": "Patient already linked to an ABHA Number",
},
status=status.HTTP_400_BAD_REQUEST,
)

abha_number = AbhaNumber.objects.filter(

Check warning on line 450 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L450

Added line #L450 was not covered by tests
external_id=data.get("abha_number")
).first()

if not abha_number:
return Response(

Check warning on line 455 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L455

Added line #L455 was not covered by tests
{
"detail": "ABHA Number not found",
},
status=status.HTTP_400_BAD_REQUEST,
)

if abha_number.patient is not None:
return Response(

Check warning on line 463 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L463

Added line #L463 was not covered by tests
{
"detail": "ABHA Number already linked to a patient",
},
status=status.HTTP_400_BAD_REQUEST,
)

abha_number.patient = patient
abha_number.save()

Check warning on line 471 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L470-L471

Added lines #L470 - L471 were not covered by tests

return Response(

Check warning on line 473 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L473

Added line #L473 was not covered by tests
AbhaNumberSerializer(abha_number).data,
status=status.HTTP_200_OK,
)

@extend_schema(
operation_id="get_new_linking_token",
responses={"200": "{'status': 'boolean'}"},
Expand Down
Loading