Skip to content
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
2 changes: 2 additions & 0 deletions claim/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def resolve_client_mutation_id(self, info):

@classmethod
def get_queryset(cls, queryset, info):
if info.field_name == "claimHistory":
return queryset
return Claim.get_queryset(queryset, info).all()


Expand Down
54 changes: 54 additions & 0 deletions claim/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ class Query(graphene.ObjectType):
ClaimAttachmentTypeGQLType
)

claim_history = OrderedDjangoFilterConnectionField(
ClaimGQLType,
claim_uuid=graphene.String(required=True),
diagnosisVariance=graphene.Int(),
code_is_not=graphene.String(),
orderBy=graphene.List(of_type=graphene.String),
items=graphene.List(of_type=graphene.String),
services=graphene.List(of_type=graphene.String),
json_ext=graphene.JSONString(),
attachment_status=graphene.Int(required=False),
care_type=graphene.String(required=False),
show_restored=graphene.Boolean(required=False),
rejection_code=graphene.Int(required=False)
)

def resolve_insuree_name_by_chfid(self, info, **kwargs):
if not info.context.user.has_perms(ClaimConfig.gql_mutation_create_claims_perms)\
and not info.context.user.has_perms(ClaimConfig.gql_mutation_update_claims_perms):
Expand Down Expand Up @@ -229,6 +244,45 @@ def resolve_claim_with_same_diagnosis(self, info, **kwargs):
validity_to__isnull=True).order_by("date_claimed")
return qs

def resolve_claim_history(self, info, **kwargs):
claim_uuid = kwargs.get('claim_uuid')

try:
target_claim = Claim.objects.get(uuid=claim_uuid)
except Claim.DoesNotExist:
return Claim.objects.none()

if (
not info.context.user.has_perms(ClaimConfig.gql_query_claims_perms)
and settings.ROW_SECURITY
):
raise PermissionDenied(_("unauthorized"))

query = Claim.objects.filter(
code=target_claim.code,
validity_to__isnull=False
)

filters = []

if "care_type" in kwargs and kwargs["care_type"]:
filters.append(Q(care_type=kwargs["care_type"]))

if "attachment_status" in kwargs:
status = kwargs["attachment_status"]
if status == 1: # WITH
filters.append(Q(attachments__isnull=False))
elif status == 2: # WITHOUT
filters.append(Q(attachments__isnull=True))

if "code_is_not" in kwargs and kwargs["code_is_not"]:
filters.append(~Q(code=kwargs["code_is_not"]))

if filters:
query = query.filter(*filters).distinct()

return gql_optimizer.query(query, info)


class Mutation(graphene.ObjectType):
create_claim = CreateClaimMutation.Field()
Expand Down
46 changes: 45 additions & 1 deletion claim/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from graphene import Schema

from claim.models import Claim
from core.models.user import ClaimAdmin
from claim.models import ClaimAdmin


import datetime
from policy.models import Policy
Expand All @@ -25,6 +26,7 @@
from location.models import Location
from medical.test_helpers import create_test_service
from medical_pricelist.test_helpers import add_service_to_hf_pricelist
from claim.test_helpers import create_test_claim


class ClaimGraphQLTestCase(openIMISGraphQLTestCase):
Expand Down Expand Up @@ -65,6 +67,7 @@ def setUpClass(cls):
cls.service, hf_id=cls.claim_admin.health_facility.id)
cls.product_service = create_test_product_service(
cls.product, cls.service, custom_props={"limit_no_adult": 20})
cls.claim = create_test_claim(custom_props={"insuree_id": cls.insuree.id})

def test_claims_query(self):

Expand Down Expand Up @@ -345,4 +348,45 @@ def test_mutation_create_claim(self):
self.assertEqual(claim.feedback_status, Claim.FEEDBACK_SELECTED)
self.assertEqual(claim.review_status, Claim.REVIEW_DELIVERED)

def test_claim_history_query(self):
historical_claim1 = create_test_claim(custom_props={
"code": self.claim.code,
"validity_to": "2023-01-01 00:00:00",
"insuree_id": self.insuree.id,
"status": Claim.STATUS_ENTERED
})
historical_claim2 = create_test_claim(custom_props={
"code": self.claim.code,
"validity_to": "2023-01-02 00:00:00",
"insuree_id": self.insuree.id,
"status": Claim.STATUS_CHECKED
})

response = self.query(
'''
query {
claimHistory(claimUuid: "%s") {
totalCount
edges {
node {
uuid
code
validityTo
status
}
}
}
}
''' % str(self.claim.uuid),
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"}
)
content = json.loads(response.content)
self.assertResponseNoErrors(response)
self.assertEqual(content['data']['claimHistory']['totalCount'], 2)
edges = content['data']['claimHistory']['edges']
self.assertEqual(edges[0]['node']['code'], self.claim.code)
self.assertIsNotNone(edges[0]['node']['validityTo'])
self.assertEqual(edges[0]['node']['status'], Claim.STATUS_ENTERED)
self.assertEqual(edges[1]['node']['code'], self.claim.code)
self.assertIsNotNone(edges[1]['node']['validityTo'])
self.assertEqual(edges[1]['node']['status'], Claim.STATUS_CHECKED)
Loading