2424from graphene_django .utils .testing import GraphQLTestCase
2525from claim_sampling import schema as claim_schema
2626from graphene .test import Client
27-
28-
27+ from policy .test_helpers import create_test_policy2
28+ from product .test_helpers import create_test_product , create_test_product_service , create_test_product_item
29+ from medical_pricelist .test_helpers import add_service_to_hf_pricelist , add_item_to_hf_pricelist
30+ from product .models import ProductItemOrService
31+ from datetime import date , timedelta , datetime
2932class ClaimSubmitServiceTestCase (GraphQLTestCase ):
3033 GRAPHQL_URL = f'/{ settings .SITE_ROOT ()} graphql'
3134 # This is required by some version of graphene but is never used. It should be set to the schema but the import
@@ -50,9 +53,9 @@ class ClaimSubmitServiceTestCase(GraphQLTestCase):
5053
5154 test_claims = []
5255
56+
5357 @classmethod
54- def setUpClass (cls ):
55- super ().setUpClass ()
58+ def setUpTestData (cls ):
5659 cls .admin_user = create_test_interactive_user (username = "testLocationAdmin" )
5760 cls .admin_token = get_token (cls .admin_user , DummyContext (user = cls .admin_user ))
5861 cls .schema = Schema (
@@ -63,8 +66,6 @@ def setUpClass(cls):
6366
6467 cls .officer = create_test_officer (custom_props = {"code" : "TSTSIMP1" })
6568
66- @classmethod
67- def setUpTestData (cls ):
6869 if cls .test_region is None :
6970 cls .test_village = create_test_village ()
7071 cls .test_ward = cls .test_village .parent
@@ -82,35 +83,56 @@ def setUpTestData(cls):
8283 location = cls .test_village ,
8384 )
8485 cls .test_insuree = create_test_insuree (is_head = True , custom_props = props , family_custom_props = family_props )
86+ product = create_test_product ("TEST_CLM" )
87+ cls .test_policy , ip = create_test_policy2 (product , cls .test_insuree )
8588 cls .test_claim_admin = create_test_claim_admin ()
8689 cls .test_icd = Diagnosis (code = 'ICD00I' , name = 'diag test' , audit_user_id = - 1 )
8790 cls .test_icd .save ()
8891
89- cls ._create_test_claims ()
92+ cls ._create_test_claims (cls .test_policy .product )
93+
9094
9195 @classmethod
92- def _create_test_claims (cls ):
96+ def _create_test_claims (cls , product ):
97+ configdate = datetime .now () - timedelta (days = 265 )
98+
9399 test_item = create_test_item (
94100 'D' ,
95- custom_props = {"code" : "cCode " , "price" : 1000 }
101+ custom_props = {"code" : "csamCo " , "price" : 1000 }
96102 )
97103 test_service = create_test_service (
98104 'D' ,
99- custom_props = {"code" : "sCode" , "price" : 1000 }
105+ custom_props = {"code" : "ssamCo" , "price" : 1000 }
106+ )
107+ create_test_product_service (
108+ product ,
109+ test_service ,
110+ custom_props = {"price_origin" : ProductItemOrService .ORIGIN_RELATIVE },
100111 )
112+ create_test_product_item (
113+ product ,
114+ test_item ,
115+ custom_props = {"price_origin" : ProductItemOrService .ORIGIN_RELATIVE },
116+ )
117+ add_service_to_hf_pricelist (test_service , hf_id = cls .test_hf .id )
118+ add_item_to_hf_pricelist (test_item , hf_id = cls .test_hf .id )
119+
120+ dateclaim = date .today () - timedelta (days = 5 )
121+ datetimeclaim = datetime .now () - timedelta (days = 5 )
101122 for i in range (10 ):
102123 claim = Claim .objects .create (
103- date_claimed = core . datetime . date ( 2024 , 1 , 15 ) ,
124+ date_claimed = dateclaim ,
104125 code = F"code_ABV{ i } " ,
105126 icd = cls .test_icd ,
106127 claimed = 2000 ,
107- date_from = core . datetime . date ( 2024 , 1 , 13 ) ,
108- date_to = core . datetime . date ( 2024 , 1 , 15 ) ,
128+ date_from = dateclaim ,
129+ date_to = None ,
109130 admin = cls .test_claim_admin ,
110131 insuree = cls .test_insuree ,
111132 health_facility = cls .test_hf ,
112133 status = Claim .STATUS_ENTERED ,
113- audit_user_id = - 1
134+ audit_user_id = - 1 ,
135+ validity_from = datetimeclaim
114136 )
115137 claim_item = ClaimItem .objects .create (
116138 claim = claim ,
@@ -119,53 +141,46 @@ def _create_test_claims(cls):
119141 qty_provided = 1 ,
120142 audit_user_id = - 1 ,
121143 status = ClaimDetail .STATUS_PASSED ,
122- availability = True
144+ availability = True ,
145+ validity_from = datetimeclaim
123146 )
124147 claim_service = ClaimService .objects .create (
125148 claim = claim ,
126149 service = test_service ,
127150 price_asked = 1000 ,
128151 qty_provided = 1 ,
129152 audit_user_id = - 1 ,
130- status = ClaimDetail .STATUS_PASSED
153+ status = ClaimDetail .STATUS_PASSED ,
154+ validity_from = datetimeclaim
131155 )
132-
133- mark_test_claim_as_processed (claim )
156+ claim . refresh_from_db ()
157+ ClaimSubmitService ( cls . admin_user ). submit_claim (claim )
134158 cls .test_claims .append (claim )
135-
159+
136160 @classmethod
137161 def _set_claim_as_valuated (cls , claim , user , is_process = False ):
138162 # Mock of dedrem
139163 claim .status = Claim .STATUS_PROCESSED
140164 claim .save ()
141165 return []
142166
143- @mock .patch ("claim.services.validate_claim" )
144- @mock .patch ("claim.services.process_dedrem" )
145- @mock .patch ("claim.services.validate_assign_prod_to_claimitems_and_services" )
146- def test_mutation_create_claim (
147- self ,
148- validate_claim ,
149- process_dedrem ,
150- validate_assign_prod_to_claimitems_and_services ):
151- validate_claim .return_value = []
152- process_dedrem .side_effect = self ._set_claim_as_valuated
153- validate_assign_prod_to_claimitems_and_services .return_value = []
167+ def test_mutation_create_claim ( self ):
168+
154169 percentage_for_sample = 20
155- response = self .query ('''
156- mutation {
170+ response = self .query (f '''
171+ mutation {{
157172 createClaimSamplingBatch(
158- input: {
173+ input: {{
159174 clientMutationId: "fdcc211f-7225-4f0e-8a66-11223344667d"
160175 clientMutationLabel: "Create Claim Sampling Batch"
161176 percentage: 30
162- filters: "{\\ "status\\ ":4, \\ "dateFrom\\ ": \\ "2024-01-13 \\ "}"
163- }
164- ) {
177+ filters: "{{ \\ "status\\ ":4, \\ "dateFrom\\ ": \\ "{ date . today () - timedelta ( days = 5 ) } \\ "} }"
178+ }}
179+ ) {{
165180 clientMutationId
166181 internalId
167- }
168- }
182+ }}
183+ }}
169184 ''' , headers = {"HTTP_AUTHORIZATION" : f"Bearer { self .admin_token } " })
170185
171186 claim_sampling = ClaimSamplingBatch .objects .first ()
@@ -202,16 +217,18 @@ def test_mutation_create_claim(
202217 self .assertEqual (rejected_from_review .count (), 2 )
203218 self .assertEqual (reviewed_delivered .count (), 3 )
204219 self .assertEqual (total , 3 )
220+ datetimeclaim = datetime .now () - timedelta (days = 5 )
205221
206222 # Extrapolation
207223 service .extrapolate_results (claim_sampling .id )
208224 attachments = ClaimSamplingBatchAssignment .objects .filter (claim_batch = claim_sampling )
209225 # 50% of remaining claims should be rejected and 50% should be valuated
210226 skip = [x .claim for x in attachments .filter (status = ClaimSamplingBatchAssignmentStatus .SKIPPED )]
211- accepted = [x for x in skip if x .status in [Claim .STATUS_PROCESSED , Claim .STATUS_VALUATED ]]
227+ accepted = [x for x in skip if x .status in [ Claim .STATUS_PROCESSED , Claim .STATUS_VALUATED ]]
212228 rejected = [x for x in skip if x .status in [Claim .STATUS_REJECTED ]]
213229 self .assertEqual (len (accepted ), 7 )
214230 self .assertEqual (len (rejected ), 0 )
231+
215232 # FIXME check the ratio (done manually looks ok)
216233
217234
0 commit comments