Skip to content

Commit

Permalink
Merge branch 'feature/allow-target-date' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip committed Mar 27, 2024
2 parents e279d8d + 62bc505 commit 248b41d
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 10 deletions.
8 changes: 6 additions & 2 deletions policy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,14 @@ def build_query(self, req):
.annotate(total_rem_delivery=Sum('claim_ded_rems__rem_delivery')) \
.annotate(total_rem_hospitalization=Sum('claim_ded_rems__rem_hospitalization')) \
.annotate(total_rem_antenatal=Sum('claim_ded_rems__rem_antenatal'))

res.query.group_by = ['id']
if hasattr(req, 'chf_id'):
res= res.filter(insuree_policies__insuree__chf_id = req.chf_id)
if not req.show_history:
res = res.filter(*core.filter_validity(validity = req.target_date if req.target_date else None))
if req.target_date:
res = res.filter(*core.filter_validity(), expiry_date__gt = req.target_date, effective_date__lte = req.target_date)
else:
res = res.filter(*core.filter_validity())
if req.active_or_last_expired_only:
# sort on status, so that any active policy (status = 2) pops up...
res = res.annotate(not_null_expiry_date=Coalesce('expiry_date', py_date.max)) \
Expand Down
121 changes: 113 additions & 8 deletions policy/tests_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
create_test_service
)
from insuree.test_helpers import create_test_insuree
from policy.test_helpers import create_test_policy
from policy.test_helpers import create_test_policy, dts
from contribution.test_helpers import create_test_premium
from product.models import ProductItemOrService
from product.test_helpers import (
Expand All @@ -26,7 +26,7 @@
create_test_health_facility,
create_test_village
)

from uuid import UUID
@dataclass
class DummyContext:
""" Just because we need a context to generate. """
Expand All @@ -51,9 +51,10 @@ def setUpClass(cls):
cls.test_district = cls.test_village.parent.parent
# Given
cls.insuree = create_test_insuree(custom_props={'current_village':cls.test_village})

cls.service = create_test_service("A", custom_props={"name": "test_simple_batch"})
cls.item = create_test_item("A", custom_props={"name": "test_simple_batch"})

cls.product = create_test_product(
"BCUL0001",
custom_props={
Expand All @@ -77,9 +78,20 @@ def setUpClass(cls):
cls.premium = create_test_premium(
policy_id=cls.policy.id, custom_props={}
)



cls.policy_past = create_test_policy(cls.product, cls.insuree, link=True, custom_props={
"enroll_date": dts("2010-01-01"),
"start_date": dts("2010-01-01"),
"validity_from": dts("2010-01-01"),
"effective_date": dts("2010-01-01"),
"expiry_date": dts("2011-01-01"),
})
cls.premium_past = create_test_premium(
policy_id=cls.policy_past.id, custom_props={'pay_date':dts('2010-01-01')}
)
cls.not_insuree = create_test_insuree(with_family= False, custom_props={'family':cls.insuree.family})



def test_insuree_policy_query(self):

response = self.query(
Expand Down Expand Up @@ -109,8 +121,95 @@ def test_insuree_policy_query(self):

# Add some more asserts if you like
...
def test_query_not_insured_family_member(self):
response = self.query(
'''
query policiesByInsuree($chfid: String!) {
policiesByInsuree(chfId:$chfid)
{
totalCount
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
policyUuid,productCode,productName,officerCode,officerName,enrollDate,effectiveDate,startDate,expiryDate,status,policyValue,balance,ded,dedInPatient,dedOutPatient,ceiling,ceilingInPatient,ceilingOutPatient
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'chfid': self.not_insuree.chf_id, 'targetDate':self.policy.effective_date.strftime("%Y-%m-%d")}
)

content = json.loads(response.content)

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['policiesByInsuree']['totalCount'], 0)

def test_query_with_variables(self):
response = self.query(
'''
query policiesByInsuree($chfid: String!) {
policiesByInsuree(chfId:$chfid)
{
totalCount
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
policyUuid,productCode,productName,officerCode,officerName,enrollDate,effectiveDate,startDate,expiryDate,status,policyValue,balance,ded,dedInPatient,dedOutPatient,ceiling,ceilingInPatient,ceilingOutPatient
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'chfid': self.insuree.chf_id, 'targetDate':self.policy.effective_date.strftime("%Y-%m-%d")}
)

content = json.loads(response.content)

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['policiesByInsuree']['totalCount'], 2)

def test_query_with_variables_2(self):
response = self.query(
'''
query policiesByInsuree($chfid: String!, $activeOrLastExpiredOnly: Boolean!) {
policiesByInsuree(chfId:$chfid, activeOrLastExpiredOnly:$activeOrLastExpiredOnly)
{
totalCount
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
policyUuid,productCode,productName,officerCode,officerName,enrollDate,effectiveDate,startDate,expiryDate,status,policyValue,balance,ded,dedInPatient,dedOutPatient,ceiling,ceilingInPatient,ceilingOutPatient
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'chfid': self.insuree.chf_id, 'activeOrLastExpiredOnly':True}
)

content = json.loads(response.content)

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['policiesByInsuree']['totalCount'], 1)
self.assertEqual(UUID(content['data']['policiesByInsuree']['edges'][0]['node']['policyUuid']), UUID(self.policy.uuid))

def test_query_with_variables_3(self):
response = self.query(
'''
Expand All @@ -130,13 +229,15 @@ def test_query_with_variables(self):
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'chfid': "070707070", 'targetDate':"2019-01-01"}
variables={'chfid': self.insuree.chf_id, 'targetDate':self.policy.effective_date.strftime("%Y-%m-%d")}
)

content = json.loads(response.content)

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['policiesByInsuree']['totalCount'], 1)
self.assertEqual(UUID(content['data']['policiesByInsuree']['edges'][0]['node']['policyUuid']), UUID(self.policy.uuid))

def test_family_query_with_variables(self):
response = self.query(
Expand All @@ -157,13 +258,17 @@ def test_family_query_with_variables(self):
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'familyUuid': str(self.insuree.family.uuid), 'targetDate':"2019-01-01"}
variables={'familyUuid': str(self.insuree.family.uuid), 'targetDate':self.policy.effective_date.strftime("%Y-%m-%d")}
)

content = json.loads(response.content)



# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['policiesByFamily']['totalCount'], 1)
self.assertEqual(UUID(content['data']['policiesByFamily']['edges'][0]['node']['policyUuid']), UUID(self.policy.uuid))



Expand Down

0 comments on commit 248b41d

Please sign in to comment.