IBCE277S ;ALB/JRA - Create MailMan message from 277STAT data array
;;2.0;INTEGRATED BILLING;**650,665**;17-Jul-18;Build 28
;;Per VA Directive 6402, this routine should not be modified.
Q
;
POST(RESULT,ARG) ;Entry point to create MailMan message from ARG array
; Input: ARG
N FLDNAM,FLDVAL,GLBO,MSGARY,BADCLM,BADLN,OCC
S GLBO="^TMP(""IBCE277J"",$J,""OUT"")" K @GLBO
;;WCJ;IB*2.0*665;KILL THE KILL SWITCH
;;JWS;IB*2.0*650;STOP 277STAT FHIR PROCESSING (I.E. KILL SWITCH)
;;G QUIT
;S SUBJ="MCT"
I $D(ARG)'>1 D Q
. S @GLBO@("Status")="0^ARG parameter is missing or has bad format"
. D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
S FLDNAM="" F S FLDNAM=$O(ARG(FLDNAM)) Q:FLDNAM="" D
. S OCC=+$P(FLDNAM,".",2)
. D GETVAL(FLDNAM,OCC)
I $D(MSGARY)'>1 D Q
. S @GLBO@("Status")="0^ARG parameter has no usable data"
. D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
S BADCLM="",BADLN=0 D MAIL
I BADCLM]"" D Q
. S @GLBO@("Status")="0^"_$S(BADCLM="XX":"Missing",1:"Bad")_" claim number"_$S(BADCLM="XX":"",1:" '"_BADCLM_"'")
. D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
I BADLN D Q
. S @GLBO@("Status")="0^Bad Line Type received in ARG parameter"
. D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
S @GLBO@("Status")="1^277STAT MailMan message created"
D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
K @GLBO
Q
;
GETVAL(FLDNAM,OCC) ;;Get the value associated with the field name
Q:($G(FLDNAM)=""!(OCC=""))
S FLDVAL=$G(ARG(FLDNAM))
;Translate any '^' to '~' since the lines of the mailman message contain pieces delimited by '^'
F Q:FLDVAL'[U S FLDVAL=$P(FLDVAL,U)_"~"_$P(FLDVAL,U,2,999)
;I $$UP^XLFSTR(FLDNAM)["TESTLIVE" S SUBJ=$S($$UP^XLFSTR(FLDVAL)="LIVE":"MCH",1:"MCT") Q
D MSGLINE($P(FLDNAM,"."),FLDVAL,OCC)
Q
;
MSGLINE(FLDNAM,FLDVAL,OCC) ;Add data to specified node in message array
;Each array node corresponds to a unique line in the MailMan message
Q:$G(FLDNAM)=""
N FLDDAT,FLDNUM,I,NODE
F I=1:1 S FLDDAT=$P($T(MAPFLD+I),";;",2) Q:FLDDAT="" D
. Q:$$UP^XLFSTR(FLDNAM)'=$$UP^XLFSTR($P(FLDDAT,U))
. S FLDNUM=$P(FLDDAT,"_",2),NODE=$P(FLDDAT,U,2),NODE=OCC_NODE Q:(NODE=""!('FLDNUM))
. S $P(MSGARY(NODE),U,FLDNUM)=FLDVAL
Q
;
CHKCLM(FLDVAL) ;;
Q:$G(FLDVAL)="" 0
N IBD,IBIFN
S $P(IBD,U,2)=FLDVAL
D STRTREC^IBCE277
Q:'IBIFN 0
Q 1
;
MAIL ;Assemble 277STAT MailMan message and create/send
N BILL,GOTLN,LN,MSG,NODE,XMTO,SUBJ
S GOTLN=0
;S XMTO("G."_SUBJ)=""
S XMTO("G.MCH")=""
S LN=$$SETMSG("RACUBOTH RUCH") ;'RACUBOTH RUCH' text needed for conditional in ^IBCESRV
S NODE="" F S NODE=$O(MSGARY(NODE)) Q:(NODE=""!(BADCLM]""!(BADLN))) D
. I NODE["LN" D Q:BADLN!(BADCLM]"")
. . I $P(MSGARY(NODE),U)'=$P(NODE,"LN",2) S BADLN=1 Q
. . S BILL=$P(MSGARY(NODE),U,2) I '$$CHKCLM(BILL) S BADCLM=$S(BILL="":"XX",1:$$GETCLM^IBCE277(BILL))
. I NODE["LN10" D PARSE(NODE,.LN) Q
. S LN=$$SETMSG(MSGARY(NODE),LN)
Q:BADCLM]""!(BADLN)
S SUBJ="MCH 277STAT "_$S(BILL["-":$P(BILL,"-",2),1:BILL)
S LN=$$SETMSG("99^$",LN),LN=$$SETMSG("NNNN",LN)
D SENDMSG^XMXAPI(DUZ,SUBJ,"MSG",.XMTO)
Q
;
SETMSG(DATA,LN) ;Set a line of the MailMan Message and return next line number
S:'$G(LN) LN=1
S MSG(LN)=$G(DATA),LN=LN+1
Q LN
;
PARSE(NODE,LN) ;
Q:($G(NODE)=""!('$G(LN)))
N I,STATARY,STATMSG,STATLIM,TXT
S STATLIM=200 ;Max characters for "Status Message" field on "10" line
S STATMSG=$P(MSGARY(NODE),U,6)
S TXT=MSGARY(NODE)
I $L(STATMSG)'>STATLIM S LN=$$SETMSG(TXT,LN) Q
D FSTRNG^IBJU1(STATMSG,STATLIM,.STATARY)
F I=1:1:STATARY S $P(TXT,U,6)=STATARY(I),LN=$$SETMSG(TXT,LN)
Q
;
QUIT ; kill switch
S @GLBO@("Status")="0^277STAT FHIR process turned off...i.e. Kill Switch"
D ENCODE^XLFJSONE(GLBO,"RESULT") S RESULT(1)="["_RESULT(1)_"]"
Q
;
MAPFLD ;RPC_field_name (limit 45 char)^Array_node
;;HeaderData_1_ReturnMessageId^HDR
;;HeaderData_2_X12ProprietaryFlag^HDR
;;HeaderData_3_StatusDate^HDR
;;HeaderData_4_StatusTime^HDR
;;HeaderData_5_MRAStatus^HDR
;;HeaderData_6_TotalNumberClaimsSubmitted^HDR
;;HeaderData_7_TotalNumberClaimsRejected^HDR
;;HeaderData_8_TotalChargesSubmitted^HDR
;;HeaderData_9_TotalChargesRejected^HDR
;;HeaderData_10_PayerName^HDR
;;HeaderData_11_PayerId^HDR
;;HeaderData_12_PayerGenerated^HDR
;;HeaderData_13_Source^HDR
;;HeaderData_14_BatchReferenceNumber^HDR
;;MessageHeader_1_LineType^LN09
;;MessageHeader_2_BillNumber^LN09
;;MessageHeader_3_MessageNumber^LN09
;;MessageHeader_4_ErrorData^LN09
;;MessageHeader_5_ErrorField^LN09
;;MessageData_1_LineType^LN10
;;MessageData_2_BillNumber^LN10
;;MessageData_3_AcceptRejectCode^LN10
;;MessageData_4_WarnErrorInfoCode^LN10
;;MessageData_5_StatusCode^LN10
;;MessageData_6_StatusMessage^LN10
;;ClaimData_1_LineType^LN13
;;ClaimData_2_BillNumber^LN13
;;ClaimData_3_ClearinghouseTraceNumber^LN13
;;ClaimData_4_PayerStatusDate^LN13
;;ClaimData_5_PayerClaimNumber^LN13
;;ClaimData_6_SplitClaimIndicator^LN13
;;ClaimData_7_ClaimType^LN13
;;ClmSvcDtSubscrPatData_1_LineType^LN15
;;ClmSvcDtSubscrPatData_2_BillNumber^LN15
;;ClmSvcDtSubscrPatData_3_PatientLastName^LN15
;;ClmSvcDtSubscrPatData_4_PatientFirstName^LN15
;;ClmSvcDtSubscrPatData_5_PatientMiddleName^LN15
;;ClmSvcDtSubscrPatData_6_PatientIdNumber^LN15
;;ClmSvcDtSubscrPatData_7_SubscriberLastName^LN15
;;ClmSvcDtSubscrPatData_8_SubscriberFirstName^LN15
;;ClmSvcDtSubscrPatData_9_SubscriberMiddleName^LN15
;;ClmSvcDtSubscrPatData_10_SubscriberIdNumber^LN15
;;ClmSvcDtSubscrPatData_11_FirstServiceDate^LN15
;;ClmSvcDtSubscrPatData_12_LastServiceDate^LN15
;
;277STAT processing will error out if there is a line 20 and/or
; line 21 in the mailman message (see IBCESRV routine).
;;ServiceLineStatusData_1_LineType^LN20
;;ServiceLineStatusData_2_BillNumber^LN20
;;ServiceLineStatusData_3_AcceptRejectCode^LN20
;;ServiceLineStatusData_4_WarnErrorInfoCode^LN20
;;ServiceLineStatusData_5_StatusCode^LN20
;;ServiceLineStatusData_6_StatusMessage^LN20
;;ServiceLineStatusData_7_FreeTextMessage^LN20
;;ServiceLineStatusData_8_ServiceLineNumber^LN20
;;ServiceLineIdData_1_LineType^LN21
;;ServiceLineIdData_2_BillNumber^LN21
;;ServiceLineIdData_3_ServiceLineNumber^LN21
;;ServiceLineIdData_4_ServiceType^LN21
;;ServiceLineIdData_5_ServiceCode^LN21
;;ServiceLineIdData_6_Modifiers^LN21
;;ServiceLineIdData_7_UnitsOfService^LN21
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HIBCE277S 6489 printed Dec 13, 2024@02:09:22 Page 2
IBCE277S ;ALB/JRA - Create MailMan message from 277STAT data array
+1 ;;2.0;INTEGRATED BILLING;**650,665**;17-Jul-18;Build 28
+2 ;;Per VA Directive 6402, this routine should not be modified.
+3 QUIT
+4 ;
POST(RESULT,ARG) ;Entry point to create MailMan message from ARG array
+1 ; Input: ARG
+2 NEW FLDNAM,FLDVAL,GLBO,MSGARY,BADCLM,BADLN,OCC
+3 SET GLBO="^TMP(""IBCE277J"",$J,""OUT"")"
KILL @GLBO
+4 ;;WCJ;IB*2.0*665;KILL THE KILL SWITCH
+5 ;;JWS;IB*2.0*650;STOP 277STAT FHIR PROCESSING (I.E. KILL SWITCH)
+6 ;;G QUIT
+7 ;S SUBJ="MCT"
+8 IF $DATA(ARG)'>1
Begin DoDot:1
+9 SET @GLBO@("Status")="0^ARG parameter is missing or has bad format"
+10 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
End DoDot:1
QUIT
+11 SET FLDNAM=""
FOR
SET FLDNAM=$ORDER(ARG(FLDNAM))
if FLDNAM=""
QUIT
Begin DoDot:1
+12 SET OCC=+$PIECE(FLDNAM,".",2)
+13 DO GETVAL(FLDNAM,OCC)
End DoDot:1
+14 IF $DATA(MSGARY)'>1
Begin DoDot:1
+15 SET @GLBO@("Status")="0^ARG parameter has no usable data"
+16 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
End DoDot:1
QUIT
+17 SET BADCLM=""
SET BADLN=0
DO MAIL
+18 IF BADCLM]""
Begin DoDot:1
+19 SET @GLBO@("Status")="0^"_$SELECT(BADCLM="XX":"Missing",1:"Bad")_" claim number"_$SELECT(BADCLM="XX":"",1:" '"_BADCLM_"'")
+20 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
End DoDot:1
QUIT
+21 IF BADLN
Begin DoDot:1
+22 SET @GLBO@("Status")="0^Bad Line Type received in ARG parameter"
+23 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
End DoDot:1
QUIT
+24 SET @GLBO@("Status")="1^277STAT MailMan message created"
+25 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
+26 KILL @GLBO
+27 QUIT
+28 ;
GETVAL(FLDNAM,OCC) ;;Get the value associated with the field name
+1 if ($GET(FLDNAM)=""!(OCC=""))
QUIT
+2 SET FLDVAL=$GET(ARG(FLDNAM))
+3 ;Translate any '^' to '~' since the lines of the mailman message contain pieces delimited by '^'
+4 FOR
if FLDVAL'[U
QUIT
SET FLDVAL=$PIECE(FLDVAL,U)_"~"_$PIECE(FLDVAL,U,2,999)
+5 ;I $$UP^XLFSTR(FLDNAM)["TESTLIVE" S SUBJ=$S($$UP^XLFSTR(FLDVAL)="LIVE":"MCH",1:"MCT") Q
+6 DO MSGLINE($PIECE(FLDNAM,"."),FLDVAL,OCC)
+7 QUIT
+8 ;
MSGLINE(FLDNAM,FLDVAL,OCC) ;Add data to specified node in message array
+1 ;Each array node corresponds to a unique line in the MailMan message
+2 if $GET(FLDNAM)=""
QUIT
+3 NEW FLDDAT,FLDNUM,I,NODE
+4 FOR I=1:1
SET FLDDAT=$PIECE($TEXT(MAPFLD+I),";;",2)
if FLDDAT=""
QUIT
Begin DoDot:1
+5 if $$UP^XLFSTR(FLDNAM)'=$$UP^XLFSTR($PIECE(FLDDAT,U))
QUIT
+6 SET FLDNUM=$PIECE(FLDDAT,"_",2)
SET NODE=$PIECE(FLDDAT,U,2)
SET NODE=OCC_NODE
if (NODE=""!('FLDNUM))
QUIT
+7 SET $PIECE(MSGARY(NODE),U,FLDNUM)=FLDVAL
End DoDot:1
+8 QUIT
+9 ;
CHKCLM(FLDVAL) ;;
+1 if $GET(FLDVAL)=""
QUIT 0
+2 NEW IBD,IBIFN
+3 SET $PIECE(IBD,U,2)=FLDVAL
+4 DO STRTREC^IBCE277
+5 if 'IBIFN
QUIT 0
+6 QUIT 1
+7 ;
MAIL ;Assemble 277STAT MailMan message and create/send
+1 NEW BILL,GOTLN,LN,MSG,NODE,XMTO,SUBJ
+2 SET GOTLN=0
+3 ;S XMTO("G."_SUBJ)=""
+4 SET XMTO("G.MCH")=""
+5 ;'RACUBOTH RUCH' text needed for conditional in ^IBCESRV
SET LN=$$SETMSG("RACUBOTH RUCH")
+6 SET NODE=""
FOR
SET NODE=$ORDER(MSGARY(NODE))
if (NODE=""!(BADCLM]""!(BADLN)))
QUIT
Begin DoDot:1
+7 IF NODE["LN"
Begin DoDot:2
+8 IF $PIECE(MSGARY(NODE),U)'=$PIECE(NODE,"LN",2)
SET BADLN=1
QUIT
+9 SET BILL=$PIECE(MSGARY(NODE),U,2)
IF '$$CHKCLM(BILL)
SET BADCLM=$SELECT(BILL="":"XX",1:$$GETCLM^IBCE277(BILL))
End DoDot:2
if BADLN!(BADCLM]"")
QUIT
+10 IF NODE["LN10"
DO PARSE(NODE,.LN)
QUIT
+11 SET LN=$$SETMSG(MSGARY(NODE),LN)
End DoDot:1
+12 if BADCLM]""!(BADLN)
QUIT
+13 SET SUBJ="MCH 277STAT "_$SELECT(BILL["-":$PIECE(BILL,"-",2),1:BILL)
+14 SET LN=$$SETMSG("99^$",LN)
SET LN=$$SETMSG("NNNN",LN)
+15 DO SENDMSG^XMXAPI(DUZ,SUBJ,"MSG",.XMTO)
+16 QUIT
+17 ;
SETMSG(DATA,LN) ;Set a line of the MailMan Message and return next line number
+1 if '$GET(LN)
SET LN=1
+2 SET MSG(LN)=$GET(DATA)
SET LN=LN+1
+3 QUIT LN
+4 ;
PARSE(NODE,LN) ;
+1 if ($GET(NODE)=""!('$GET(LN)))
QUIT
+2 NEW I,STATARY,STATMSG,STATLIM,TXT
+3 ;Max characters for "Status Message" field on "10" line
SET STATLIM=200
+4 SET STATMSG=$PIECE(MSGARY(NODE),U,6)
+5 SET TXT=MSGARY(NODE)
+6 IF $LENGTH(STATMSG)'>STATLIM
SET LN=$$SETMSG(TXT,LN)
QUIT
+7 DO FSTRNG^IBJU1(STATMSG,STATLIM,.STATARY)
+8 FOR I=1:1:STATARY
SET $PIECE(TXT,U,6)=STATARY(I)
SET LN=$$SETMSG(TXT,LN)
+9 QUIT
+10 ;
QUIT ; kill switch
+1 SET @GLBO@("Status")="0^277STAT FHIR process turned off...i.e. Kill Switch"
+2 DO ENCODE^XLFJSONE(GLBO,"RESULT")
SET RESULT(1)="["_RESULT(1)_"]"
+3 QUIT
+4 ;
MAPFLD ;RPC_field_name (limit 45 char)^Array_node
+1 ;;HeaderData_1_ReturnMessageId^HDR
+2 ;;HeaderData_2_X12ProprietaryFlag^HDR
+3 ;;HeaderData_3_StatusDate^HDR
+4 ;;HeaderData_4_StatusTime^HDR
+5 ;;HeaderData_5_MRAStatus^HDR
+6 ;;HeaderData_6_TotalNumberClaimsSubmitted^HDR
+7 ;;HeaderData_7_TotalNumberClaimsRejected^HDR
+8 ;;HeaderData_8_TotalChargesSubmitted^HDR
+9 ;;HeaderData_9_TotalChargesRejected^HDR
+10 ;;HeaderData_10_PayerName^HDR
+11 ;;HeaderData_11_PayerId^HDR
+12 ;;HeaderData_12_PayerGenerated^HDR
+13 ;;HeaderData_13_Source^HDR
+14 ;;HeaderData_14_BatchReferenceNumber^HDR
+15 ;;MessageHeader_1_LineType^LN09
+16 ;;MessageHeader_2_BillNumber^LN09
+17 ;;MessageHeader_3_MessageNumber^LN09
+18 ;;MessageHeader_4_ErrorData^LN09
+19 ;;MessageHeader_5_ErrorField^LN09
+20 ;;MessageData_1_LineType^LN10
+21 ;;MessageData_2_BillNumber^LN10
+22 ;;MessageData_3_AcceptRejectCode^LN10
+23 ;;MessageData_4_WarnErrorInfoCode^LN10
+24 ;;MessageData_5_StatusCode^LN10
+25 ;;MessageData_6_StatusMessage^LN10
+26 ;;ClaimData_1_LineType^LN13
+27 ;;ClaimData_2_BillNumber^LN13
+28 ;;ClaimData_3_ClearinghouseTraceNumber^LN13
+29 ;;ClaimData_4_PayerStatusDate^LN13
+30 ;;ClaimData_5_PayerClaimNumber^LN13
+31 ;;ClaimData_6_SplitClaimIndicator^LN13
+32 ;;ClaimData_7_ClaimType^LN13
+33 ;;ClmSvcDtSubscrPatData_1_LineType^LN15
+34 ;;ClmSvcDtSubscrPatData_2_BillNumber^LN15
+35 ;;ClmSvcDtSubscrPatData_3_PatientLastName^LN15
+36 ;;ClmSvcDtSubscrPatData_4_PatientFirstName^LN15
+37 ;;ClmSvcDtSubscrPatData_5_PatientMiddleName^LN15
+38 ;;ClmSvcDtSubscrPatData_6_PatientIdNumber^LN15
+39 ;;ClmSvcDtSubscrPatData_7_SubscriberLastName^LN15
+40 ;;ClmSvcDtSubscrPatData_8_SubscriberFirstName^LN15
+41 ;;ClmSvcDtSubscrPatData_9_SubscriberMiddleName^LN15
+42 ;;ClmSvcDtSubscrPatData_10_SubscriberIdNumber^LN15
+43 ;;ClmSvcDtSubscrPatData_11_FirstServiceDate^LN15
+44 ;;ClmSvcDtSubscrPatData_12_LastServiceDate^LN15
+45 ;
+46 ;277STAT processing will error out if there is a line 20 and/or
+47 ; line 21 in the mailman message (see IBCESRV routine).
+48 ;;ServiceLineStatusData_1_LineType^LN20
+49 ;;ServiceLineStatusData_2_BillNumber^LN20
+50 ;;ServiceLineStatusData_3_AcceptRejectCode^LN20
+51 ;;ServiceLineStatusData_4_WarnErrorInfoCode^LN20
+52 ;;ServiceLineStatusData_5_StatusCode^LN20
+53 ;;ServiceLineStatusData_6_StatusMessage^LN20
+54 ;;ServiceLineStatusData_7_FreeTextMessage^LN20
+55 ;;ServiceLineStatusData_8_ServiceLineNumber^LN20
+56 ;;ServiceLineIdData_1_LineType^LN21
+57 ;;ServiceLineIdData_2_BillNumber^LN21
+58 ;;ServiceLineIdData_3_ServiceLineNumber^LN21
+59 ;;ServiceLineIdData_4_ServiceType^LN21
+60 ;;ServiceLineIdData_5_ServiceCode^LN21
+61 ;;ServiceLineIdData_6_Modifiers^LN21
+62 ;;ServiceLineIdData_7_UnitsOfService^LN21
+63 ;