Skip to content

Commit

Permalink
Merge pull request #1672 from BLSQ/POLIO-1671_remove_non_polio_from_l…
Browse files Browse the repository at this point in the history
…qas_afro_map

POLIO-1671: remove non polio from lqas afro map
  • Loading branch information
quang-le authored Oct 3, 2024
2 parents 5c67a25 + 2acaeb5 commit 5e113a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/polio/api/lqas_im/lqasim_zoom_in_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
from plugins.polio.api.common import LQASStatus, RoundSelection, determine_status_for_district, make_safe_bbox
from plugins.polio.api.lqas_im.base_viewset import LqasAfroViewset
from plugins.polio.models import Campaign, Round
from plugins.polio.models.base import CampaignType


def get_latest_active_campaign_and_rounds(org_unit, start_date_after, end_date_before):
today = dt.date.today()
latest_active_round_qs = Round.objects.filter(campaign__country=org_unit)
polio_campaign_type = CampaignType.objects.get(name=CampaignType.POLIO)
latest_active_round_qs = Round.objects.filter(
campaign__country=org_unit, campaign__campaign_types=polio_campaign_type
)
if start_date_after is not None:
latest_active_round_qs = latest_active_round_qs.filter(started_at__gte=start_date_after)
if end_date_before is not None:
Expand Down
41 changes: 41 additions & 0 deletions plugins/polio/tests/test_lqas_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
reduce_to_country_status,
)
from plugins.polio.models import Campaign, CampaignScope, Round, RoundScope
from plugins.polio.models.base import CampaignType


class PolioLqasAfroMapTestCase(APITestCase):
Expand Down Expand Up @@ -136,6 +137,8 @@ def setUp(cls) -> None:
version=cls.source_version,
simplified_geom=cls.country_3_geo_json,
)
cls.polio_type, created = CampaignType.objects.get_or_create(name=CampaignType.POLIO)
cls.measles_type, created = CampaignType.objects.get_or_create(name=CampaignType.MEASLES)

# Campaign 1. Scope at campaign level
cls.campaign_1 = Campaign.objects.create(
Expand All @@ -144,6 +147,7 @@ def setUp(cls) -> None:
separate_scopes_per_round=False,
initial_org_unit=cls.country_org_unit_1,
)

cls.campaign1_scope_group = Group.objects.create(
name="campaign1scope", domain="POLIO", source_version=cls.source_version
)
Expand All @@ -169,6 +173,7 @@ def setUp(cls) -> None:
ended_at=cls.campaign1_round2_end.strftime("%Y-%m-%d"),
campaign=cls.campaign_1,
)
cls.campaign_1.campaign_types.add(cls.polio_type)

# Campaign 2. Scope at round level
cls.campaign_2 = Campaign.objects.create(
Expand Down Expand Up @@ -210,6 +215,8 @@ def setUp(cls) -> None:
cls.campaign2_round2_scope = RoundScope.objects.create(
round=cls.campaign2_round2, vaccine="nOPV2", group=cls.campaign2_round2_scope_org_units
)
cls.campaign_2.campaign_types.add(cls.polio_type)

# Creating a campign with round ending at date.max to check if it is exluded from results
cls.excluded_campaign = Campaign.objects.create(
obr_name="EXCLUDEDCAMPAIGN",
Expand Down Expand Up @@ -305,6 +312,40 @@ def setUp(cls) -> None:
)
cls.url_bounds = json.dumps({"_southWest": {"lat": 1, "lng": 1}, "_northEast": {"lat": 10, "lng": 10}})

# Non polio campaign, should not appear in results
cls.non_polio_campaign = Campaign.objects.create(
obr_name="NOT POLIO",
account=cls.account,
separate_scopes_per_round=False,
initial_org_unit=cls.country_org_unit_1,
)
cls.non_polio_campaign_scope_group = Group.objects.create(
name="campaign1scope", domain="POLIO", source_version=cls.source_version
)
cls.non_polio_campaign_scope_group.org_units.add(cls.district_org_unit_1)
cls.non_polio_campaign_scope_group.org_units.add(cls.district_org_unit_2)
cls.non_polio_campaign_scope_group.save()
cls.non_polio_campaign_scope = CampaignScope.objects.create(
campaign=cls.non_polio_campaign, vaccine="bOPV", group=cls.non_polio_campaign_scope_group
)
cls.non_polio_campaign_round1_start = (datetime.now() - timedelta(days=68)).date()
cls.non_polio_campaign_round1_end = (datetime.now() - timedelta(days=63)).date()
cls.non_polio_campaign_round2_start = (datetime.now() - timedelta(days=37)).date()
cls.non_polio_campaign_round2_end = (datetime.now() - timedelta(days=32)).date()
cls.non_polio_campaign_round1 = Round.objects.create(
number=1,
started_at=cls.non_polio_campaign_round1_start.strftime("%Y-%m-%d"),
ended_at=cls.non_polio_campaign_round1_end.strftime("%Y-%m-%d"),
campaign=cls.non_polio_campaign,
)
cls.non_polio_campaign_round2 = Round.objects.create(
number=2,
started_at=cls.non_polio_campaign_round2_start.strftime("%Y-%m-%d"),
ended_at=cls.non_polio_campaign_round2_end.strftime("%Y-%m-%d"),
campaign=cls.non_polio_campaign,
)
cls.non_polio_campaign.campaign_types.add(cls.measles_type)

def test_authorized_user(self):
c = APIClient()
c.force_authenticate(user=self.authorized_user)
Expand Down

0 comments on commit 5e113a4

Please sign in to comment.