-
Notifications
You must be signed in to change notification settings - Fork 4
/
X12_835_Export.php
1900 lines (1684 loc) · 68 KB
/
X12_835_Export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
This script is intended to be used as a template for outputting an
ANSI ASC X12.835 Health Care Claim Payment/Advice transaction set ( version: 005010X221 )
Each loop, segment and data element has been documented to a reasonable level.
For detailed information about the X12 835 transaction set set go to www.wpc-edi.com
This is a 'plain vanilla' implementation of the standard.
- Where the data is sourced from an MS SQL database via ODBC
(you will need to change your dataset and field names to match your data source)
(or you can change your data source field names to match this)
- It is based on getting an input dataset containing the following fields:
check__number
check__date
vendor__name
vendor__NPI
vendor__address1
vendor__address2
vendor__city
vendor__state
vendor__zip
claim__id
clm__TotalClaimChargeAmount
clm__ClaimPaymentAmount
clm__copay__amount
clm__coinsurance__amount
clm__deductible
You will need to add more fields to your source dataset if you switch on some of the situational segments that
are currently switched off
- A .txt file is output as 1 continuous string of characters
- You can also change the linefeed switch to make the output file more readable (see PARAMETERS section below)
- Some optional segments have been commented out, some included. You will need to determine which segments are required
to meet your particular business rules.
- Default values have been used throughout.
- Dummy values have been included for many other elements. You will need to replace these with the
specific values for your implementation.
- If there are no errors, and the claim count is greater than zero, a summary email is output
- If there are no errors, and the claim count is zero, a warning email is output
- If there are errors an error email is output
For debugging, uncomment out the echo commands.
*/
/*
NOTE:
Include your database configuration file here if your datasource is a database.
e.g. using an ODBC connection to an MS SQL database
include('config__ODBC.php');
Global $DB;
$DB = str__replace("\"", "", $DB);
$connection_string = odbc_connect($DB,"","");
$sqlquery = "Exec usp__mysqlstoredprocedure";
$process = odbc_exec($connection_string, $sqlquery);
*/
/********** PARAMETERS **********/
// Set filename to the full path and filename of the file to be output.
$filename='C:\\EDI__Test\\X12__835.txt';
// Set linefeed to "\n" to make the output file somewhat 'human readable' by inserting a linefeed between each segment
// or set to "" for production
$linefeed="";
//$linefeed="\n";
/********************************/
/* Message strings for logs/email notifications */
$infomsg="";
$errormsg="";
/* Counts for logs/email summaries */
$check__count=0;
$claim__count=0;
$proc__count=0;
$charges=0;
$net__amount=0;
$total__NumberofIncludedSegments=0;
$X12__835__File = fopen($filename,'w');
/* ************************************************************************************************ */
// ISA - INTERCHANGE CONTROL HEADER
//
// NOTE: All elements of the ISA are REQUIRED
//
$ISA01__AuthorInfoQual="00";
// 00 = No Authorization Information Present (No Meaningful Information in I02)
// 03 = Additional Data Identification
$ISA02__AuthorInformation=" ";
$ISA03__SecurityInfoQual="00";
// 00 = No Security Information Present (No Meaningful Information in I04)
// 03 = Password
$ISA04__SecurityInformation=" ";
$ISA05__InterchangeIDQual="ZZ";
// 01 Duns (Dun & Bradstreet)
// 14 Duns Plus Suffix
// 20 Health Industry Number (HIN) CODE SOURCE 121: Health Industry Number
// 27 Carrier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 28 Fiscal Intermediary Identification Number as assigned by Health Care Financing Administration (HCFA)
// 29 Medicare Provider and Supplier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 30 U.S. Federal Tax Identification Number
// 33 National Association of Insurance Commissioners Company Code (NAIC)
// ZZ Mutually Defined
$ISA06__InterchangeSenderID="XXXXXXXXXXXXXXX";
$ISA07__InterchangeIDQual="ZZ";
// 01 Duns (Dun & Bradstreet)
// 14 Duns Plus Suffix
// 20 Health Industry Number (HIN) CODE SOURCE 121: Health Industry Number
// 27 Carrier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 28 Fiscal Intermediary Identification Number as assigned by Health Care Financing Administration (HCFA)
// 29 Medicare Provider and Supplier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 30 U.S. Federal Tax Identification Number
// 33 National Association of Insurance Commissioners Company Code (NAIC)
// ZZ Mutually Defined
$ISA08__InterchangeReceiverID="XXXXXXXXXXXXXXX";
$ISA09__InterchangeDate=date("ymd");
$ISA10__InterchangeTime=date("hm");
$ISA11__RepetitionSeparator="^";
$ISA12__InterchangeControlVersionNum="00501";
$ISA13__InterchangeControlNumber="0".date("mdHi");
$ISA14__AckRequested="0";
// 0 No Interchange Acknowledgment Requested
// 1 Interchange Acknowledgment Requested (TA1)
$ISA15__UsageIndicator="T";
// P=Production, T=test
$ISA16__ComponentElementSeperator=":";
// echo "__ ISA\n";
fwrite($X12__835__File, "ISA*"
.$ISA01__AuthorInfoQual."*"
.$ISA02__AuthorInformation."*"
.$ISA03__SecurityInfoQual."*"
.$ISA04__SecurityInformation."*"
.$ISA05__InterchangeIDQual."*"
.$ISA06__InterchangeSenderID."*"
.$ISA07__InterchangeIDQual."*"
.$ISA08__InterchangeReceiverID."*"
.$ISA09__InterchangeDate."*"
.$ISA10__InterchangeTime."*"
.$ISA11__RepetitionSeparator."*"
.$ISA12__InterchangeControlVersionNum."*"
.$ISA13__InterchangeControlNumber."*"
.$ISA14__AckRequested."*"
.$ISA15__UsageIndicator."*"
.$ISA16__ComponentElementSeperator
."~".$linefeed);
/* ************************************************************************************************ */
// GS - FUNCTIONAL GROUP HEADER
//
// NOTE: All elements of the GS are REQUIRED
//
$GS01__FunctionalIdentifierCode="HP";
// HP = Health Care Claim Payment/Advice (835)
$GS02__ApplicationSendersCode="123456789012345";
$GS03__ApplicationReceiversCode="123456789012345";
$GS04__Date=date("Ymd");
$GS05__Time=date("hms");
$GS06__GroupControlNumber="123456789";
$GS07__ResponsibleAgencyCode="X";
// X = Accredited Standards Committee X12
$GS08__VersionRelease="005010X221A1";
// 005010X221A1 Standards Approved for Publication by ASC X12 Procedures Review Board through October 2003
// echo "__ GS\n";
fwrite($X12__835__File, "GS*".
$GS01__FunctionalIdentifierCode."*".
$GS02__ApplicationSendersCode."*".
$GS03__ApplicationReceiversCode."*".
$GS04__Date."*".
$GS05__Time."*".
$GS06__GroupControlNumber."*".
$GS07__ResponsibleAgencyCode."*".
$GS08__VersionRelease."~".$linefeed);
/* ************************************************************************************************ */
// There are 3 iteration levels:
// 1. Check number
// 2. Claim number
// 3. Procedure code
$holdCheckNumber="";
$holdClaim__id="";
$holdClaim__procedure__id="";
$claimSeq=1;
$GE01__NumberofTransactionSetsIncluded=0;
$TransactionSetControlNumber=0;
/* ************************************************************************************************ */
// Iterate thru the entire dataset
while(odbc_fetch_row($process))
{
// Control break for Check Number
if($holdCheckNumber=="" || $holdCheckNumber!=odbc_result($process,"check__number"))
{
if($holdCheckNumber!="")
{
// Close out the previous transaction set
/* ************************************************************************************************ */
// PLB - PROVIDER ADJUSTMENT
// $PLB01__ProviderIdentifier="";
// Required
// $PLB02__FiscalPeriodDate="";
// Required
// $PLB03__1__ADJUSTMENTIDENTIFIER="";
// Required
// 50 Late Charge
// 51 Interest Penalty Charge
// 72 Authorized Return
// 90 Early Payment Allowance
// AH Origination Fee
// AM Applied to Borrowers Account
// AP Acceleration of Benefits
// B2 Rebate
// B3 Recovery Allowance
// BD Bad Debt Adjustment
// BN Bonus
// C5 Temporary Allowance
// CR Capitation Interest
// CS Adjustment
// CT Capitation Payment
// CV Capital Passthru
// CW Certified Registered Nurse Anesthetist Passthru
// DM Direct Medical Education Passthru
// E3 Withholding
// FB Forwarding Balance
// FC Fund Allocation
// GO Graduate Medical Education Passthru
// HM Hemophilia Clotting Factor Supplement
// IP Incentive Premium Payment
// IR Internal Revenue Service Withholding
// IS Interim Settlement
// J1 Nonreimbursable
// L3 Penalty
// L6 Interest Owed
// LE Levy
// LS Lump Sum
// OA Organ Acquisition Passthru
// OB Offset for Affiliated Providers
// PI Periodic Interim Payment
// PL Payment Final
// RA Retro-activity Adjustment
// RE Return on Equity
// SL Student Loan Repayment
// TL Third Party Liability
// WO Overpayment Recovery
// WU Unspecified Recovery
// $PLB03__2__ProviderAdjustmentIdentifier="";
// Required
// $PLB04__ProviderAdjustmentAmount="";
// Situational
// $PLB05__1__ADJUSTMENTIDENTIFIER="";
// Situational
// $PLB05__2__ProviderAdjustmentIdentifier="";
// Situational
// $PLB06__ProviderAdjustmentAmount="";
// Situational
// $PLB07__1__ADJUSTMENTIDENTIFIER="";
// Situational
// $PLB07__2__ProviderAdjustmentIdentifier="";
// Situational
// $PLB08__ProviderAdjustmentAmount="";
// Situational
// $PLB09__1__ADJUSTMENTIDENTIFIER="";
// Situational
// $PLB09__2__ProviderAdjustmentIdentifier="";
// Situational
// $PLB10__ProviderAdjustmentAmount="";
// Situational
// $PLB11__1__ADJUSTMENTIDENTIFIER="";
// Situational
// $PLB11__2__ProviderAdjustmentIdentifier="";
// Situational
// $PLB12__ProviderAdjustmentAmount="";
// Situational
// $PLB13__1__ADJUSTMENTIDENTIFIER="";
// Situational
// $PLB13__2__ProviderAdjustmentIdentifier="";
// Situational
// $PLB14__ProviderAdjustmentAmount="";
// Situational
// echo "__ PLB\n";
// fwrite($X12__835__File, "PLB*".
// $PLB01__ProviderIdentifier."*".
// $PLB02__FiscalPeriodDate."*".
// $PLB03__1__ADJUSTMENTIDENTIFIER.":".$PLB03__2__ProviderAdjustmentIdentifier."*".
// $PLB04__ProviderAdjustmentAmount."*".
// $PLB05__1__ADJUSTMENTIDENTIFIER.":".$PLB05__2__ProviderAdjustmentIdentifier."*".
// $PLB06__ProviderAdjustmentAmount."*".
// $PLB07__1__ADJUSTMENTIDENTIFIER.":".$PLB07__2__ProviderAdjustmentIdentifier."*".
// $PLB08__ProviderAdjustmentAmount."*".
// $PLB09__1__ADJUSTMENTIDENTIFIER.":".$PLB09__2__ProviderAdjustmentIdentifier."*".
// $PLB10__ProviderAdjustmentAmount."*".
// $PLB11__1__ADJUSTMENTIDENTIFIER.":".$PLB11__2__ProviderAdjustmentIdentifier."*".
// $PLB12__ProviderAdjustmentAmount."*".
// $PLB13__1__ADJUSTMENTIDENTIFIER.":".$PLB13__2__ProviderAdjustmentIdentifier."*".
// $PLB14__ProviderAdjustmentAmount
// ."~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
// SE - TRANSACTION SET TRAILER
$TransactionSegmentCount++;
$SE01__NumberofIncludedSegments=$TransactionSegmentCount;
$SE02__TransactionSetControlNumber=$ST02__TransactionSetControlNumber;
$GE01__NumberofTransactionSetsIncluded++;
$total__NumberofIncludedSegments+=$TransactionSegmentCount;
// echo "__ SE\n";
fwrite($X12__835__File, "SE*".
$SE01__NumberofIncludedSegments."*".
$SE02__TransactionSetControlNumber.
"~".$linefeed);
}
/* ************************************************************************************************ */
// ST - TRANSACTION SET HEADER
$TransactionSetControlNumber++;
$TransactionSegmentCount=0;
if($TransactionSetControlNumber<1000)
{
if($TransactionSetControlNumber<100)
{
if($TransactionSetControlNumber<10)
{ $ST02__TransactionSetControlNumber="000".$TransactionSetControlNumber; }
else
{ $ST02__TransactionSetControlNumber="00".$TransactionSetControlNumber; }
}
else
{ $ST02__TransactionSetControlNumber="0".$TransactionSetControlNumber; }
}
else
{ $ST02__TransactionSetControlNumber=$TransactionSetControlNumber; }
// echo "__ ST\n";
$check__count++;
fwrite($X12__835__File, "ST*835*".
$ST02__TransactionSetControlNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// BPR - FINANCIAL INFORMATION
if(odbc_result($process,"vendor__net__amount")<=0)
{
$errormsg.="BPR02 Provider net amount <= $0: "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
if(odbc_result($process,"check__date")=="" || odbc_result($process,"check__date")==null)
{
$errormsg.="BPR16 Provider check date is missing: "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
/* Outputs a line per vendor check */
$infomsg.="<tr>";
$infomsg.="<td>".odbc_result($process,"check__number")."</td>";
$infomsg.="<td>".odbc_result($process,"vendor__name")."</td>";
$infomsg.="<td style=\"text-align:right;\">$".number_format(odbc_result($process,"vendor__charges"),2)."</td>";
$infomsg.="<td style=\"text-align:right;\">$".number_format(odbc_result($process,"vendor__net__amount"),2)."</td>";
$infomsg.="<td style=\"text-align:right;\">".number_format(odbc_result($process,"vendor__claim__count"))."</td>";
$infomsg.="<td style=\"text-align:right;\">".number_format(odbc_result($process,"vendor__proc__count"))."</td>";
$infomsg.="</tr>";
$BPR01__TransactionHandlingCode="C";
// Required
// C Payment Accompanies Remittance Advice
// D Make Payment Only
// H Notification Only
// I Remittance Information Only
// P Prenotification of Future Transfers
// U Split Payment and Remittance
// X Handling Partys Option to Split Payment and Remittance
$BPR02__TotalActualProviderPaymentAmount=number_format(odbc_result($process,"vendor__net__amount"),2,'.','');
$BPR03__CreditDebitFlag="C";
// Required
// C Credit
// D Debit
$BPR04__PaymentMethodCode="BOP";
// Required
// ACH Automated Clearing House (ACH)
// BOP Financial Institution Option
// CHK Check
// FWT Federal Reserve Funds/Wire Transfer - Nonrepetitive
// Non-Payment Data
$BPR05__PaymentFormatCode="";
// Situational
// CCP Cash Concentration/Disbursement plus Addenda (CCD+) (ACH)
// CTX Corporate Trade Exchange (CTX) (ACH)
$BPR06__DepositoryFinancialInstitutionQualifier="01";
// Situational
// 01 ABA Transit Routing Number Including Check Digits (9 digits)
// 04 Canadian Bank Branch and Institution Number
$BPR07__DFI__ID="99999999";
// Situational
$BPR08__AccountNoQualifier="DA";
// Situational
// DA Demand Deposit
$BPR09__SenderBankAccountNo="483021811769";
// Situational
$BPR10__OriginatingCompanyIdent="1"."205038398"; //USI Tax ID
// Situational
$BPR11__OriginatingCompanySupplementalCode="";
// Situational
$BPR12__IDNumberQualifier="01";
// Situational
// 01 ABA Transit Routing Number Including Check Digits (9 digits)
// 04 Canadian Bank Branch and Institution Number
$BPR13__IdentificationNumber="0012345678"; //??
// Situational
$BPR14__AccountNumberQualifier="DA"; //??
// Situational
// DA Demand Deposit
// SG Savings
$BPR15__AccountNumber="0012345678"; //??
// Situational
$BPR16__checkIssueDate=substr(odbc_result($process,"check__date"),0,4)
.substr(odbc_result($process,"check__date"),5,2)
.substr(odbc_result($process,"check__date"),8,2);
// Situational
fwrite($X12__835__File, "BPR*".
$BPR01__TransactionHandlingCode."*".
$BPR02__TotalActualProviderPaymentAmount."*".
$BPR03__CreditDebitFlag."*".
$BPR04__PaymentMethodCode."*".
$BPR05__PaymentFormatCode."*".
$BPR06__DepositoryFinancialInstitutionQualifier."*".
$BPR07__DFI__ID."*".
$BPR08__AccountNoQualifier."*".
$BPR09__SenderBankAccountNo."*".
$BPR10__OriginatingCompanyIdent."*".
$BPR11__OriginatingCompanySupplementalCode."*".
$BPR12__IDNumberQualifier."*".
$BPR13__IdentificationNumber."*".
$BPR14__AccountNumberQualifier."*".
$BPR15__AccountNumber."*".
$BPR16__checkIssueDate."~".$linefeed);
$TransactionSegmentCount++;
// echo "__ BPR\n";
/* ************************************************************************************************ */
// TRN - REASSOCIATION TRACE NUMBER
if(odbc_result($process,"check__number")=="" || odbc_result($process,"check__number")==null)
{
$errormsg.="TRN Provider check number is missing: "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
$TRN01__TraceTypeCode="1";
// Required
// 1 Current Transaction Trace Numbers
$TRN02__ReferenceIdent=odbc_result($process,"check__number");
// Required
$TRN03__OriginatingCompanyIdent="1"."987654321";
// Required
$TRN04__Reference__Id="";
// Situational
// echo "__ TRN\n";
fwrite($X12__835__File, "TRN*".
$TRN01__TraceTypeCode."*".
$TRN02__ReferenceIdent."*".
$TRN03__OriginatingCompanyIdent."~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// CUR - FOREIGN CURRENCY INFORMATION
// $CUR01__EntityIdentifierCode="PR";
// Required
// PR Payer
// $CUR02__CurrencyCode="USD";
// Required
// Standard ISO currency code
// e.g. USD US Dollars
// echo "__ CUR*PR\n";
// fwrite($X12__835__File, "CUR*".
// $CUR01__EntityIdentifierCode."*".
// $CUR02__CurrencyCode.
// ."~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - RECEIVER IDENTIFICATION
// $REF01__ReferenceIdentificationQualifier="EV";
// Required
// EV Receiver Identification Number
// $REF02__ReferenceIdentification="";
// Required
// echo "__ REF*EV\n";
// fwrite($X12__835__File, "REF*".
// $REF01__ReferenceIdentificationQualifier."*".
// $REF02__ReferenceIdentification.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - VERSION IDENTIFICATION
// $REF01__ReferenceIdentificationQualifier="F2";
// Required
// F2 Version Code - Local
// $REF02__ReferenceIdentification="";
// Required
// echo "__ REF*F2\n";
// fwrite($X12__835__File, "REF*".
// $REF01__ReferenceIdentificationQualifier."*".
// $REF02__ReferenceIdentification.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
// DTM - PRODUCTION DATE
$DTM01__DateTimeQualifier="405";
// Required
// 405 Production
$DTM02__ProductionDate=date("Ymd");
// Required
// echo "__ DTM\n";
fwrite($X12__835__File, "DTM*".
$DTM01__DateTimeQualifier."*".
$DTM02__ProductionDate.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N1 - Loop 1000A - PAYER IDENTIFICATION
$N101__EntityIdentifierCode="PR";
// Required
// PR Payer
$N102__PayerName="Paying Company Name";
// Required
// echo "1000A N1\n";
fwrite($X12__835__File, "N1*".
$N101__EntityIdentifierCode."*".
$N102__PayerName.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
//N3 - Loop 1000A - PAYER ADDRESS
$N301__AddressLine1="777 Main Street";
// Required
$N302__AddressLine2="13th Floor";
// Situational
// echo "1000A N3\n";
if($N302__AddressLine2=="")
{ fwrite($X12__835__File, "N3*".$N301__AddressLine1."~".$linefeed); }
else
{ fwrite($X12__835__File, "N3*".$N301__AddressLine1."*".$N302__AddressLine2."~".$linefeed); }
$TransactionSegmentCount++;
/* ************************************************************************************************ */
//N4 - Loop 1000A - PAYER CITY, STATE, ZIP CODE
$N401__city="New York";
// Required
$N402__state="NY";
// Required
$N403__zip="10001";
// Required
// $N404__country__code="";
// Situational
// Use the alpha-2 country codes from Part 1 of ISO 3166
// $N405__location__qualifier="";
// Not used
// $N406__location__identifier="";
// Not used
// $N407__country__subdivision__code="";
// Situational
// Use the country subdivision codes from Part 2 of ISO 3166.
// echo "1000A N4\n";
fwrite($X12__835__File, "N4*".
$N401__city."*".
$N402__state."*".
$N403__zip.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
//REF - Loop 1000A - ADDITIONAL PAYER IDENTIFICATION
// $REF01__ReferenceIdentificationQualifier="HI";
// Required
// 2U Payer Identification Number
// EO Submitter Identification Number
// HI Health Industry Number (HIN)
// NF National Association of Insurance Commissioners (NAIC) Code
// $REF02__ReferenceIdentification="12345678";
// Required
// echo "1000A REF*HI\n";
// fwrite($X12__835__File, "REF*".$REF01__ReferenceIdentificationQualifier."*".$REF02__ReferenceIdentification."~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
//PER - Loop 1000A - PAYER Business Contact Information
// $PER01__ContactFunctionCode="CX";
// Required
// CX Payers Claim Office
// $PER02__Name="John Doe";
// Situational
// $PER03__CommunicationNumberQualifier="TE";
// Situational
// EM Electronic Mail
// FX Facsimile
// TE Telephone
// $PER04__CommunicationNumber="2125551234";
// Situational
// $PER05__CommunicationNumberQualifier="FX";
// Situational
// EM Electronic Mail
// EX Telephone Extension
// FX Facsimile
// TE Telephone
// $PER06__CommunicationNumber="2125551235";
// Situational
// $PER07__CommunicationNumberQualifier="FX";
// Situational
// EX Telephone Extension
// $PER08__CommunicationNumber="555";
// Situational
// echo "1000A PER*CX\n";
// fwrite($X12__835__File, "PER*".
// $PER01__ContactFunctionCode."*".
// $PER02__Name."*".
// $PER03__CommunicationNumberQualifier."*".
// $PER04__CommunicationNumber."*".
// $PER05__CommunicationNumberQualifier."*".
// $PER06__CommunicationNumber."*".
// $PER07__CommunicationNumberQualifier."*".
// $PER08__CommunicationNumber.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
//PER - Loop 1000A - PAYER TECHNICAL CONTACT INFORMATION
// $PER01__ContactFunctionCode="BL";
// Required
// BL Technical Department
// $PER02__Name="Jane Doe";
// Situational
// $PER03__CommunicationNumberQualifier="TE";
// Situational
// EM Electronic Mail
// FX Facsimile
// TE Telephone
// $PER04__CommunicationNumber="2125551234";
// Situational
// $PER05__CommunicationNumberQualifier="FX";
// Situational
// EM Electronic Mail
// EX Telephone Extension
// FX Facsimile
// TE Telephone
// $PER06__CommunicationNumber="2125551235";
// Situational
// $PER07__CommunicationNumberQualifier="FX";
// Situational
// EX Telephone Extension
// $PER08__CommunicationNumber="555";
// Situational
// echo "1000A PER*CX\n";
// fwrite($X12__835__File, "PER*".
// $PER01__ContactFunctionCode."*".
// $PER02__Name."*".
// $PER03__CommunicationNumberQualifier."*".
// $PER04__CommunicationNumber."*".
// $PER05__CommunicationNumberQualifier."*".
// $PER06__CommunicationNumber."*".
// $PER07__CommunicationNumberQualifier."*".
// $PER08__CommunicationNumber.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
//PER - Loop 1000A - PAYER WEB SITE
// $PER01__ContactFunctionCode="IC";
// Required
// IC Information Contact
// $PER02__Name="";
// Not Used
// $PER03__CommunicationNumberQualifier="UR";
// Required
// UR Uniform Resource Locator (URL)
// $PER04__CommunicationNumber="mywebsite@address.com";
// Situational
// echo "1000A PER*CX\n";
// fwrite($X12__835__File, "PER*".
// $PER01__ContactFunctionCode."*".
// $PER02__Name."*".
// $PER03__CommunicationNumberQualifier."*".
// $PER04__CommunicationNumber.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
//N1 - Loop 1000B - PAYEE IDENTIFICATION
if(odbc_result($process,"vendor__name")=="")
{
$errormsg.="1000B N102 Provider name missing: "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
if(odbc_result($process,"vendor__NPI")=="" || !is__numeric(substr(odbc_result($process,"vendor__NPI"),0,10)))
{
$errormsg.="1000B N104 Provider NPI missing or in incorrect format: "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
$N101__EntityIdentifierCode="PE";
// Required
// PE Payee
$N102__PayeeName=substr(odbc_result($process,"vendor__name"),0,80);
// Required
$N103__IdentificationCodeQualifier="XX";
// Required
// FI Federal Taxpayers Identification Number
// XV Centers for Medicare and Medicaid Services PlanID
// XX Centers for Medicare and Medicaid Services National Provider Identifier
$N104__PayeeID=substr(odbc_result($process,"vendor__NPI"),0,10);
// Required
// echo "1000B N1\n";
fwrite($X12__835__File, "N1*".
$N101__EntityIdentifierCode."*".
$N102__PayeeName."*".
$N103__IdentificationCodeQualifier."*".
$N104__PayeeID.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
//N3 - Loop 1000B - PAYEE ADDRESS
if(odbc_result($process,"vendor__address1")=="")
{
$errormsg.="1000B N301 Provider address missing address line: "
.odbc_result($process,"vendor__address1")." - "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
$N301__AddressLine1=odbc_result($process,"vendor__address1");
// Required
$N302__AddressLine2=odbc_result($process,"vendor__address2");
// Situational
// echo "1000B N3\n";
if($N302__AddressLine2=="")
{ fwrite($X12__835__File, "N3*".$N301__AddressLine1."~".$linefeed); }
else
{ fwrite($X12__835__File, "N3*".$N301__AddressLine1."*".$N302__AddressLine2."~".$linefeed); }
$TransactionSegmentCount++;
/* ************************************************************************************************ */
//N4 - Loop 1000B - PAYEE CITY, STATE, ZIP CODE
if(odbc_result($process,"vendor__city")=="" ||odbc_result($process,"vendor__state")=="" ||odbc_result($process,"vendor__zipcode")=="")
{
$errormsg.="1000B N401 N402 N403 Provider address missing city, state or zip: "
.odbc_result($process,"vendor__city").","
.odbc_result($process,"vendor__state")." "
.odbc_result($process,"vendor__zipcode")." - "
.odbc_result($process,"vendor__name")
." [".odbc_result($process,"vendor__NPI")."]<br />";
}
$N401__city=odbc_result($process,"vendor__city");
// Required
$N402__state=odbc_result($process,"vendor__state");
// Required
$N403__zip=odbc_result($process,"vendor__zipcode");
// Required
// $N404__country__code="";
// Situational
// Use the alpha-2 country codes from Part 1 of ISO 3166
// $N405__location__qualifier="";
// Not used
// $N406__location__identifier="";
// Not used
// $N407__country__subdivision__code="";
// Situational
// Use the country subdivision codes from Part 2 of ISO 3166.
// echo "1000B N4\n";
fwrite($X12__835__File, "N4*".
$N401__city."*".
$N402__state."*".
$N403__zip.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
$holdCheckNumber=odbc_result($process,"check__number");
}
//*********************
// CLAIM HEADER
//*********************
if($holdClaim__id=="" || $holdClaim__id!=odbc_result($process,"claim__id"))
{
/* ************************************************************************************************ */
// LX - LOOP 2000 - HEADER NUMBER
$LX01__AssignedNumber=$claimSeq;
// Required
// echo "2000 LX\n";
fwrite($X12__835__File, "LX*".
$LX01__AssignedNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// TS3 - PROVIDER SUMMARY INFORMATION
// $TS301__ProviderIdentifier="";
// Required
// $TS302__FacilityTypeCode="";
// Required
// $TS303__FiscalPeriodDate="";
// Required
// $TS304__TotalClaimCount="";
// Required
// $TS305__TotalClaimChargeAmount="";
// Required
// $TS306__MonetaryAmount="";
// Not used
// $TS307__MonetaryAmount="";
// Not used
// $TS308__MonetaryAmount="";
// Not used
// $TS309__MonetaryAmount="";
// Not used
// $TS310__MonetaryAmount="";
// Not used
// $TS311__MonetaryAmount="";
// Not used
// $TS312__MonetaryAmount="";
// Not used
// $TS313__TotalMSPPayerAmount="";
// Situational
// $TS314__MonetaryAmount="";
// Not used
// $TS315__TotalNonLabChargeAmount="";
// Situational
// $TS316__MonetaryAmount="";
// Not used
// $TS317__TotalHCPCSReportedChargeAmount="";
// Situational
// $TS318__TotalHCPCSPayableAmount="";
// Situational
// $TS319__MonetaryAmount="";
// Not used
// $TS320__TotalProfessionalComponentAmount="";
// Situational
// $TS321__TotalMSPPatientLiabilityMetAmount="";
// Situational
// $TS322__TotalPatientReimbursementAmount="";
// Situational
// $TS323__TotalPIPClaimCount="";
// Situational
// $TS324__TotalPIPAdjustmentAmount="";
// Situational
// echo "2000 TS3\n";
// fwrite($X12__835__File, "TS3*".
// $TS301__ProviderIdentifier."*".
// $TS302__FacilityTypeCode."*".
// $TS303__FiscalPeriodDate."*".
// $TS304__TotalClaimCount."*".
// $TS306__MonetaryAmount."*".
// $TS307__MonetaryAmount."*".
// $TS308__MonetaryAmount."*".
// $TS309__MonetaryAmount."*".
// $TS310__MonetaryAmount."*".
// $TS311__MonetaryAmount."*".
// $TS312__MonetaryAmount."*".
// $TS313__TotalMSPPayerAmount."*".
// $TS314__MonetaryAmount."*".
// $TS315__TotalNonLabChargeAmount."*".
// $TS316__MonetaryAmount."*".
// $TS317__TotalHCPCSReportedChargeAmount."*".
// $TS318__TotalHCPCSPayableAmount."*".
// $TS319__MonetaryAmount."*".
// $TS320__TotalProfessionalComponentAmount."*".
// $TS321__TotalMSPPatientLiabilityMetAmount."*".
// $TS322__TotalPatientReimbursementAmount."*".
// $TS323__TotalPIPClaimCount."*".
// $TS324__TotalPIPAdjustmentAmount.
// "~".$linefeed);
// $TransactionSegmentCount++;
/* ************************************************************************************************ */
// TS2 - PROVIDER SUPPLEMENTAL SUMMARY INFORMATION
// $TS201__TotalDRGAmount="";
// Situational
// $TS202__TotalFederalSpecificAmount="";
// Situational
// $TS203__TotalHospitalSpecificAmount="";
// Situational
// $TS204__TotalDisproportionateShareAmount="";
// Situational
// $TS205__TotalCapitalAmount="";
// Situational
// $TS206__TotalIndirectMedicalEducationAmount="";
// Situational
// $TS207__TotalOutlierDayCount="";
// Situational
// $TS208__TotalDayOutlierAmount="";
// Situational
// $TS209__TotalCostOutlierAmount="";
// Situational
// $TS210__AverageDRGLengthofStay="";
// Situational
// $TS211__TotalDischargeCount="";
// Situational
// $TS212__TotalCostReportDayCount="";
// Situational
// $TS213__TotalCoveredDayCount="";
// Situational
// $TS214__TotalNoncoveredDayCount="";
// Situational
// $TS215__TotalMSPPassThroughAmount="";
// Situational
// $TS216__AverageDRGweight="";
// Situational
// $TS217__TotalPPSCapitalFSPDRGAmount="";
// Situational
// $TS218__TotalPPSCapitalHSPDRGAmount="";
// Situational
// $TS219__TotalPPSDSHDRGAmount="";
// Situational
// echo "2000 TS3\n";
// fwrite($X12__835__File, "TS3*".
// $TS201__TotalDRGAmount."*".
// $TS202__TotalFederalSpecificAmount."*".
// $TS203__TotalHospitalSpecificAmount."*".
// $TS204__TotalDisproportionateShareAmount."*".
// $TS205__TotalCapitalAmount."*".
// $TS206__TotalIndirectMedicalEducationAmount."*".
// $TS207__TotalOutlierDayCount."*".
// $TS208__TotalDayOutlierAmount."*".
// $TS209__TotalCostOutlierAmount."*".
// $TS210__AverageDRGLengthofStay."*".
// $TS211__TotalDischargeCount."*".
// $TS212__TotalCostReportDayCount."*".
// $TS213__TotalCoveredDayCount."*".
// $TS214__TotalNoncoveredDayCount."*".
// $TS215__TotalMSPPassThroughAmount."*".