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

adding swagger support #2772

Merged
merged 23 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b547baa
fix medication administration upsert api (#2769)
khavinshankar Jan 22, 2025
ba647ba
add now as default for authored datetime (#2770)
sainak Jan 22, 2025
2f59824
Add abatement and chronic_condition to conditions (#2771)
sainak Jan 22, 2025
07f3f70
added swaggar support
DraKen0009 Jan 22, 2025
837f0ae
added more swaggar support
DraKen0009 Jan 22, 2025
853427f
fixed create mixin change
DraKen0009 Jan 22, 2025
58a9987
reverted status code change
DraKen0009 Jan 22, 2025
00550df
Merge branch 'develop' into prafful/feat/adding-swagger-support
DraKen0009 Jan 22, 2025
71e2389
using isoparse for less strict validations on date (#2774)
DraKen0009 Jan 23, 2025
1932fd6
Merge branch 'develop' into prafful/feat/adding-swagger-support
DraKen0009 Jan 23, 2025
2f9fa83
Add `requester` to `MedicationRequest` and basic authzn. tests (#2773)
rithviknishad Jan 23, 2025
aff7fdb
created a decorator for schema generation
DraKen0009 Jan 24, 2025
83cf327
merged develop
DraKen0009 Jan 24, 2025
de73f58
updated the decorator
DraKen0009 Jan 24, 2025
ca3345e
Add chronic condition api (#2775)
sainak Jan 24, 2025
b9c52a6
Fix condition updates
vigneshhari Jan 24, 2025
3a5319d
Merge develop
vigneshhari Jan 24, 2025
5efcfbb
Fix update specs
vigneshhari Jan 24, 2025
6add747
Update allergy_intolerance update spec and added tests (#2778)
sainak Jan 24, 2025
d7b4084
updated decorator to include tags
DraKen0009 Jan 26, 2025
a46ca16
Merge branch 'develop' into prafful/feat/adding-swagger-support
DraKen0009 Jan 26, 2025
45cdda8
update for tags
DraKen0009 Jan 26, 2025
680b141
Merge branch 'vigneshhari/locations' into prafful/feat/adding-swagger…
vigneshhari Jan 26, 2025
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
30 changes: 0 additions & 30 deletions care/abdm/migrations/0014_replace_0013.py

This file was deleted.

46 changes: 0 additions & 46 deletions care/abdm/migrations_old/0013_abhanumber_patient.py

This file was deleted.

2 changes: 1 addition & 1 deletion care/audit_log/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RequestInformation(NamedTuple):
exception: Exception | None


logger = logging.getLogger(__name__)
logger = logging.getLogger("audit_log")


class AuditLogMiddleware:
Expand Down
9 changes: 9 additions & 0 deletions care/emr/api/otp_viewsets/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from django.conf import settings
from django.utils import timezone
from drf_spectacular.utils import extend_schema
from pydantic import BaseModel, Field, field_validator
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response

from care.emr.api.viewsets.base import EMRBaseViewSet
from care.facility.models.patient import PatientMobileOTP
from care.utils.decorators.schema_decorator import generate_swagger_schema_decorator
from care.utils.models.validators import mobile_validator
from care.utils.sms.send_sms import send_sms
from config.patient_otp_token import PatientToken
Expand Down Expand Up @@ -41,10 +43,14 @@ class OTPLoginSpec(OTPLoginRequestSpec):
otp: str = Field(min_length=settings.OTP_LENGTH, max_length=settings.OTP_LENGTH)


@generate_swagger_schema_decorator
class OTPLoginView(EMRBaseViewSet):
authentication_classes = []
permission_classes = []

@extend_schema(
request=OTPLoginRequestSpec,
)
@action(detail=False, methods=["POST"])
def send(self, request):
data = OTPLoginRequestSpec(**request.data)
Expand Down Expand Up @@ -76,6 +82,9 @@ def send(self, request):
otp_obj.save()
return Response({"otp": "generated"})

@extend_schema(
request=OTPLoginSpec,
)
@action(detail=False, methods=["POST"])
def login(self, request):
data = OTPLoginSpec(**request.data)
Expand Down
2 changes: 2 additions & 0 deletions care/emr/api/otp_viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
PatientOTPReadSpec,
PatientOTPWriteSpec,
)
from care.utils.decorators.schema_decorator import generate_swagger_schema_decorator
from config.patient_otp_authentication import (
JWTTokenPatientAuthentication,
OTPAuthenticatedPermission,
)


@generate_swagger_schema_decorator
class PatientOTPView(EMRCreateMixin, EMRListMixin, EMRBaseViewSet):
authentication_classes = [JWTTokenPatientAuthentication]
permission_classes = [OTPAuthenticatedPermission]
Expand Down
12 changes: 12 additions & 0 deletions care/emr/api/otp_viewsets/slot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from drf_spectacular.utils import extend_schema
from pydantic import UUID4, BaseModel
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
Expand All @@ -18,6 +19,7 @@
TokenBookingReadSpec,
TokenSlotBaseSpec,
)
from care.utils.decorators.schema_decorator import generate_swagger_schema_decorator
from config.patient_otp_authentication import (
JWTTokenPatientAuthentication,
OTPAuthenticatedPermission,
Expand All @@ -33,19 +35,26 @@ class CancelAppointmentSpec(BaseModel):
appointment: UUID4


@generate_swagger_schema_decorator
class OTPSlotViewSet(EMRRetrieveMixin, EMRBaseViewSet):
authentication_classes = [JWTTokenPatientAuthentication]
permission_classes = [OTPAuthenticatedPermission]
database_model = TokenSlot
pydantic_read_model = TokenSlotBaseSpec

@extend_schema(
request=SlotsForDayRequestSpec,
)
@action(detail=False, methods=["POST"])
def get_slots_for_day(self, request, *args, **kwargs):
request_data = SlotsForDayRequestSpec(**request.data)
return SlotViewSet.get_slots_for_day_handler(
request_data.facility, request.data
)

@extend_schema(
request=AppointmentBookingSpec,
)
@action(detail=True, methods=["POST"])
def create_appointment(self, request, *args, **kwargs):
request_data = AppointmentBookingSpec(**request.data)
Expand All @@ -57,6 +66,9 @@ def create_appointment(self, request, *args, **kwargs):
self.get_object(), request.data, None
)

@extend_schema(
request=CancelAppointmentSpec,
)
@action(detail=False, methods=["POST"])
def cancel_appointment(self, request, *args, **kwargs):
request_data = CancelAppointmentSpec(**request.data)
Expand Down
31 changes: 21 additions & 10 deletions care/emr/api/viewsets/allergy_intolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
)
from care.emr.models import Patient
from care.emr.models.allergy_intolerance import AllergyIntolerance
from care.emr.models.encounter import Encounter
from care.emr.registries.system_questionnaire.system_questionnaire import (
InternalQuestionnaireRegistry,
)
from care.emr.resources.allergy_intolerance.spec import (
AllergyIntoleranceSpec,
AllergyIntoleranceReadSpec,
AllergyIntoleranceUpdateSpec,
AllergyIntoleranceWriteSpec,
AllergyIntrolanceSpecRead,
)
from care.emr.resources.questionnaire.spec import SubjectType
from care.security.authorization import AuthorizationController
from care.utils.decorators.schema_decorator import generate_swagger_schema_decorator


class AllergyIntoleranceFilters(FilterSet):
clinical_status = CharFilter(field_name="clinical_status")


@generate_swagger_schema_decorator
@extend_schema_view(
create=extend_schema(request=AllergyIntoleranceSpec),
create=extend_schema(request=AllergyIntoleranceWriteSpec),
)
class AllergyIntoleranceViewSet(
EMRQuestionnaireResponseMixin,
Expand All @@ -44,9 +47,9 @@ class AllergyIntoleranceViewSet(
EMRUpsertMixin,
):
database_model = AllergyIntolerance
pydantic_model = AllergyIntoleranceSpec
pydantic_read_model = AllergyIntrolanceSpecRead
pydantic_update_model = AllergyIntoleranceWriteSpec
pydantic_model = AllergyIntoleranceWriteSpec
pydantic_read_model = AllergyIntoleranceReadSpec
pydantic_update_model = AllergyIntoleranceUpdateSpec
questionnaire_type = "allergy_intolerance"
questionnaire_title = "Allergy Intolerance"
questionnaire_description = "Allergy Intolerance"
Expand All @@ -59,15 +62,23 @@ def get_patient_obj(self):
Patient, external_id=self.kwargs["patient_external_id"]
)

def authorize_update(self, request_obj, model_instance):
self.authorize_create({})

def authorize_create(self, instance):
if not AuthorizationController.call(
"can_write_patient_obj", self.request.user, self.get_patient_obj()
):
raise PermissionDenied("You do not have permission to update encounter")
# TODO If there is an encounter, check access to the encounter

def authorize_update(self, request_obj, model_instance):
encounter = get_object_or_404(Encounter, external_id=request_obj.encounter)
if not AuthorizationController.call(
"can_update_encounter_obj",
self.request.user,
encounter,
):
raise PermissionDenied("You do not have permission to update encounter")

def clean_update_data(self, request_data):
return super().clean_update_data(request_data, keep_fields={"encounter"})

def get_queryset(self):
if not AuthorizationController.call(
Expand Down
12 changes: 7 additions & 5 deletions care/emr/api/viewsets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ def perform_update(self, instance):
updated_by=self.request.user,
)

def clean_update_data(self, request_data):
def clean_update_data(self, request_data, keep_fields: set | None = None):
if type(request_data) is list:
return request_data
request_data.pop("id", None)
request_data.pop("external_id", None)
request_data.pop("patient", None)
request_data.pop("encounter", None)
ignored_fields = {"id", "external_id", "patient", "encounter"}
if keep_fields:
ignored_fields = ignored_fields - set(keep_fields)
for field in ignored_fields:
request_data.pop(field, None)
return request_data

def update(self, request, *args, **kwargs):
Expand Down Expand Up @@ -229,6 +230,7 @@ class EMRBaseViewSet(GenericViewSet):
pydantic_retrieve_model: EMRResource = None
database_model: EMRBaseModel = None
lookup_field = "external_id"
tags = [__name__]

def get_exception_handler(self):
return emr_exception_handler
Expand Down
4 changes: 4 additions & 0 deletions care/emr/api/viewsets/batch_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import transaction
from drf_spectacular.utils import extend_schema
from pydantic import BaseModel, Field
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
Expand Down Expand Up @@ -26,6 +27,9 @@ class BatchRequestView(GenericViewSet):
def get_exception_handler(self):
return emr_exception_handler

@extend_schema(
request=BatchRequest,
)
def create(self, request, *args, **kwargs):
requests = BatchRequest(**request.data)
errored = False
Expand Down
Loading
Loading