medicafe 0.250610.0__py3-none-any.whl → 0.250630.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,992 @@
1
+ # MediLink_GraphQL.py
2
+ """
3
+ GraphQL module for United Healthcare Super Connector API
4
+ Handles query templates, query building, and response transformations
5
+ """
6
+
7
+ import json
8
+ from typing import Dict, Any, Optional, List
9
+
10
+ class GraphQLQueryBuilder:
11
+ """Builder class for constructing GraphQL queries for Super Connector API"""
12
+
13
+ @staticmethod
14
+ def get_eligibility_query() -> str:
15
+ """
16
+ Returns the GraphQL query for eligibility checks.
17
+ Based on the Super Connector swagger documentation.
18
+ """
19
+ return """
20
+ query CheckEligibility($input: EligibilityInput!) {
21
+ checkEligibility(input: $input) {
22
+ eligibility {
23
+ eligibilityInfo {
24
+ trnId
25
+ member {
26
+ memberId
27
+ firstName
28
+ lastName
29
+ middleName
30
+ suffix
31
+ dateOfBirth
32
+ gender
33
+ relationship
34
+ relationshipCode
35
+ relationshipTypeCode
36
+ individualRelationshipCode
37
+ dependentSequenceNumber
38
+ }
39
+ contact {
40
+ addresses {
41
+ type
42
+ street1
43
+ street2
44
+ city
45
+ state
46
+ country
47
+ zip
48
+ zip4
49
+ }
50
+ }
51
+ insuranceInfo {
52
+ policyNumber
53
+ eligibilityStartDate
54
+ eligibilityEndDate
55
+ planStartDate
56
+ planEndDate
57
+ policyStatus
58
+ planTypeDescription
59
+ planVariation
60
+ reportingCode
61
+ stateOfIssueCode
62
+ productType
63
+ productId
64
+ productCode
65
+ payerId
66
+ lineOfBusiness
67
+ lineOfBusinessCode
68
+ coverageTypes {
69
+ typeCode
70
+ description
71
+ }
72
+ }
73
+ associatedIds {
74
+ alternateId
75
+ medicaidRecipientId
76
+ exchangeMemberId
77
+ alternateSubscriberId
78
+ hicNumber
79
+ mbiNumber
80
+ subscriberMemberFacingIdentifier
81
+ survivingSpouseId
82
+ subscriberId
83
+ memberReplacementId
84
+ legacyMemberId
85
+ customerAccountIdentifier
86
+ }
87
+ planLevels {
88
+ level
89
+ family {
90
+ networkStatus
91
+ planAmount
92
+ planAmountFrequency
93
+ remainingAmount
94
+ }
95
+ individual {
96
+ networkStatus
97
+ planAmount
98
+ planAmountFrequency
99
+ remainingAmount
100
+ }
101
+ }
102
+ delegatedInfo {
103
+ entity
104
+ payerId
105
+ contact {
106
+ phone
107
+ fax
108
+ email
109
+ }
110
+ addresses {
111
+ type
112
+ street1
113
+ street2
114
+ city
115
+ state
116
+ country
117
+ zip
118
+ zip4
119
+ }
120
+ }
121
+ additionalInfo {
122
+ isReferralRequired
123
+ }
124
+ }
125
+ primaryCarePhysician {
126
+ isPcpFound
127
+ lastName
128
+ firstName
129
+ middleName
130
+ phoneNumber
131
+ address {
132
+ type
133
+ street1
134
+ street2
135
+ city
136
+ state
137
+ country
138
+ zip
139
+ zip4
140
+ }
141
+ networkStatusCode
142
+ affiliateHospitalName
143
+ providerGroupName
144
+ }
145
+ coordinationOfBenefit {
146
+ coordinationOfBenefitDetails {
147
+ payer {
148
+ id
149
+ name
150
+ phoneNumber
151
+ address {
152
+ type
153
+ street1
154
+ street2
155
+ city
156
+ state
157
+ country
158
+ zip
159
+ zip4
160
+ }
161
+ }
162
+ cobPrimacy {
163
+ indicator
164
+ description
165
+ message
166
+ }
167
+ }
168
+ uhgPrimacyStatus {
169
+ policyEffectiveDate
170
+ policyTerminationDate
171
+ primacy {
172
+ indicator
173
+ description
174
+ message
175
+ }
176
+ }
177
+ }
178
+ idCardImages {
179
+ side
180
+ content
181
+ contentType
182
+ }
183
+ providerNetwork {
184
+ status
185
+ tier
186
+ }
187
+ serviceLevels {
188
+ family {
189
+ networkStatus
190
+ services {
191
+ isVendorOnly
192
+ service
193
+ serviceCode
194
+ serviceDate
195
+ text
196
+ status
197
+ coPayAmount
198
+ coPayFrequency
199
+ coInsurancePercent
200
+ planAmount
201
+ remainingAmount
202
+ metYearToDateAmount
203
+ isReferralObtainedCopay
204
+ isReferralObtainedCoInsurance
205
+ referralCopayAmount
206
+ referralCoInsurancePercent
207
+ benefitsAllowedFrequencies
208
+ benefitsRemainingFrequencies
209
+ message {
210
+ note {
211
+ isSingleMessageDetail
212
+ isViewDetail
213
+ messages
214
+ text
215
+ subMessages {
216
+ service
217
+ status
218
+ copay
219
+ msg
220
+ startDate
221
+ endDate
222
+ minCopay
223
+ minCopayMsg
224
+ maxCopay
225
+ maxCopayMsg
226
+ isPrimaryIndicator
227
+ }
228
+ limitationInfo {
229
+ lmtPeriod
230
+ lmtType
231
+ lmtOccurPerPeriod
232
+ lmtDollarPerPeriod
233
+ message
234
+ }
235
+ isMultipleCopaysFound
236
+ isMultipleCoinsuranceFound
237
+ }
238
+ coPay {
239
+ isSingleMessageDetail
240
+ isViewDetail
241
+ messages
242
+ text
243
+ subMessages {
244
+ service
245
+ status
246
+ copay
247
+ msg
248
+ startDate
249
+ endDate
250
+ minCopay
251
+ minCopayMsg
252
+ maxCopay
253
+ maxCopayMsg
254
+ isPrimaryIndicator
255
+ }
256
+ limitationInfo {
257
+ lmtPeriod
258
+ lmtType
259
+ lmtOccurPerPeriod
260
+ lmtDollarPerPeriod
261
+ message
262
+ }
263
+ isMultipleCopaysFound
264
+ isMultipleCoinsuranceFound
265
+ }
266
+ coInsurance {
267
+ isSingleMessageDetail
268
+ isViewDetail
269
+ messages
270
+ text
271
+ subMessages {
272
+ service
273
+ status
274
+ copay
275
+ msg
276
+ startDate
277
+ endDate
278
+ minCopay
279
+ minCopayMsg
280
+ maxCopay
281
+ maxCopayMsg
282
+ isPrimaryIndicator
283
+ }
284
+ limitationInfo {
285
+ lmtPeriod
286
+ lmtType
287
+ lmtOccurPerPeriod
288
+ lmtDollarPerPeriod
289
+ message
290
+ }
291
+ isMultipleCopaysFound
292
+ isMultipleCoinsuranceFound
293
+ }
294
+ deductible {
295
+ isSingleMessageDetail
296
+ isViewDetail
297
+ messages
298
+ text
299
+ subMessages {
300
+ service
301
+ status
302
+ copay
303
+ msg
304
+ startDate
305
+ endDate
306
+ minCopay
307
+ minCopayMsg
308
+ maxCopay
309
+ maxCopayMsg
310
+ isPrimaryIndicator
311
+ }
312
+ limitationInfo {
313
+ lmtPeriod
314
+ lmtType
315
+ lmtOccurPerPeriod
316
+ lmtDollarPerPeriod
317
+ message
318
+ }
319
+ isMultipleCopaysFound
320
+ isMultipleCoinsuranceFound
321
+ }
322
+ benefitsAllowed {
323
+ isSingleMessageDetail
324
+ isViewDetail
325
+ messages
326
+ text
327
+ subMessages {
328
+ service
329
+ status
330
+ copay
331
+ msg
332
+ startDate
333
+ endDate
334
+ minCopay
335
+ minCopayMsg
336
+ maxCopay
337
+ maxCopayMsg
338
+ isPrimaryIndicator
339
+ }
340
+ limitationInfo {
341
+ lmtPeriod
342
+ lmtType
343
+ lmtOccurPerPeriod
344
+ lmtDollarPerPeriod
345
+ message
346
+ }
347
+ isMultipleCopaysFound
348
+ isMultipleCoinsuranceFound
349
+ }
350
+ benefitsRemaining {
351
+ isSingleMessageDetail
352
+ isViewDetail
353
+ messages
354
+ text
355
+ subMessages {
356
+ service
357
+ status
358
+ copay
359
+ msg
360
+ startDate
361
+ endDate
362
+ minCopay
363
+ minCopayMsg
364
+ maxCopay
365
+ maxCopayMsg
366
+ isPrimaryIndicator
367
+ }
368
+ limitationInfo {
369
+ lmtPeriod
370
+ lmtType
371
+ lmtOccurPerPeriod
372
+ lmtDollarPerPeriod
373
+ message
374
+ }
375
+ isMultipleCopaysFound
376
+ isMultipleCoinsuranceFound
377
+ }
378
+ coPayList
379
+ coInsuranceList
380
+ }
381
+ }
382
+ }
383
+ individual {
384
+ networkStatus
385
+ services {
386
+ isVendorOnly
387
+ service
388
+ serviceCode
389
+ serviceDate
390
+ text
391
+ status
392
+ coPayAmount
393
+ coPayFrequency
394
+ coInsurancePercent
395
+ planAmount
396
+ remainingAmount
397
+ metYearToDateAmount
398
+ isReferralObtainedCopay
399
+ isReferralObtainedCoInsurance
400
+ referralCopayAmount
401
+ referralCoInsurancePercent
402
+ benefitsAllowedFrequencies
403
+ benefitsRemainingFrequencies
404
+ message {
405
+ note {
406
+ isSingleMessageDetail
407
+ isViewDetail
408
+ messages
409
+ text
410
+ subMessages {
411
+ service
412
+ status
413
+ copay
414
+ msg
415
+ startDate
416
+ endDate
417
+ minCopay
418
+ minCopayMsg
419
+ maxCopay
420
+ maxCopayMsg
421
+ isPrimaryIndicator
422
+ }
423
+ limitationInfo {
424
+ lmtPeriod
425
+ lmtType
426
+ lmtOccurPerPeriod
427
+ lmtDollarPerPeriod
428
+ message
429
+ }
430
+ isMultipleCopaysFound
431
+ isMultipleCoinsuranceFound
432
+ }
433
+ coPay {
434
+ isSingleMessageDetail
435
+ isViewDetail
436
+ messages
437
+ text
438
+ subMessages {
439
+ service
440
+ status
441
+ copay
442
+ msg
443
+ startDate
444
+ endDate
445
+ minCopay
446
+ minCopayMsg
447
+ maxCopay
448
+ maxCopayMsg
449
+ isPrimaryIndicator
450
+ }
451
+ limitationInfo {
452
+ lmtPeriod
453
+ lmtType
454
+ lmtOccurPerPeriod
455
+ lmtDollarPerPeriod
456
+ message
457
+ }
458
+ isMultipleCopaysFound
459
+ isMultipleCoinsuranceFound
460
+ }
461
+ coInsurance {
462
+ isSingleMessageDetail
463
+ isViewDetail
464
+ messages
465
+ text
466
+ subMessages {
467
+ service
468
+ status
469
+ copay
470
+ msg
471
+ startDate
472
+ endDate
473
+ minCopay
474
+ minCopayMsg
475
+ maxCopay
476
+ maxCopayMsg
477
+ isPrimaryIndicator
478
+ }
479
+ limitationInfo {
480
+ lmtPeriod
481
+ lmtType
482
+ lmtOccurPerPeriod
483
+ lmtDollarPerPeriod
484
+ message
485
+ }
486
+ isMultipleCopaysFound
487
+ isMultipleCoinsuranceFound
488
+ }
489
+ deductible {
490
+ isSingleMessageDetail
491
+ isViewDetail
492
+ messages
493
+ text
494
+ subMessages {
495
+ service
496
+ status
497
+ copay
498
+ msg
499
+ startDate
500
+ endDate
501
+ minCopay
502
+ minCopayMsg
503
+ maxCopay
504
+ maxCopayMsg
505
+ isPrimaryIndicator
506
+ }
507
+ limitationInfo {
508
+ lmtPeriod
509
+ lmtType
510
+ lmtOccurPerPeriod
511
+ lmtDollarPerPeriod
512
+ message
513
+ }
514
+ isMultipleCopaysFound
515
+ isMultipleCoinsuranceFound
516
+ }
517
+ benefitsAllowed {
518
+ isSingleMessageDetail
519
+ isViewDetail
520
+ messages
521
+ text
522
+ subMessages {
523
+ service
524
+ status
525
+ copay
526
+ msg
527
+ startDate
528
+ endDate
529
+ minCopay
530
+ minCopayMsg
531
+ maxCopay
532
+ maxCopayMsg
533
+ isPrimaryIndicator
534
+ }
535
+ limitationInfo {
536
+ lmtPeriod
537
+ lmtType
538
+ lmtOccurPerPeriod
539
+ lmtDollarPerPeriod
540
+ message
541
+ }
542
+ isMultipleCopaysFound
543
+ isMultipleCoinsuranceFound
544
+ }
545
+ benefitsRemaining {
546
+ isSingleMessageDetail
547
+ isViewDetail
548
+ messages
549
+ text
550
+ subMessages {
551
+ service
552
+ status
553
+ copay
554
+ msg
555
+ startDate
556
+ endDate
557
+ minCopay
558
+ minCopayMsg
559
+ maxCopay
560
+ maxCopayMsg
561
+ isPrimaryIndicator
562
+ }
563
+ limitationInfo {
564
+ lmtPeriod
565
+ lmtType
566
+ lmtOccurPerPeriod
567
+ lmtDollarPerPeriod
568
+ message
569
+ }
570
+ isMultipleCopaysFound
571
+ isMultipleCoinsuranceFound
572
+ }
573
+ coPayList
574
+ coInsuranceList
575
+ }
576
+ }
577
+ }
578
+ }
579
+ extendedAttributes {
580
+ fundingCode
581
+ fundingType
582
+ hsa
583
+ cdhp
584
+ governmentProgramCode
585
+ cmsPackageBenefitPlanCode
586
+ cmsSegmentId
587
+ cmsContractId
588
+ marketType
589
+ obligorId
590
+ marketSite
591
+ benefitPlanId
592
+ virtualVisit
593
+ planVariation
594
+ groupNumber
595
+ legacyPanelNumber
596
+ coverageLevel
597
+ sharedArrangement
598
+ productServiceCode
599
+ designatedVirtualClinicNetwork
600
+ medicaidVariableCode
601
+ healthInsuranceExchangeId
602
+ memberDiv
603
+ legalEntityCode
604
+ }
605
+ otherBeneficiaries {
606
+ memberId
607
+ firstName
608
+ lastName
609
+ middleName
610
+ suffix
611
+ dateOfBirth
612
+ gender
613
+ relationship
614
+ relationshipCode
615
+ relationshipTypeCode
616
+ individualRelationshipCode
617
+ dependentSequenceNumber
618
+ }
619
+ }
620
+ }
621
+ }
622
+ """
623
+
624
+ @staticmethod
625
+ def build_eligibility_variables(
626
+ member_id: str,
627
+ first_name: Optional[str] = None,
628
+ last_name: Optional[str] = None,
629
+ date_of_birth: Optional[str] = None,
630
+ service_start_date: Optional[str] = None,
631
+ service_end_date: Optional[str] = None,
632
+ coverage_types: Optional[List[str]] = None,
633
+ payer_id: Optional[str] = None,
634
+ provider_last_name: Optional[str] = None,
635
+ provider_first_name: Optional[str] = None,
636
+ provider_npi: Optional[str] = None,
637
+ group_number: Optional[str] = None,
638
+ trn_id: Optional[str] = None,
639
+ service_level_codes: Optional[List[str]] = None,
640
+ plan_start_date: Optional[str] = None,
641
+ plan_end_date: Optional[str] = None,
642
+ family_indicator: Optional[str] = None
643
+ ) -> Dict[str, Any]:
644
+ """
645
+ Builds the variables object for the eligibility GraphQL query.
646
+
647
+ Args:
648
+ member_id: Unique identifier for the member
649
+ first_name: First name of the member
650
+ last_name: Last name of the member
651
+ date_of_birth: Date of birth in ISO 8601 format (YYYY-MM-DD)
652
+ service_start_date: Start date of the service in ISO 8601 format
653
+ service_end_date: End date of the service in ISO 8601 format
654
+ coverage_types: Types of coverage to include (e.g., ["Medical", "Behavioral"])
655
+ payer_id: Payer identifier
656
+ provider_last_name: Last name of the provider
657
+ provider_first_name: First name of the provider
658
+ provider_npi: National Provider Identifier (NPI) of the provider
659
+ group_number: Group number
660
+ trn_id: Transaction identifier
661
+ service_level_codes: Service level codes (max 10)
662
+ plan_start_date: Start date of the plan in ISO 8601 format
663
+ plan_end_date: End date of the plan in ISO 8601 format
664
+ family_indicator: Indicator for family/individual
665
+
666
+ Returns:
667
+ Dictionary containing the variables for the GraphQL query
668
+ """
669
+ variables = {
670
+ "memberId": member_id
671
+ }
672
+
673
+ # Add optional parameters if provided
674
+ if first_name:
675
+ variables["firstName"] = first_name
676
+ if last_name:
677
+ variables["lastName"] = last_name
678
+ if date_of_birth:
679
+ variables["dateOfBirth"] = date_of_birth
680
+ if service_start_date:
681
+ variables["serviceStartDate"] = service_start_date
682
+ if service_end_date:
683
+ variables["serviceEndDate"] = service_end_date
684
+ if coverage_types:
685
+ variables["coverageTypes"] = coverage_types
686
+ if payer_id:
687
+ variables["payerId"] = payer_id
688
+ if provider_last_name:
689
+ variables["providerLastName"] = provider_last_name
690
+ if provider_first_name:
691
+ variables["providerFirstName"] = provider_first_name
692
+ if provider_npi:
693
+ variables["providerNPI"] = provider_npi
694
+ if group_number:
695
+ variables["groupNumber"] = group_number
696
+ if trn_id:
697
+ variables["trnId"] = trn_id
698
+ if service_level_codes:
699
+ variables["serviceLevelCodes"] = service_level_codes
700
+ if plan_start_date:
701
+ variables["planStartDate"] = plan_start_date
702
+ if plan_end_date:
703
+ variables["planEndDate"] = plan_end_date
704
+ if family_indicator:
705
+ variables["familyIndicator"] = family_indicator
706
+
707
+ return variables
708
+
709
+ @staticmethod
710
+ def build_eligibility_request(variables: Dict[str, Any]) -> Dict[str, Any]:
711
+ """
712
+ Builds the complete GraphQL request body for eligibility checks.
713
+
714
+ Args:
715
+ variables: Variables dictionary for the GraphQL query
716
+
717
+ Returns:
718
+ Complete GraphQL request body
719
+ """
720
+ return {
721
+ "query": GraphQLQueryBuilder.get_eligibility_query(),
722
+ "variables": {
723
+ "input": variables
724
+ }
725
+ }
726
+
727
+ @staticmethod
728
+ def get_sample_eligibility_request() -> Dict[str, Any]:
729
+ """
730
+ Returns the sample GraphQL request from the swagger documentation.
731
+ This is for testing purposes to verify the endpoint is working.
732
+ """
733
+ return {
734
+ "query": "query CheckEligibility($input: EligibilityInput!) { checkEligibility(input: $input) { eligibility { eligibilityInfo { trnId member { memberId firstName lastName middleName suffix dateOfBirth gender relationship relationshipCode relationshipTypeCode individualRelationshipCode dependentSequenceNumber } contact { addresses { type street1 street2 city state country zip zip4 } } insuranceInfo { policyNumber eligibilityStartDate eligibilityEndDate planStartDate planEndDate policyStatus planTypeDescription planVariation reportingCode stateOfIssueCode productType productId productCode payerId lineOfBusiness lineOfBusinessCode coverageTypes { typeCode description } } associatedIds { alternateId medicaidRecipientId exchangeMemberId alternateSubscriberId hicNumber mbiNumber subscriberMemberFacingIdentifier survivingSpouseId subscriberId memberReplacementId legacyMemberId customerAccountIdentifier } planLevels { level family { networkStatus planAmount planAmountFrequency remainingAmount } individual { networkStatus planAmount planAmountFrequency remainingAmount } } delegatedInfo { entity payerId contact { phone fax email } addresses { type street1 street2 city state country zip zip4 } } additionalInfo { isReferralRequired } } primaryCarePhysician { isPcpFound lastName firstName middleName phoneNumber address { type street1 street2 city state country zip zip4 } networkStatusCode affiliateHospitalName providerGroupName } coordinationOfBenefit { coordinationOfBenefitDetails { payer { id name phoneNumber address { type street1 street2 city state country zip zip4 } } cobPrimacy { indicator description message } } uhgPrimacyStatus { policyEffectiveDate policyTerminationDate primacy { indicator description message } } } idCardImages { side content contentType } providerNetwork { status tier } serviceLevels { family { networkStatus services { isVendorOnly service serviceCode serviceDate text status coPayAmount coPayFrequency coInsurancePercent planAmount remainingAmount metYearToDateAmount isReferralObtainedCopay isReferralObtainedCoInsurance referralCopayAmount referralCoInsurancePercent benefitsAllowedFrequencies benefitsRemainingFrequencies message { note { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coPay { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coInsurance { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } deductible { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } benefitsAllowed { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } benefitsRemaining { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coPayList coInsuranceList } } } individual { networkStatus services { isVendorOnly service serviceCode serviceDate text status coPayAmount coPayFrequency coInsurancePercent planAmount remainingAmount metYearToDateAmount isReferralObtainedCopay isReferralObtainedCoInsurance referralCopayAmount referralCoInsurancePercent benefitsAllowedFrequencies benefitsRemainingFrequencies message { note { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coPay { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coInsurance { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } deductible { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } benefitsAllowed { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } benefitsRemaining { isSingleMessageDetail isViewDetail messages text subMessages { service status copay msg startDate endDate minCopay minCopayMsg maxCopay maxCopayMsg isPrimaryIndicator } limitationInfo { lmtPeriod lmtType lmtOccurPerPeriod lmtDollarPerPeriod message } isMultipleCopaysFound isMultipleCoinsuranceFound } coPayList coInsuranceList } } } } extendedAttributes { fundingCode fundingType hsa cdhp governmentProgramCode cmsPackageBenefitPlanCode cmsSegmentId cmsContractId marketType obligorId marketSite benefitPlanId virtualVisit planVariation groupNumber legacyPanelNumber coverageLevel sharedArrangement productServiceCode designatedVirtualClinicNetwork medicaidVariableCode healthInsuranceExchangeId memberDiv legalEntityCode } otherBeneficiaries { memberId firstName lastName middleName suffix dateOfBirth gender relationship relationshipCode relationshipTypeCode individualRelationshipCode dependentSequenceNumber } } } }",
735
+ "variables": {
736
+ "input": {
737
+ "memberId": "0001234567",
738
+ "firstName": "ABC",
739
+ "lastName": "EFGH",
740
+ "dateOfBirth": "YYYY-MM-DD",
741
+ "serviceStartDate": "YYYY-MM-DD",
742
+ "serviceEndDate": "YYYY-MM-DD",
743
+ "coverageTypes": [
744
+ "Medical"
745
+ ],
746
+ "payerId": "12345",
747
+ "providerLastName": "XYZ",
748
+ "providerFirstName": "QWERT",
749
+ "providerNPI": "1234567890"
750
+ }
751
+ }
752
+ }
753
+
754
+ class GraphQLResponseTransformer:
755
+ """Transforms GraphQL responses to match REST API format"""
756
+
757
+ @staticmethod
758
+ def transform_eligibility_response(graphql_response: Dict[str, Any]) -> Dict[str, Any]:
759
+ """
760
+ Transforms the GraphQL eligibility response to match the REST API format.
761
+ This ensures the calling code receives the same structure regardless of endpoint.
762
+
763
+ Args:
764
+ graphql_response: Raw GraphQL response from Super Connector API
765
+
766
+ Returns:
767
+ Transformed response matching REST API format
768
+ """
769
+ try:
770
+ # Check if GraphQL response has data
771
+ if 'data' not in graphql_response or 'checkEligibility' not in graphql_response['data']:
772
+ return {
773
+ 'statuscode': '404',
774
+ 'message': 'No eligibility data found in GraphQL response'
775
+ }
776
+
777
+ eligibility_data = graphql_response['data']['checkEligibility']['eligibility']
778
+ if not eligibility_data:
779
+ return {
780
+ 'statuscode': '404',
781
+ 'message': 'No eligibility records found'
782
+ }
783
+
784
+ # Take the first eligibility record (assuming single member query)
785
+ first_eligibility = eligibility_data[0]
786
+ eligibility_info = first_eligibility.get('eligibilityInfo', {})
787
+
788
+ # Transform to REST-like format
789
+ rest_response = {
790
+ 'statuscode': '200',
791
+ 'message': 'Eligibility found',
792
+ 'rawGraphQLResponse': graphql_response # Include original response for debugging
793
+ }
794
+
795
+ # Safely extract member information
796
+ member_info = eligibility_info.get('member', {})
797
+ if member_info:
798
+ rest_response.update({
799
+ 'memberId': member_info.get('memberId'),
800
+ 'firstName': member_info.get('firstName'),
801
+ 'lastName': member_info.get('lastName'),
802
+ 'middleName': member_info.get('middleName'),
803
+ 'suffix': member_info.get('suffix'),
804
+ 'dateOfBirth': member_info.get('dateOfBirth'),
805
+ 'gender': member_info.get('gender'),
806
+ 'relationship': member_info.get('relationship'),
807
+ 'relationshipCode': member_info.get('relationshipCode'),
808
+ 'individualRelationshipCode': member_info.get('individualRelationshipCode'),
809
+ 'dependentSequenceNumber': member_info.get('dependentSequenceNumber')
810
+ })
811
+
812
+ # Safely extract insurance information
813
+ insurance_info = eligibility_info.get('insuranceInfo', {})
814
+ if insurance_info:
815
+ rest_response.update({
816
+ 'policyNumber': insurance_info.get('policyNumber'),
817
+ 'eligibilityStartDate': insurance_info.get('eligibilityStartDate'),
818
+ 'eligibilityEndDate': insurance_info.get('eligibilityEndDate'),
819
+ 'planStartDate': insurance_info.get('planStartDate'),
820
+ 'planEndDate': insurance_info.get('planEndDate'),
821
+ 'policyStatus': insurance_info.get('policyStatus'),
822
+ 'planTypeDescription': insurance_info.get('planTypeDescription'),
823
+ 'planVariation': insurance_info.get('planVariation'),
824
+ 'reportingCode': insurance_info.get('reportingCode'),
825
+ 'stateOfIssueCode': insurance_info.get('stateOfIssueCode'),
826
+ 'productType': insurance_info.get('productType'),
827
+ 'productId': insurance_info.get('productId'),
828
+ 'productCode': insurance_info.get('productCode'),
829
+ 'lineOfBusiness': insurance_info.get('lineOfBusiness'),
830
+ 'lineOfBusinessCode': insurance_info.get('lineOfBusinessCode'),
831
+ 'coverageTypes': insurance_info.get('coverageTypes', [])
832
+ })
833
+
834
+ # Safely extract associated IDs
835
+ associated_ids = eligibility_info.get('associatedIds', {})
836
+ if associated_ids:
837
+ rest_response.update({
838
+ 'alternateId': associated_ids.get('alternateId'),
839
+ 'medicaidRecipientId': associated_ids.get('medicaidRecipientId'),
840
+ 'exchangeMemberId': associated_ids.get('exchangeMemberId'),
841
+ 'alternateSubscriberId': associated_ids.get('alternateSubscriberId'),
842
+ 'hicNumber': associated_ids.get('hicNumber'),
843
+ 'mbiNumber': associated_ids.get('mbiNumber'),
844
+ 'subscriberMemberFacingIdentifier': associated_ids.get('subscriberMemberFacingIdentifier'),
845
+ 'survivingSpouseId': associated_ids.get('survivingSpouseId'),
846
+ 'subscriberId': associated_ids.get('subscriberId'),
847
+ 'memberReplacementId': associated_ids.get('memberReplacementId'),
848
+ 'legacyMemberId': associated_ids.get('legacyMemberId'),
849
+ 'customerAccountIdentifier': associated_ids.get('customerAccountIdentifier')
850
+ })
851
+
852
+ # Safely extract plan levels
853
+ plan_levels = eligibility_info.get('planLevels', [])
854
+ if plan_levels:
855
+ rest_response['planLevels'] = plan_levels
856
+
857
+ # Safely extract delegated info
858
+ delegated_info = eligibility_info.get('delegatedInfo', [])
859
+ if delegated_info:
860
+ rest_response['delegatedInfo'] = delegated_info
861
+
862
+ # Safely extract additional information
863
+ additional_info = eligibility_info.get('additionalInfo', {})
864
+ if additional_info:
865
+ rest_response['isReferralRequired'] = additional_info.get('isReferralRequired')
866
+
867
+ # Safely extract primary care physician
868
+ pcp = first_eligibility.get('primaryCarePhysician', {})
869
+ if pcp:
870
+ rest_response.update({
871
+ 'pcpIsFound': pcp.get('isPcpFound'),
872
+ 'pcpLastName': pcp.get('lastName'),
873
+ 'pcpFirstName': pcp.get('firstName'),
874
+ 'pcpMiddleName': pcp.get('middleName'),
875
+ 'pcpPhoneNumber': pcp.get('phoneNumber'),
876
+ 'pcpAddress': pcp.get('address'),
877
+ 'pcpNetworkStatusCode': pcp.get('networkStatusCode'),
878
+ 'pcpAffiliateHospitalName': pcp.get('affiliateHospitalName'),
879
+ 'pcpProviderGroupName': pcp.get('providerGroupName')
880
+ })
881
+
882
+ # Safely extract coordination of benefit
883
+ cob = first_eligibility.get('coordinationOfBenefit', {})
884
+ if cob:
885
+ rest_response['coordinationOfBenefit'] = cob
886
+
887
+ # Safely extract ID card images
888
+ id_card_images = first_eligibility.get('idCardImages', [])
889
+ if id_card_images:
890
+ rest_response['idCardImages'] = id_card_images
891
+
892
+ # Safely extract provider network information
893
+ provider_network = first_eligibility.get('providerNetwork', {})
894
+ if provider_network:
895
+ rest_response.update({
896
+ 'networkStatus': provider_network.get('status'),
897
+ 'networkTier': provider_network.get('tier')
898
+ })
899
+
900
+ # Safely extract service levels
901
+ service_levels = first_eligibility.get('serviceLevels', [])
902
+ if service_levels:
903
+ rest_response['serviceLevels'] = service_levels
904
+
905
+ # Extract first service as example for compatibility
906
+ if service_levels and len(service_levels) > 0:
907
+ first_service_level = service_levels[0]
908
+ individual_services = first_service_level.get('individual', [])
909
+ if individual_services and len(individual_services) > 0:
910
+ first_individual = individual_services[0]
911
+ services = first_individual.get('services', [])
912
+ if services and len(services) > 0:
913
+ first_service = services[0]
914
+ rest_response.update({
915
+ 'serviceCode': first_service.get('serviceCode'),
916
+ 'serviceText': first_service.get('text'),
917
+ 'serviceStatus': first_service.get('status'),
918
+ 'coPayAmount': first_service.get('coPayAmount'),
919
+ 'coPayFrequency': first_service.get('coPayFrequency'),
920
+ 'coInsurancePercent': first_service.get('coInsurancePercent'),
921
+ 'planAmount': first_service.get('planAmount'),
922
+ 'remainingAmount': first_service.get('remainingAmount'),
923
+ 'metYearToDateAmount': first_service.get('metYearToDateAmount')
924
+ })
925
+
926
+ # Safely extract extended attributes
927
+ extended_attrs = first_eligibility.get('extendedAttributes', {})
928
+ if extended_attrs:
929
+ rest_response.update({
930
+ 'fundingCode': extended_attrs.get('fundingCode'),
931
+ 'fundingType': extended_attrs.get('fundingType'),
932
+ 'hsa': extended_attrs.get('hsa'),
933
+ 'cdhp': extended_attrs.get('cdhp'),
934
+ 'governmentProgramCode': extended_attrs.get('governmentProgramCode'),
935
+ 'cmsPackageBenefitPlanCode': extended_attrs.get('cmsPackageBenefitPlanCode'),
936
+ 'cmsSegmentId': extended_attrs.get('cmsSegmentId'),
937
+ 'cmsContractId': extended_attrs.get('cmsContractId'),
938
+ 'marketType': extended_attrs.get('marketType'),
939
+ 'obligorId': extended_attrs.get('obligorId'),
940
+ 'marketSite': extended_attrs.get('marketSite'),
941
+ 'benefitPlanId': extended_attrs.get('benefitPlanId'),
942
+ 'virtualVisit': extended_attrs.get('virtualVisit'),
943
+ 'planVariation': extended_attrs.get('planVariation'),
944
+ 'groupNumber': extended_attrs.get('groupNumber'),
945
+ 'legacyPanelNumber': extended_attrs.get('legacyPanelNumber'),
946
+ 'coverageLevel': extended_attrs.get('coverageLevel'),
947
+ 'sharedArrangement': extended_attrs.get('sharedArrangement'),
948
+ 'productServiceCode': extended_attrs.get('productServiceCode'),
949
+ 'designatedVirtualClinicNetwork': extended_attrs.get('designatedVirtualClinicNetwork'),
950
+ 'medicaidVariableCode': extended_attrs.get('medicaidVariableCode'),
951
+ 'healthInsuranceExchangeId': extended_attrs.get('healthInsuranceExchangeId'),
952
+ 'memberDiv': extended_attrs.get('memberDiv'),
953
+ 'legalEntityCode': extended_attrs.get('legalEntityCode')
954
+ })
955
+
956
+ # Safely extract other beneficiaries
957
+ other_beneficiaries = first_eligibility.get('otherBeneficiaries', [])
958
+ if other_beneficiaries:
959
+ rest_response['otherBeneficiaries'] = other_beneficiaries
960
+
961
+ return rest_response
962
+
963
+ except Exception as e:
964
+ # Log the error and the response structure for debugging
965
+ print("Error transforming GraphQL response: {}".format(str(e)))
966
+ print("Response structure: {}".format(json.dumps(graphql_response, indent=2)))
967
+ return {
968
+ 'statuscode': '500',
969
+ 'message': 'Error processing GraphQL response: {}'.format(str(e)),
970
+ 'rawGraphQLResponse': graphql_response
971
+ }
972
+
973
+ # Convenience functions for easy access
974
+ def get_eligibility_query() -> str:
975
+ """Get the eligibility GraphQL query"""
976
+ return GraphQLQueryBuilder.get_eligibility_query()
977
+
978
+ def build_eligibility_variables(**kwargs) -> Dict[str, Any]:
979
+ """Build eligibility query variables"""
980
+ return GraphQLQueryBuilder.build_eligibility_variables(**kwargs)
981
+
982
+ def build_eligibility_request(variables: Dict[str, Any]) -> Dict[str, Any]:
983
+ """Build complete eligibility request body"""
984
+ return GraphQLQueryBuilder.build_eligibility_request(variables)
985
+
986
+ def transform_eligibility_response(graphql_response: Dict[str, Any]) -> Dict[str, Any]:
987
+ """Transform GraphQL eligibility response to REST format"""
988
+ return GraphQLResponseTransformer.transform_eligibility_response(graphql_response)
989
+
990
+ def get_sample_eligibility_request() -> Dict[str, Any]:
991
+ """Get the sample GraphQL request from swagger documentation"""
992
+ return GraphQLQueryBuilder.get_sample_eligibility_request()