-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into sainak/fix/beds
- Loading branch information
Showing
14 changed files
with
278 additions
and
42 deletions.
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
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,17 @@ | ||
# Generated by Django 4.2.2 on 2023-09-05 06:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("abdm", "0009_healthfacility"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="healthfacility", | ||
name="registered", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from care.facility.models.mixins.permissions.base import BasePermissionMixin | ||
from care.users.models import User | ||
|
||
|
||
class HealthFacilityPermissions(BasePermissionMixin): | ||
""" | ||
Permissions for HealthFacilityViewSet | ||
""" | ||
|
||
def has_object_read_permission(self, request): | ||
return self.facility.has_object_read_permission(request) | ||
|
||
def has_object_write_permission(self, request): | ||
allowed_user_types = [ | ||
User.TYPE_VALUE_MAP["WardAdmin"], | ||
User.TYPE_VALUE_MAP["LocalBodyAdmin"], | ||
User.TYPE_VALUE_MAP["DistrictAdmin"], | ||
User.TYPE_VALUE_MAP["StateAdmin"], | ||
] | ||
return request.user.is_superuser or ( | ||
request.user.user_type in allowed_user_types | ||
and self.facility.has_object_write_permission(request) | ||
) | ||
|
||
def has_object_update_permission(self, request): | ||
return self.has_object_write_permission(request) | ||
|
||
def has_object_destroy_permission(self, request): | ||
return self.has_object_write_permission(request) |
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
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
17 changes: 17 additions & 0 deletions
17
care/facility/migrations/0383_patientconsultation_icd11_principal_diagnosis.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,17 @@ | ||
# Generated by Django 4.2.2 on 2023-09-04 09:49 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0382_assetservice_remove_asset_last_serviced_on_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="patientconsultation", | ||
name="icd11_principal_diagnosis", | ||
field=models.CharField(blank=True, default="", max_length=100, null=True), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from rest_framework import status | ||
|
||
from care.facility.models import MedibaseMedicine | ||
from care.utils.tests.test_base import TestBase | ||
|
||
|
||
class PrescriptionsApiTestCase(TestBase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.medicine = MedibaseMedicine.objects.first() | ||
|
||
self.normal_prescription_data = { | ||
"medicine": self.medicine.external_id, | ||
"prescription_type": "REGULAR", | ||
"dosage": "1 mg", | ||
"frequency": "OD", | ||
"is_prn": False, | ||
} | ||
|
||
def test_create_normal_prescription(self): | ||
consultation = self.create_consultation() | ||
response = self.client.post( | ||
f"/api/v1/consultation/{consultation.external_id}/prescriptions/", | ||
self.normal_prescription_data, | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_prescribe_duplicate_active_medicine_and_discontinue(self): | ||
""" | ||
1. Creates a prescription with Medicine A | ||
2. Attempts to create another prescription with Medicine A (expecting failure) | ||
3. Discontinues the first prescription | ||
4. Re-attempts to create another prescription with Medicine A (expecting success) | ||
""" | ||
consultation = self.create_consultation() | ||
res = self.client.post( | ||
f"/api/v1/consultation/{consultation.external_id}/prescriptions/", | ||
self.normal_prescription_data, | ||
) | ||
self.assertEqual(res.status_code, status.HTTP_201_CREATED) | ||
discontinue_prescription_id = res.data["id"] | ||
|
||
res = self.client.post( | ||
f"/api/v1/consultation/{consultation.external_id}/prescriptions/", | ||
self.normal_prescription_data, | ||
) | ||
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
res = self.client.post( | ||
f"/api/v1/consultation/{consultation.external_id}/prescriptions/{discontinue_prescription_id}/discontinue/", | ||
{ | ||
"discontinued_reason": "Test Reason", | ||
}, | ||
) | ||
self.assertEqual(res.status_code, status.HTTP_200_OK) | ||
|
||
res = self.client.post( | ||
f"/api/v1/consultation/{consultation.external_id}/prescriptions/", | ||
self.normal_prescription_data, | ||
) | ||
self.assertEqual(res.status_code, status.HTTP_201_CREATED) |
Oops, something went wrong.