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

Soft delete assets from deleted facilities/hospitals #1996

Merged
merged 26 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b7423f4
Soft delete assets from deleted facilities/hospitals
hrit2773 Mar 20, 2024
9025140
soft delete assets on deleting facility-removed redundant migrations
hrit2773 Mar 21, 2024
e95842f
added custom migrations and test cases
hrit2773 Mar 24, 2024
ebfed1b
Merge branch 'develop' into develop
hrit2773 Mar 24, 2024
ad66e21
Updated soft delete problem
hrit2773 Mar 24, 2024
1cfed7f
fix back
hrit2773 Mar 24, 2024
24f3eec
fix
hrit2773 Mar 24, 2024
cc8b5c5
Discard changes to Makefile
sainak Mar 25, 2024
e9afef8
Discard changes to config/celery_app.py
sainak Mar 25, 2024
b6f4a99
Merge branch 'develop' into develop
hrit2773 Mar 25, 2024
ea7786e
Merge branch 'coronasafe:develop' into develop
hrit2773 Mar 25, 2024
7330609
added cron job to soft delete
hrit2773 Mar 25, 2024
5f01058
changed soft delete assets
hrit2773 Mar 27, 2024
288422b
Merge branch 'coronasafe:develop' into develop
hrit2773 Mar 30, 2024
19415d0
Changed
hrit2773 Mar 30, 2024
9da57c5
Merge branch 'coronasafe:develop' into develop
hrit2773 Apr 4, 2024
5a11110
Discard changes to config/celery_app.py
sainak Apr 8, 2024
9473388
Merge branch 'develop' into develop
hrit2773 Apr 8, 2024
02e7382
Merge branch 'develop' into develop
hrit2773 Apr 15, 2024
691f9e8
Merge branch 'develop' into develop
hrit2773 Apr 24, 2024
8ea95a8
Merge branch 'develop' into develop
sainak Aug 23, 2024
1ab2e5a
fix query
sainak Aug 23, 2024
0ec7e14
Merge remote-tracking branch 'origin/develop' into hrit2773/develop
sainak Sep 22, 2024
9f31133
revert to soft deleting objects in delete method
sainak Sep 22, 2024
9a11922
wrap delete in transaction
sainak Sep 23, 2024
5850871
Merge branch 'develop' into develop
vigneshhari Sep 23, 2024
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
14 changes: 13 additions & 1 deletion care/facility/models/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth import get_user_model
from django.contrib.postgres.fields import ArrayField
from django.core.validators import MinValueValidator
from django.db import models
from django.db import models, transaction
from django.db.models import IntegerChoices
from django.db.models.constraints import CheckConstraint, UniqueConstraint
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -90,27 +90,27 @@
(5, "Hotel"),
(6, "Lodge"),
(7, "TeleMedicine"),
# (8, "Govt Hospital"), # Change from "Govt Hospital" to "Govt Medical College Hospitals"

Check failure on line 93 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:93:5: ERA001 Found commented-out code
(9, "Govt Labs"),
(10, "Private Labs"),
# Use 8xx for Govt owned hospitals and health centres
(800, "Primary Health Centres"),
# (801, "24x7 Public Health Centres"), # Change from "24x7 Public Health Centres" to "Primary Health Centres"

Check failure on line 98 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:98:5: ERA001 Found commented-out code
(802, "Family Health Centres"),
(803, "Community Health Centres"),
# (820, "Urban Primary Health Center"), # Change from "Urban Primary Health Center" to "Primary Health Centres"

Check failure on line 101 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:101:5: ERA001 Found commented-out code
(830, "Taluk Hospitals"),
# (831, "Taluk Headquarters Hospitals"), # Change from "Taluk Headquarters Hospitals" to "Taluk Hospitals"

Check failure on line 103 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:103:5: ERA001 Found commented-out code
(840, "Women and Child Health Centres"),
# (850, "General hospitals"), # Change from "General hospitals" to "District Hospitals"

Check failure on line 105 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:105:5: ERA001 Found commented-out code
(860, "District Hospitals"),
(870, "Govt Medical College Hospitals"),
(900, "Co-operative hospitals"),
(910, "Autonomous healthcare facility"),
# Use 9xx for Labs
# (950, "Corona Testing Labs"), # Change from "Corona Testing Labs" to "Govt Labs"

Check failure on line 111 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:111:5: ERA001 Found commented-out code
# Use 10xx for Corona Care Center
# (1000, "Corona Care Centre"), # Change from "Corona Care Centre" to "Other"

Check failure on line 113 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (ERA001)

care/facility/models/facility.py:113:5: ERA001 Found commented-out code
(1010, "COVID-19 Domiciliary Care Center"),
# Use 11xx for First Line Treatment Centre
(1100, "First Line Treatment Centre"),
Expand Down Expand Up @@ -207,7 +207,7 @@
"hub_id", flat=True
)
if spoke_id in ancestors_of_base:
raise serializers.ValidationError("This facility is already an ancestor hub")

Check failure on line 210 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (EM101)

care/facility/models/facility.py:210:43: EM101 Exception must not use a string literal, assign to variable first
for ancestor in ancestors_of_base:
check_if_spoke_is_not_ancestor(ancestor, spoke_id)

Expand Down Expand Up @@ -299,6 +299,18 @@
facility=self, user=self.created_by, created_by=self.created_by
)

@transaction.atomic
def delete(self, *args):
from care.facility.models.asset import Asset, AssetLocation

AssetLocation.objects.filter(facility_id=self.id).update(deleted=True)
Asset.objects.filter(
current_location_id__in=AssetLocation._base_manager.filter( # noqa: SLF001
facility_id=self.id
).values_list("id", flat=True)
).update(deleted=True)
return super().delete(*args)

@property
def get_features_display(self):
if not self.features:
Expand All @@ -308,19 +320,19 @@
def get_facility_flags(self):
return FacilityFlag.get_all_flags(self.id)

CSV_MAPPING = {
"name": "Facility Name",
"facility_type": "Facility Type",
"address": "Address",
"ward__name": "Ward Name",
"ward__number": "Ward Number",
"local_body__name": "Local Body",
"district__name": "District",
"state__name": "State",
"phone_number": "Phone Number",
}

Check failure on line 333 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (RUF012)

care/facility/models/facility.py:323:19: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`

CSV_MAKE_PRETTY = {"facility_type": (lambda x: REVERSE_FACILITY_TYPES[x])}

Check failure on line 335 in care/facility/models/facility.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (RUF012)

care/facility/models/facility.py:335:23: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`


class FacilityHubSpoke(BaseModel, FacilityRelatedPermissionMixin):
Expand Down
Loading