Skip to content

Commit

Permalink
Fix error type
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari committed Dec 25, 2024
1 parent e59bbce commit 6a1a980
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions care/emr/api/viewsets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def emr_exception_handler(exc, context):
if type(exc.detail) is dict: # noqa SIM102
if "errors" in exc.detail:
return Response(exc.detail, status=400)
if type(exc.detail) is list:
errors = " , ".join([str(e) for e in exc.detail])
return Response(
{"errors": {"type": "validation_error", "msg": errors}}, status=400
)
return Response(
{"errors": {"type": "validation_error", "msg": exc.detail}}, status=400
)
Expand Down
15 changes: 10 additions & 5 deletions care/emr/api/viewsets/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ def get_queryset(self):
super().get_queryset().select_related("parent", "created_by", "updated_by")
)

@action(detail=False , methods=["GET"])
def mine(self , request, *args , **kwargs):
orgusers = OrganizationUser.objects.filter(user = request.user).select_related("organization")
@action(detail=False, methods=["GET"])
def mine(self, request, *args, **kwargs):
orgusers = OrganizationUser.objects.filter(user=request.user).select_related(
"organization"
)
data = [
self.get_read_pydantic_model().serialize(orguser.organization).to_json() for orguser in orgusers
self.get_read_pydantic_model().serialize(orguser.organization).to_json()
for orguser in orgusers
]
return Response({ "count" : len(data) , "results" : data})
return Response({"count": len(data), "results": data})


class OrganizationUsersViewSet(EMRModelViewSet):
database_model = OrganizationUser
pydantic_model = OrganizationUserWriteSpec
Expand Down
1 change: 1 addition & 0 deletions care/emr/models/organziation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class FacilityOrganization(EMRBaseModel):
parent_cache = ArrayField(models.IntegerField(), default=list)
metadata = models.JSONField(default=dict)


class Organization(EMRBaseModel):
active = models.BooleanField(default=True)
root_org = models.ForeignKey(
Expand Down
2 changes: 2 additions & 0 deletions care/emr/resources/facility_organization/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FacilityOrganizationBaseSpec(EMRResource):
parent: UUID4 | None = None
metadata: dict = {}


class FacilityOrganizationWriteSpec(FacilityOrganizationBaseSpec):
facility: UUID4

Expand Down Expand Up @@ -77,6 +78,7 @@ class FacilityOrganizationReadSpec(FacilityOrganizationBaseSpec):
system_generated: bool
level_cache: int = 0
has_children: bool

@classmethod
def perform_extra_serialization(cls, mapping, obj):
mapping["id"] = obj.external_id
Expand Down
1 change: 1 addition & 0 deletions care/emr/resources/organization/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class OrganizationBaseSpec(EMRResource):
parent: UUID4 | None = None
metadata: dict = {}


class OrganizationWriteSpec(OrganizationBaseSpec):
@model_validator(mode="after")
def validate_parent_organization(self):
Expand Down

0 comments on commit 6a1a980

Please sign in to comment.