Skip to content

Commit

Permalink
Merge pull request #115 from openimis/feature/OP-2292
Browse files Browse the repository at this point in the history
Feature/op 2292
  • Loading branch information
delcroip authored Oct 18, 2024
2 parents cd8b4c6 + 216549a commit 1158752
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
25 changes: 19 additions & 6 deletions policy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import core
from claim.models import Claim, ClaimItem
from django import dispatch
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.exceptions import (
PermissionDenied,
ValidationError,
ObjectDoesNotExist,
MultipleObjectsReturned,
)
from django.db import connection
from django.db.models import Q, Count, Min, Max, Sum, F
from django.db.models.functions import Coalesce
Expand Down Expand Up @@ -773,11 +778,19 @@ def get_eligibility(self, insuree, item_or_service, model, req, now):
if item_or_service == "item":
item_or_service_code = req.item_code

# TODO validity is checked but should be optional in get_queryset
item_or_service_obj = model.get_queryset(None, self.user).get(
code__iexact=item_or_service_code, *core.filter_validity()
)

# try to get the service/item with the exact code
try:
item_or_service_obj = model.get_queryset(None, self.user).get(
code=item_or_service_code
)
except model.DoesNotExist:
item_or_service_obj = model.get_queryset(None, self.user).filter(
code__iexact=item_or_service_code
).first()
if item_or_service_obj is None:
raise model.DoesNotExist(f"{model.__name__} has no match for code {item_or_service_code}")
except MultipleObjectsReturned:
raise MultipleObjectsReturned(f"{model.__name__} has multiple match for code {item_or_service_code}")
# Beware that MonthAdd() is in Gregorian calendar, not Nepalese or anything else
queryset_item_or_service = (
InsureePolicy.objects.filter(
Expand Down
25 changes: 22 additions & 3 deletions policy/tests/tests_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def setUpClass(cls):
cls.service = create_test_service(
"A", custom_props={"name": "test_simple_batch"}
)
cls.service_2 = create_test_service(
"a", custom_props={"name": "test_simple_batch"}
)
cls.item = create_test_item("A", custom_props={"name": "test_simple_batch"})

cls.item_2 = create_test_item("a", custom_props={"name": "test_simple_batch"})
cls.product = create_test_product(
"BCUL0001",
custom_props={
Expand Down Expand Up @@ -299,7 +302,7 @@ def test_family_query_with_variables(self):
UUID(self.policy.uuid),
)

def test_insuree_policy_query(self):
def test_insuree_policy_service_query(self):

response = self.query(
f"""
Expand All @@ -317,6 +320,7 @@ def test_insuree_policy_query(self):

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
def test_insuree_policy_item_query(self):

# Add some more asserts if you like
response = self.query(
Expand All @@ -336,8 +340,23 @@ def test_insuree_policy_query(self):
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

def test_insuree_policy_wrong_service_query(self):
response = self.query(
f"""
{{
policyItemEligibilityByInsuree(chfId:"{self.insuree.chf_id}",itemCode:"IDONOTEXIST")
{{
minDateItem,itemLeft,isItemOk
}}
}}
""",
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
)

# This validates the status code and if you get errors
self.assertResponseHasErrors(response)

# Add some more asserts if you like
...

def test_mutation_simple(self):
muuid = "203327cd-501e-41e1-a026-ed742e360081"
Expand Down

0 comments on commit 1158752

Please sign in to comment.