-
Notifications
You must be signed in to change notification settings - Fork 325
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
Add list and detail serializer patient external serializer #1539
Closed
GeekGawd
wants to merge
4
commits into
ohcnetwork:develop
from
GeekGawd:list-detail-serializer-patient-external
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d599df4
Add list and detail serializer patient external serializer
GeekGawd 9e3b566
Merge branch 'master' into list-detail-serializer-patient-external
GeekGawd ca7a79a
Merge branch 'master' of https://github.com/geekgawd/care into list-d…
GeekGawd f138a04
Fix Test Cases
GeekGawd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
care/facility/tests/test_facility_patient_external_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from enum import Enum | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
from care.utils.tests.test_utils import TestUtils | ||
|
||
|
||
class ExpectedPatientExternalTestListKeys(Enum): | ||
id = "id" | ||
name = "name" | ||
age = "age" | ||
age_in = "age_in" | ||
test_type = "test_type" | ||
result = "result" | ||
patient_created = "patient_created" | ||
result_date = "result_date" | ||
|
||
|
||
class ExpectedPatientExternalTestRetrieveKeys(Enum): | ||
id = "id" | ||
ward_object = "ward_object" | ||
local_body_object = "local_body_object" | ||
district_object = "district_object" | ||
sample_collection_date = "sample_collection_date" | ||
result_date = "result_date" | ||
external_id = "external_id" | ||
created_date = "created_date" | ||
modified_date = "modified_date" | ||
deleted = "deleted" | ||
srf_id = "srf_id" | ||
name = "name" | ||
age = "age" | ||
age_in = "age_in" | ||
gender = "gender" | ||
address = "address" | ||
mobile_number = "mobile_number" | ||
is_repeat = "is_repeat" | ||
patient_status = "patient_status" | ||
source = "source" | ||
patient_category = "patient_category" | ||
lab_name = "lab_name" | ||
test_type = "test_type" | ||
sample_type = "sample_type" | ||
result = "result" | ||
patient_created = "patient_created" | ||
ward = "ward" | ||
local_body = "local_body" | ||
district = "district" | ||
|
||
|
||
class WardKeys(Enum): | ||
ID = "id" | ||
NAME = "name" | ||
NUMBER = "number" | ||
LOCAL_BODY = "local_body" | ||
|
||
|
||
class LocalBodyKeys(Enum): | ||
ID = "id" | ||
NAME = "name" | ||
BODY_TYPE = "body_type" | ||
LOCALBODY_CODE = "localbody_code" | ||
DISTRICT = "district" | ||
|
||
|
||
class DistrictKeys(Enum): | ||
ID = "id" | ||
NAME = "name" | ||
STATE = "state" | ||
|
||
|
||
class PatientExternalTestViewSetTestCase(TestUtils, APITestCase): | ||
@classmethod | ||
def setUpTestData(cls) -> None: | ||
cls.state = cls.create_state() | ||
cls.district = cls.create_district(cls.state) | ||
cls.super_user = cls.create_super_user(username="su2", district=cls.district) | ||
cls.local_body = cls.create_local_body(cls.district) | ||
cls.ward = cls.create_ward(cls.local_body) | ||
cls.patient_external = cls.create_patient_external_test( | ||
district=cls.district, local_body=cls.local_body, ward=cls.ward | ||
) | ||
|
||
def setUp(self) -> None: | ||
refresh_token = RefreshToken.for_user(self.super_user) | ||
self.client.credentials( | ||
HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" | ||
) | ||
|
||
def test_list_patient_external_test(self): | ||
response = self.client.get("/api/v1/external_result/") | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIsInstance(response.json()["results"], list) | ||
|
||
# Ensure only necessary data is being sent and no extra data | ||
expected_keys = [key.value for key in ExpectedPatientExternalTestListKeys] | ||
data = response.json()["results"][0] | ||
self.assertCountEqual(data.keys(), expected_keys) | ||
|
||
def test_retrieve_patient_external_test(self): | ||
response = self.client.get( | ||
f"/api/v1/external_result/{self.patient_external.id}/" | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
expected_keys = [key.value for key in ExpectedPatientExternalTestRetrieveKeys] | ||
|
||
data = response.json() | ||
|
||
self.assertCountEqual(data.keys(), expected_keys) | ||
|
||
self.assertCountEqual( | ||
data["ward_object"].keys(), [key.value for key in WardKeys] | ||
) | ||
self.assertCountEqual( | ||
data["local_body_object"].keys(), [key.value for key in LocalBodyKeys] | ||
) | ||
self.assertCountEqual( | ||
data["district_object"].keys(), [key.value for key in DistrictKeys] | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this serializer