Skip to content

Commit

Permalink
Merge pull request #175 from openimis/feature/fix_claim_update
Browse files Browse the repository at this point in the history
Fixed claim update bug
  • Loading branch information
delcroip authored Apr 23, 2024
2 parents 03b3ace + 277fec4 commit c8c9aa2
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 87 deletions.
Empty file added claim/tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ class DummyUser:
self.assertEqual(claim.feedback_status, Claim.FEEDBACK_SELECTED)

def test_submit_claim_with_different_packatypes(self):
from .apps import ClaimConfig
from claim.apps import ClaimConfig
ClaimConfig.native_code_for_services=False
insuree = create_test_insuree()
self.assertIsNotNone(insuree)
Expand Down
96 changes: 48 additions & 48 deletions claim/tests.py → claim/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,42 +167,59 @@ def test_mutation_create_claim(self):
}}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})

#wait

response = self.query('''
{
mutationLogs(clientMutationId: "3a90436a-d5ea-48e7-bde4-0bcff0240260")
{
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
id,status,error,clientMutationId,clientMutationLabel,clientMutationDetails,requestDateTime,jsonExt
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})



self.get_mutation_result('3a90436a-d5ea-48e7-bde4-0bcff0240260', self.admin_token )
claim = Claim.objects.filter(code = 'm-c-claim').first()
self.assertIsNotNone(claim)
self.assertEqual(claim.status, Claim.STATUS_ENTERED)

response = self.query(
f'''
mutation {{
updateClaim(
input: {{
clientMutationId: "3a90436b-d5ea-48e7-bde4-0bcff0240260"
clientMutationLabel: "Update Claim - m-c-claim"
code: "m-c-claim"
autogenerate: false
uuid: "{str(claim.uuid)}"
insureeId: {self.insuree.id}
adminId: {self.claim_admin.id}
dateFrom: "2023-11-06"
icdId: 2
jsonExt: "{{}}"
feedbackStatus: 1
reviewStatus: 1
dateClaimed: "2023-12-06"
healthFacilityId: {self.claim_admin.health_facility.id}
visitType: "O"
services: [
{{
serviceId: {self.service.id}
priceAsked: "10.00"
qtyProvided: "1.00"
status: 1,
serviceItemSet: [],
serviceServiceSet: []
}}
]
items: [
]
}}
) {{
clientMutationId
internalId
}}
}}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})
self.get_mutation_result('3a90436b-d5ea-48e7-bde4-0bcff0240260', self.admin_token )

#submit claim
response = self.query(f'''
mutation {{
submitClaims(
input: {{
clientMutationId: "d02fff0a-dd95-4413-a2f6-4cf2189dc0d6"
clientMutationId: "d02fff0a-dd95-4413-a2f4-4cf2189dc0d6"
clientMutationLabel: "Submit claim erterwtw"
uuids: ["{claim.uuid}"]
Expand All @@ -215,7 +232,7 @@ def test_mutation_create_claim(self):
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})
self.assertResponseNoErrors(response)

self.get_mutation_result('d02fff0a-dd95-4413-a2f4-4cf2189dc0d6', self.admin_token )
# select for feeback
claim = Claim.objects.filter(code = 'm-c-claim').first()
create_test_officer(villages=[claim.insuree.family.location])
Expand All @@ -224,7 +241,7 @@ def test_mutation_create_claim(self):
mutation {{
selectClaimsForFeedback(
input: {{
clientMutationId: "f0585e2b-d72d-4001-905a-1cf10e9f1722"
clientMutationId: "f0585e2b-d72d-4001-915a-1cf10e9f1722"
clientMutationLabel: "Select claim sadddfas for feedback"
uuids: ["{claim.uuid}"]
Expand All @@ -237,25 +254,8 @@ def test_mutation_create_claim(self):
''' ,
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})
self.assertResponseNoErrors(response)

self.get_mutation_result('f0585e2b-d72d-4001-915a-1cf10e9f1722', self.admin_token )
## check the mutation answer
response = self.query('''
{
mutationLogs(clientMutationId: "f0585e2b-d72d-4001-905a-1cf10e9f1722")
{
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
id,status,error,clientMutationId,clientMutationLabel,clientMutationDetails,requestDateTime,jsonExt
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"})
self.assertResponseNoErrors(response)

claim = Claim.objects.filter(code = 'm-c-claim').first()
self.assertEqual(claim.feedback_status, Claim.FEEDBACK_SELECTED)
2 changes: 1 addition & 1 deletion claim/test_services.py → claim/tests/tests_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from core.services import create_or_update_interactive_user, create_or_update_core_user
import datetime
from .services import *
from claim.services import *
import core
from medical.test_helpers import create_test_service, create_test_item
from claim.utils import service_create_hook, calcul_amount_service, service_update_hook
Expand Down
78 changes: 41 additions & 37 deletions claim/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import math
from claim.models import Claim, ClaimItem, ClaimService, ClaimDetail, ClaimServiceItem ,ClaimServiceService
from claim.models import Claim, ClaimItem, ClaimService, ClaimDetail, ClaimServiceItem, ClaimServiceService
from medical.models import Item, Service
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
from .apps import ClaimConfig


def process_child_relation(user, data_children, claim_id, children, create_hook):
claimed = 0
from core.utils import TimeUtils
if __check_if_maximum_amount_overshoot(data_children, children):
raise ValidationError(_("mutation.claim_item_service_maximum_amount_overshoot"))
for data_elt in data_children:
if ClaimConfig.native_code_for_services == False:
if create_hook==service_create_hook :
if create_hook == service_create_hook:
claimed += calcul_amount_service(data_elt)
else:
claimed += data_elt['qty_provided'] * data_elt['price_asked']
Expand All @@ -28,7 +29,7 @@ def process_child_relation(user, data_children, claim_id, children, create_hook)
elt.audit_user_id = user.id_for_audit
elt.claim_id = claim_id
elt.validity_to = None
if create_hook==service_create_hook :
if create_hook == service_create_hook:
service_update_hook(elt.claim_id, data_elt)

elt.save()
Expand All @@ -44,9 +45,10 @@ def process_child_relation(user, data_children, claim_id, children, create_hook)

return claimed


def calcul_amount_service(elt):
totalClaimed = elt['price_asked'] * elt['qty_provided']
if len(elt['service_item_set'])!=0 and len(elt['service_service_set'])!=0:
if len(elt['service_item_set']) != 0 and len(elt['service_service_set']) != 0:
totalClaimed = 0
for service_item_set in elt['service_item_set']:
if "qty_asked" in service_item_set:
Expand All @@ -57,7 +59,7 @@ def calcul_amount_service(elt):
if not (math.isnan(service_service_set["qty_asked"])):
totalClaimed += service_service_set['qty_asked'] * service_service_set['price_asked']
return totalClaimed


def __check_if_maximum_amount_overshoot(data_children, children):
is_overshoot = False
Expand Down Expand Up @@ -90,66 +92,68 @@ def service_create_hook(claim_id, service):
service_item_set = service.pop('service_item_set', None)
service_service_set = service.pop('service_service_set', None)
ClaimServiceId = ClaimService.objects.create(claim_id=claim_id, **service)
if(service_item_set):
if (service_item_set):
for serviceL in service_item_set:
if "qty_asked" in serviceL:
if (math.isnan(serviceL["qty_asked"])):
serviceL["qty_asked"] = 0
itemId = Item.objects.filter(code=serviceL["sub_item_code"]).first()
ClaimServiceItem.objects.create(
item = itemId,
claim_service = ClaimServiceId,
qty_displayed = serviceL["qty_asked"],
qty_provided = serviceL["qty_provided"],
price_asked = serviceL["price_asked"],
item=itemId,
claim_service=ClaimServiceId,
qty_displayed=serviceL["qty_asked"],
qty_provided=serviceL["qty_provided"],
price_asked=serviceL["price_asked"],
)

if(service_service_set):
for serviceserviceS in service_service_set:
if "qty_asked" in serviceserviceS :
if (math.isnan(serviceserviceS["qty_asked"])):
serviceserviceS["qty_asked"] = 0
serviceId = Service.objects.filter(code=serviceserviceS["sub_service_code"]).first()
if (service_service_set):
for service_service in service_service_set:
if "qty_asked" in service_service:
if (math.isnan(service_service["qty_asked"])):
service_service["qty_asked"] = 0
serviceId = Service.objects.filter(code=service_service["sub_service_code"]).first()
ClaimServiceService.objects.create(
service = serviceId,
claim_service = ClaimServiceId,
qty_displayed = serviceserviceS["qty_asked"],
qty_provided = serviceserviceS["qty_provided"],
price_asked = serviceserviceS["price_asked"],
service=serviceId,
claim_service=ClaimServiceId,
qty_displayed=service_service["qty_asked"],
qty_provided=service_service["qty_provided"],
price_asked=service_service["price_asked"],
)


def service_update_hook(claim_id, service):
service_item_set = service["service_item_set"]
service_service_set = service["service_service_set"]
service_item_set = service.get("service_item_set")
service_service_set = service.get("service_service_set")
service.pop('service_item_set', None)
service.pop('service_service_set', None)
ClaimServiceId = ClaimService.objects.filter(claim=claim_id, service=service["service_id"]).first()
if(service_item_set):
if (service_item_set):
for serviceL in service_item_set:
if "qty_asked" in serviceL:
if (math.isnan(serviceL["qty_asked"])):
serviceL["qty_asked"] = 0
itemId = Item.objects.filter(code=serviceL["sub_item_code"]).first()
claimServiceItemId = ClaimServiceItem.objects.filter(
item=itemId,
claim_service = ClaimServiceId
claim_service=ClaimServiceId
).first()
claimServiceItemId.qty_displayed=serviceL["qty_asked"]
claimServiceItemId.qty_displayed = serviceL["qty_asked"]
claimServiceItemId.save()

if(service_service_set):
for serviceserviceS in service_service_set:
if "qty_asked" in serviceserviceS:
if (math.isnan(serviceserviceS["qty_asked"])):
serviceserviceS["qty_asked"] = 0
serviceId = Service.objects.filter(code=serviceserviceS["sub_service_code"]).first()
if (service_service_set):
for service_service in service_service_set:
if "qty_asked" in service_service:
if (math.isnan(service_service["qty_asked"])):
service_service["qty_asked"] = 0
serviceId = Service.objects.filter(code=service_service["sub_service_code"]).first()
claimServiceServiceId = ClaimServiceService.objects.filter(
service=serviceId,
claim_service = ClaimServiceId
claim_service=ClaimServiceId
).first()
claimServiceServiceId.qty_displayed=serviceserviceS["qty_asked"]
claimServiceServiceId.qty_displayed = service_service["qty_asked"]
claimServiceServiceId.save()


def process_items_relations(user, claim, items):
return process_child_relation(user, items, claim.id, claim.items, item_create_hook)

Expand All @@ -167,7 +171,7 @@ def autogenerate_nepali_claim_code(config):
code = 0
if last_claim:
code = int(last_claim.latest('code').code[-code_length:])
return prefix + str(code+1).zfill(code_length)
return prefix + str(code + 1).zfill(code_length)


def __get_current_nepali_fiscal_year_code():
Expand All @@ -179,7 +183,7 @@ def __get_current_nepali_fiscal_year_code():
else:
current_year = nepali_datetime.date.today().year

year_code = str(current_year) + "-" + str(current_year+1)[-3:] + "-"
year_code = str(current_year) + "-" + str(current_year + 1)[-3:] + "-"
return year_code


Expand Down

0 comments on commit c8c9aa2

Please sign in to comment.