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

Feature/remove admin area #4609

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 0 additions & 10 deletions src/frontend/data/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1482,14 +1482,6 @@ type GroupAttributeNode {
labelEn: String
}

enum HouseholdCollectIndividualData {
A_
A_2
A_1
A_3
A_0
}

enum HouseholdCollectType {
STANDARD
SINGLE
Expand Down Expand Up @@ -1582,7 +1574,6 @@ type HouseholdNode implements Node {
orgNameEnumerator: String!
village: String!
registrationMethod: HouseholdRegistrationMethod!
collectIndividualData: HouseholdCollectIndividualData!
currency: String
unhcrId: String!
detailId: String
Expand Down Expand Up @@ -1713,7 +1704,6 @@ input HouseholdUpdateDataObjectType {
orgNameEnumerator: String
village: String
registrationMethod: String
collectIndividualData: String
currency: String
unhcrId: String
flexFields: Arg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export const fakeGrievanceTicketPaymentVerification = {
orgEnumerator: 'A_',
updatedAt: '2024-12-09T20:40:33.645629+00:00',
consent: null,
collectIndividualData: 'A_',
registrationDataImport: {
name: 'Test Import',
dataSource: 'API',
Expand Down
1 change: 0 additions & 1 deletion src/frontend/fixtures/population/fakeHousehold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const fakeHousehold = {
orgEnumerator: 'A_',
updatedAt: '2024-01-17T09:20:12.470481+00:00',
consent: null,
collectIndividualData: 'A_',
registrationDataImport: {
name: 'Test Import',
dataSource: 'FLEX_REGISTRATION',
Expand Down
27 changes: 7 additions & 20 deletions src/frontend/src/__generated__/graphql.tsx

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/frontend/src/apollo/fragments/HouseholdFragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const householdDetailed = gql`
orgEnumerator
updatedAt
consent
collectIndividualData
individuals {
totalCount
edges {
Expand Down
1 change: 0 additions & 1 deletion src/hct_mis_api/api/endpoints/lookups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from hct_mis_api.api.endpoints.lookups.area import AreaList, AreaTypeList # noqa: F401
from hct_mis_api.api.endpoints.lookups.base import ( # noqa: F401
CountryAPIView,
DataCollectingPolicy,
DocumentType,
MaritalStatus,
ObservedDisability,
Expand Down
6 changes: 0 additions & 6 deletions src/hct_mis_api/api/endpoints/lookups/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from hct_mis_api.api.filters import CountryFilter
from hct_mis_api.apps.geo.models import Country
from hct_mis_api.apps.household.models import (
COLLECT_TYPES,
IDENTIFICATION_TYPE_CHOICE,
MARITAL_STATUS_CHOICE,
OBSERVED_DISABILITY_CHOICE,
Expand Down Expand Up @@ -64,11 +63,6 @@ def get(self, request: "Request", format: Optional[Any] = None) -> Response:
return Response(dict(RELATIONSHIP_CHOICE))


class DataCollectingPolicy(HOPEAPIView):
def get(self, request: "Request", format: Optional[Any] = None) -> Response:
return Response(dict(COLLECT_TYPES[1:]))


class Roles(HOPEAPIView):
def get(self, request: "Request", format: Optional[Any] = None) -> Response:
return Response(dict(ROLE_CHOICE))
Expand Down
2 changes: 0 additions & 2 deletions src/hct_mis_api/api/endpoints/rdi/push_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from hct_mis_api.apps.geo.models import Area, Country
from hct_mis_api.apps.household.models import (
BLANK,
COLLECT_TYPES,
HEAD,
NON_BENEFICIARY,
RESIDENCE_STATUS_CHOICE,
Expand Down Expand Up @@ -50,7 +49,6 @@ class PushPeopleSerializer(serializers.ModelSerializer):

country_origin = serializers.ChoiceField(choices=Countries(), required=False)
country = serializers.ChoiceField(choices=Countries())
collect_individual_data = serializers.ChoiceField(choices=COLLECT_TYPES)
residence_status = serializers.ChoiceField(choices=RESIDENCE_STATUS_CHOICE)
village = serializers.CharField(allow_blank=True, allow_null=True, required=False)

Expand Down
41 changes: 11 additions & 30 deletions src/hct_mis_api/api/endpoints/rdi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from hct_mis_api.api.utils import humanize_errors
from hct_mis_api.apps.core.utils import IDENTIFICATION_TYPE_TO_KEY_MAPPING
from hct_mis_api.apps.household.models import (
COLLECT_TYPE_FULL,
COLLECT_TYPE_NONE,
COLLECT_TYPE_PARTIAL,
HEAD,
IDENTIFICATION_TYPE_CHOICE,
NON_BENEFICIARY,
Expand All @@ -40,7 +37,6 @@

from hct_mis_api.apps.core.models import BusinessArea


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -100,22 +96,6 @@ class Meta:
]


class CollectDataMixin(serializers.Serializer):
collect_individual_data = serializers.CharField(required=True)

def validate_collect_individual_data(self, value: str) -> str:
v = value.upper()
if v in [COLLECT_TYPE_FULL, "FULL", "F"]:
return COLLECT_TYPE_FULL
if v in [COLLECT_TYPE_PARTIAL, "PARTIAL", "P"]:
return COLLECT_TYPE_PARTIAL
if v in [COLLECT_TYPE_NONE, "NO", "N", "NONE"]:
return COLLECT_TYPE_NONE
raise ValidationError(
"Invalid value %s. " "Check values at %s" % (value, reverse("api:datacollectingpolicy-list"))
)


class IndividualSerializer(serializers.ModelSerializer):
first_registration_date = serializers.DateTimeField(default=timezone.now)
last_registration_date = serializers.DateTimeField(default=timezone.now)
Expand Down Expand Up @@ -155,7 +135,7 @@ def validate_role(self, value: str) -> Optional[str]:
raise ValidationError("Invalid value %s. " "Check values at %s" % (value, reverse("api:role-list")))


class HouseholdSerializer(CollectDataMixin, serializers.ModelSerializer):
class HouseholdSerializer(serializers.ModelSerializer):
first_registration_date = serializers.DateTimeField(default=timezone.now)
last_registration_date = serializers.DateTimeField(default=timezone.now)
members = IndividualSerializer(many=True, required=True)
Expand Down Expand Up @@ -189,15 +169,16 @@ def validate(self, attrs: Dict) -> Dict:
def get_related() -> int:
return len([m for m in attrs["members"] if m["relationship"] not in [NON_BENEFICIARY]])

ctype = attrs.get("collect_individual_data", "")
if ctype == COLLECT_TYPE_NONE:
if not attrs.get("size", 0) > 0:
raise ValidationError({"size": ["This field is required 2"]})
elif ctype == COLLECT_TYPE_PARTIAL:
if not attrs.get("size", 0) > get_related():
raise ValidationError({"size": ["Households size must be greater than provided details"]})
else:
attrs["size"] = get_related()
# TODO - 221086 how to check this? Data collecting type in the program does not store information if individual data is collected
# ctype = attrs.get("collect_individual_data", "")
# if ctype == COLLECT_TYPE_NONE:
# if not attrs.get("size", 0) > 0:
# raise ValidationError({"size": ["This field is required 2"]})
# elif ctype == COLLECT_TYPE_PARTIAL:
# if not attrs.get("size", 0) > get_related():
# raise ValidationError({"size": ["Households size must be greater than provided details"]})
# else:
# attrs["size"] = get_related()
return attrs


Expand Down
5 changes: 0 additions & 5 deletions src/hct_mis_api/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
"lookups/observeddisability/", endpoints.lookups.ObservedDisability().as_view(), name="observeddisability-list"
),
path("lookups/relationship/", endpoints.lookups.Relationship().as_view(), name="relationship-list"),
path(
"lookups/datacollectingpolicy/",
endpoints.lookups.DataCollectingPolicy().as_view(),
name="datacollectingpolicy-list",
),
path("lookups/role/", endpoints.lookups.Roles().as_view(), name="role-list"),
path("lookups/sex/", endpoints.lookups.Sex().as_view(), name="sex-list"),
path("lookups/program-statuses/", endpoints.lookups.ProgramStatuses().as_view(), name="program-statuses-list"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@
SEX_CHOICE,
WORK_STATUS_CHOICE,
)
from hct_mis_api.apps.registration_data.models import (
COLLECT_TYPES,
RegistrationDataImport,
)
from hct_mis_api.apps.registration_data.models import RegistrationDataImport

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -714,19 +711,6 @@
Scope.PEOPLE_UPDATE,
],
},
{
"id": "d9eea60c-5747-4d26-9f4b-f99a2165e913",
"type": TYPE_SELECT_ONE,
"name": "collect_individual_data",
"lookup": "collect_individual_data",
"required": False,
"label": {"English(EN)": f"Will you be collecting all member {TEMPLATE_INDIVIDUAL} data?"},
"hint": "",
"choices": [{"label": {"English(EN)": label}, "value": value} for value, label in COLLECT_TYPES],
"associated_with": _HOUSEHOLD,
"xlsx_field": "collect_individual_data_h_c",
"scope": [Scope.GLOBAL, Scope.TARGETING, Scope.KOBO_IMPORT, Scope.HOUSEHOLD_UPDATE, Scope.XLSX],
},
{
"id": "1c2e3c42-8b32-4198-bd4f-06a61e2ecf0e",
"type": TYPE_SELECT_ONE,
Expand Down Expand Up @@ -1964,20 +1948,6 @@
"xlsx_field": "unicef_id_i_c",
"scope": [Scope.INDIVIDUAL_XLSX_UPDATE],
},
{
"id": "e48a4e26-6552-4e15-855f-9ea4d5268c84",
"type": TYPE_SELECT_ONE,
"name": "admin_area_title",
"lookup": "admin_area__p_code",
"required": False,
"label": {"English(EN)": f"{TEMPLATE_HOUSEHOLD} resides in which admin area?"},
"hint": "",
"choices": [],
"associated_with": _HOUSEHOLD,
"xlsx_field": "admin_area_h_c",
"scope": [Scope.HOUSEHOLD_UPDATE],
"snapshot_field": "admin_area_id__p_code",
},
{
"id": "9da8c56a-3c65-47d9-8149-699761842ce4",
"type": TYPE_STRING,
Expand Down
11 changes: 11 additions & 0 deletions src/hct_mis_api/apps/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
from openpyxl.worksheet.worksheet import Worksheet

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.geo.models import Area
from hct_mis_api.apps.household.models import Household

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -943,3 +945,12 @@ class JSONBSet(Func):
def __init__(self, expression: Any, path: Any, new_value: Any, create_missing: bool = True, **extra: Any) -> None:
create_missing = Value("true") if create_missing else Value("false") # type: ignore
super().__init__(expression, path, new_value, create_missing, **extra)


def get_lowest_admin_area(household: "Household") -> Optional["Area"]:
fields = ["admin1", "admin2", "admin3"]
for field in fields:
admin_area = getattr(household, field)
if admin_area:
return admin_area
return None
1 change: 0 additions & 1 deletion src/hct_mis_api/apps/grievance/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class HouseholdUpdateDataObjectType(graphene.InputObjectType):
org_name_enumerator = graphene.String()
village = graphene.String()
registration_method = graphene.String()
collect_individual_data = graphene.String()
currency = graphene.String()
unhcr_id = graphene.String()
flex_fields = Arg()
Expand Down
8 changes: 0 additions & 8 deletions src/hct_mis_api/apps/household/admin/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,6 @@ def sanity_check(self, request: HttpRequest, pk: UUID) -> TemplateResponse:

active_individuals = hh.individuals(manager="all_objects").exclude(Q(duplicate=True) | Q(withdrawn=True))
ghosts_individuals = hh.individuals(manager="all_objects").filter(Q(duplicate=True) | Q(withdrawn=True))
all_individuals = hh.individuals(manager="all_objects").all()
if hh.collect_individual_data:
if active_individuals.count() != hh.size:
warnings.append([messages.WARNING, "HH size does not match"])

else:
if all_individuals.count() > 1:
warnings.append([messages.ERROR, "Individual data not collected but members found"])

if hh.size != total_in_ranges:
warnings.append(
Expand Down
13 changes: 3 additions & 10 deletions src/hct_mis_api/apps/household/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

from hct_mis_api.apps.core.celery import app
from hct_mis_api.apps.household.documents import HouseholdDocument, get_individual_doc
from hct_mis_api.apps.household.models import (
COLLECT_TYPE_FULL,
COLLECT_TYPE_PARTIAL,
Household,
Individual,
)
from hct_mis_api.apps.household.models import Household, Individual
from hct_mis_api.apps.household.services.household_recalculate_data import (
recalculate_data,
)
Expand Down Expand Up @@ -54,7 +49,7 @@ def recalculate_population_fields_chunk_task(households_ids: List[UUID], program
fields_to_update = []
for hh in (
Household.objects.filter(pk__in=households_ids_page)
.only("id", "collect_individual_data")
.only("id")
.prefetch_related("individuals")
.select_for_update(of=("self",), skip_locked=True)
.order_by("pk")
Expand Down Expand Up @@ -85,9 +80,7 @@ def recalculate_population_fields_task(
program = Program.objects.get(id=program_id)
recalculate_composition = program.data_collecting_type.recalculate_composition
queryset = Household.objects.filter(**params).only("pk").order_by("pk")
if recalculate_composition is None:
queryset = queryset.filter(collect_individual_data__in=(COLLECT_TYPE_FULL, COLLECT_TYPE_PARTIAL))
elif not recalculate_composition:
if not recalculate_composition:
queryset = queryset.none()

if queryset.exists():
Expand Down
2 changes: 0 additions & 2 deletions src/hct_mis_api/apps/household/fixtures/data-cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
"org_name_enumerator": "UNICEF",
"village": "",
"registration_method": "COMMUNITY",
"collect_individual_data": "1",
"currency": "USD",
"unhcr_id": "",
"internal_data": {},
Expand Down Expand Up @@ -202,7 +201,6 @@
"org_name_enumerator": "UNICEF",
"village": "",
"registration_method": "COMMUNITY",
"collect_individual_data": "1",
"currency": "USD",
"unhcr_id": "",
"internal_data": {},
Expand Down
2 changes: 0 additions & 2 deletions src/hct_mis_api/apps/household/fixtures/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
"org_name_enumerator": "UNICEF",
"village": "",
"registration_method": "COMMUNITY",
"collect_individual_data": "1",
"currency": "USD",
"unhcr_id": "",
"detail_id": "4",
Expand Down Expand Up @@ -201,7 +200,6 @@
"org_name_enumerator": "UNICEF",
"village": "",
"registration_method": "COMMUNITY",
"collect_individual_data": "1",
"currency": "USD",
"unhcr_id": "",
"detail_id": "3",
Expand Down
17 changes: 17 additions & 0 deletions src/hct_mis_api/apps/household/migrations/0010_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.25 on 2025-01-24 14:02

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('household', '0009_migration'),
]

operations = [
migrations.RemoveField(
model_name='household',
name='collect_individual_data',
),
]
Loading
Loading