Skip to content

Commit

Permalink
Fix issues with location spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari committed Jan 29, 2025
1 parent 644210d commit 73ff1bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion care/emr/api/viewsets/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def validate_destroy(self, instance):
# TODO Add validation to check if patient association exists

def validate_data(self, instance, model_obj=None):
facility = self.get_facility_obj()
if not model_obj and instance.parent:
parent = get_object_or_404(FacilityLocation, external_id=instance.parent)
if parent.facility_id != instance.facility_id:
if parent.facility_id != facility.id:
raise PermissionDenied("Parent Incompatible with Location")
if parent.mode == FacilityLocationModeChoices.instance.value:
raise ValidationError("Instances cannot have children")
Expand Down
2 changes: 1 addition & 1 deletion care/emr/resources/location/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def validate_parent_organization(self):
if (
self.parent
and not FacilityLocation.objects.filter(
external_id=self.parent, mode=FacilityLocationModeChoices.instance.value
external_id=self.parent, mode=FacilityLocationModeChoices.kind.value
).exists()
):
err = "Parent not found"
Expand Down

0 comments on commit 73ff1bc

Please sign in to comment.