77
88import org .json .JSONArray ;
99import org .json .JSONObject ;
10+ import org .openimis .imisclaims .CheckMutationQuery ;
1011import org .openimis .imisclaims .SQLHandler ;
1112import org .openimis .imisclaims .SynchronizeService ;
1213import org .openimis .imisclaims .domain .entity .Claim ;
@@ -26,15 +27,19 @@ public class CreateClaims {
2627
2728 @ NonNull
2829 private final CreateClaimGraphQLRequest createClaimGraphQLRequest ;
30+ @ NonNull
31+ private final CheckMutation checkMutation ;
2932
3033 public CreateClaims () {
31- this (new CreateClaimGraphQLRequest ());
34+ this (new CreateClaimGraphQLRequest (), new CheckMutation () );
3235 }
3336
3437 public CreateClaims (
35- @ NonNull CreateClaimGraphQLRequest createPolicyGraphQLRequest
38+ @ NonNull CreateClaimGraphQLRequest createPolicyGraphQLRequest ,
39+ @ NonNull CheckMutation checkMutation
3640 ) {
3741 this .createClaimGraphQLRequest = createPolicyGraphQLRequest ;
42+ this .checkMutation = checkMutation ;
3843 }
3944
4045 @ WorkerThread
@@ -45,7 +50,7 @@ public List<PostNewClaims.Result> execute(
4550 List <PostNewClaims .Result > results = new ArrayList <>();
4651 SQLHandler sqlHandler = new SQLHandler (context );
4752 for (PendingClaimGQL pendingClaim : claims ){
48- int insureeId = Integer . parseInt ( new FetchInsuree ().execute (pendingClaim .getChfId () ));
53+ int insureeId = new FetchInsuree ().execute (pendingClaim .getChfId ());
4954 int adminId = Integer .parseInt (new FetchClaimAdmin ().execute (pendingClaim .getClaimAdmin ()));
5055 int icdId = new FetchDiagnose ().execute (pendingClaim .getIcdCode ());
5156 int icd1Id = 0 ;
@@ -69,7 +74,18 @@ public List<PostNewClaims.Result> execute(
6974 if (pendingClaim .getReferalHF () != null && !pendingClaim .getReferalHF ().isEmpty ()){
7075 referFromId = Integer .parseInt (sqlHandler .getHfId (pendingClaim .getReferalHF ()));
7176 }
72- results .add (createClaimGraphQLRequest .create (pendingClaim ,Integer .parseInt (hfId ),adminId ,insureeId ,icdId , referFromId , icd1Id , icd2Id , icd3Id , icd4Id ));
77+ CheckMutationQuery .Node response = checkMutation .execute (
78+ createClaimGraphQLRequest .create (pendingClaim ,Integer .parseInt (hfId ),adminId ,insureeId ,icdId , referFromId , icd1Id , icd2Id , icd3Id , icd4Id ),
79+ "Érreur lors de la création de la prestation " + pendingClaim .getClaimCode ()
80+ );
81+
82+ results .add (
83+ new PostNewClaims .Result (
84+ pendingClaim .getClaimCode (),
85+ response .status () != 0 && response .status () == 2 ? PostNewClaims .Result .Status .SUCCESS : PostNewClaims .Result .Status .REJECTED ,
86+ response .status () == 1 ? response .error () : "" )
87+ );
88+
7389 }
7490 return results ;
7591 }
0 commit comments