Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: IBECECQ1

IBECECQ1.m

Go to the documentation of this file.
IBECECQ1 ;BSL/DVA-BILLING - SEND/RECEIVE QRY & DSR HL7 messages FOR PATIENT ACCUMULATOR INTERFACE ; 01 Jun 2022  7:17 AM
 ;;2.0;INTEGRATED BILLING;**704**;21-MAR-94;Build 49
 ;Per VA Directive 6402, this routine should not be modified.
 ;
 ; Reference to $$STARTMSG^HLOPRS,$$NEXTSEG^HLOPRS,$$GET^HLOPRS,$$MSGID^HLOPRS in ICR #4718
 ; Reference to $$ADDSEG^HLOAPI,$$NEWMSG^HLOAPI,SET^HLOAPI in ICR #4722
 ; Reference to $$SENDONE^HLOAPI1 in ICR #4717
 ;
 ; -4200Build and send seeding of Vista data to DAS SPOE IBECEAC-QRY DSR^Q03 
 ; Receive seeding query of Vista data from DAS SPOE IBECEAC-QRY DSR^Q03 
 ;
 ; Sample message
 ;MSH|^~\&||695^HL7.IVMVEE.FO-ALBANY.DOMAIN.EXT:5127^DNS|IBECECQ-QRYRESP|200DAS^:^DNS|20211001094308-0500||QRY^RO2^QRY_RO2|695 1469|T^|2.3|||AL|NE|USA
 ;QRD|20211008123254-0500|1|1||||1|DRI^DODMORE MESSAGE|1008713999V404928
 ;QRF|IBECEAC-QRY|20161106|20161107
 ;
 Q   ;No direct routine calls
 ;
ADM ;Called from IB MEANS TEST BILLING protocol
 Q:$P($G(DGPMA),"^",2)'=1
 D EN(DFN)
 Q
 ;
EDTCLCK(DFN,IBADMIT) ;Called from Billing CLock Maintenance option
 N IBTRYTIL,IBECDT,IBECLDT,IBECIEN,IBECSTDT,IBECENDT,IBNOW
 Q:'$$ICN^IBARXMU(DFN)  ;Do not run query of patient does not have an ICN
 D MTEQRY(DFN,IBADMIT)  ;Run Query
 W !,"Running Billing Clock Query, please wait."
 S IBFLAG1=0 S IBTRYTIL=$$FMADD^XLFDT($$NOW^XLFDT,,,1),IBNOW=$$NOW^XLFDT F  Q:$$NOW^XLFDT>IBTRYTIL  Q:IBFLAG1  D
 .H 2 W "." S IBECDT1=-(IBADMIT_.9999) F  S IBECDT1=$O(^IBE(351,"AIVDT",DFN,IBECDT1)) Q:'IBECDT1  S IBECIEN=$O(^IBE(351,"AIVDT",DFN,IBECDT1,";"),-1) Q:'IBECIEN  D
 ..S IBECLDT=$$GET1^DIQ(351,IBECIEN_",",.04,"I") Q:IBECLDT=3  D
 ...S IBECSTDT=$$GET1^DIQ(351,IBECIEN_",",.03,"I"),IBECENDT=$$GET1^DIQ(351,IBECIEN_",",.1,"I"),IBECENDT=$S(IBECENDT:IBECENDT,IBECLDT=2:($$CLSDT^IBECECX1(IBECSTDT)),1:DT) D
 ....I (IBECENDT>=IBADMIT),$$GET1^DIQ(351,IBECIEN_",",14,"I")>IBNOW,$P(^IBE(351,IBECIEN,1),U,5) S IBFLAG1=1,IBECDA=IBECIEN Q
 Q
 ;
MTEQRY(DFN,IBADMIT) ;Query for Billing CLock Maintenance option
 N IBICN,IBDISCH
 S IBICN=$$ICN^IBARXMU(DFN)
 I +IBICN<1 S SERROR="NO PATIENT ICN FOUND",SERR=1 Q  ;quit if unable to find ICN
 S IBDISCH=$$CLSDT^IBECECX1(IBADMIT)
 I IBDISCH S IBDISCH=$$FMTHL7^XLFDT($P(IBDISCH,"."))
 S IBADMIT=$$FMTHL7^XLFDT($P(IBADMIT,"."))
 S IBOADMIT=IBADMIT
 I IBDISCH S IBODISCH=IBDISCH
 S:$G(SERR)="" SERR=0
 D MSH,QRD,QRF,SENDQRY
 Q
 ;
CCBILL(DFN,IBADMIT) ;OUTGOING QRY Called from CC Inpatient Bill
 ;
 N X,PARMS,SEG,MSG,VALUE,FIELD,QRYNUM,SERROR,SERR,NAME,ERROR,XXX,WHOTO,IBACBCLK,IBADM,IBDISC,IBDISCH,IBIEN,IBICN,IBQIEN,IBC0,IBODISCH,IBOADMIN
 ;
 ;S IBC0=^IBE(351,IBCLDA,0)    
 ;HL7 to FM - $$HL7TFM^XLFDT(DT)   
 ;FM TO HL7 - $$FMTHL7^XLFDT(DT)
 ; Retrieve Admission and Discharge dates from the PTF file
 ;
 D CCINPT^IBECECX1(DFN,.IBADMIT)                       ;Get admit/discharge data
 S IBICN=$$ICN^IBARXMU(DFN)
 I +IBICN<1 S SERROR="NO PATIENT ICN FOUND",SERR=1 Q  ;quit if unable to find ICN
 S:$G(SERR)="" SERR=0
 D MSH,QRD,QRF,SENDQRY
 Q
 ;-------------------------------------------------OUTGOING QRY ----------------------------------------
EN(DFN) ;OUTGOING QRY  ENTRY POINT
 ; IBQIEN - Query Request Message IEN (#778) that initiated this response                                   CALLED FROM CLADD^IBAUTL3
 N X,PARMS,SEG,MSG,VALUE,FIELD,QRYNUM,SERROR,SERR,NAME,ERROR,XXX,WHOTO,IBACBCLK,IBADM,IBDISC,IBADMIT,IBDISCH,IBIEN,IBICN,IBQIEN,IBC0,IBODISCH,IBOADMIN
 ;
 ;S IBC0=^IBE(351,IBCLDA,0)    
 ;HL7 to FM - $$HL7TFM^XLFDT(DT)   
 ;FM TO HL7 - $$FMTHL7^XLFDT(DT)
 ; Retrieve Admission and Discharge dates from the PTF file
 ;
 D INPT^IBECECX1(DFN)                 ;Get admit/discharge data
 S IBICN=$$ICN^IBARXMU(DFN)
 I +IBICN<1 S SERROR="NO PATIENT ICN FOUND",SERR=1 Q  ;quit if unable to find ICN
 S:$G(SERR)="" SERR=0
 D MSH,QRD,QRF,SENDQRY
 Q
 ;
MSH ;  Build MSH Segment
 N PARMS K ^TMP("DSR")
 S PARMS("COUNTRY")="USA"
 S PARMS("MESSAGE TYPE")="QRY"
 S PARMS("EVENT")="R02"
 S PARMS("VERSION")="2.3"
 S PARMS("MESSAGE STRUCTURE")="QRY_R02"
 S MSG="^TMP("_"QRY"
 S X=$$NEWMSG^HLOAPI(.PARMS,.MSG,.ERROR)
MSA ;Build MSA Segment  (OPTIONAL)
 S VALUE="MSA",FIELD=0 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S VALUE="AL",FIELD=1 D SET^HLOAPI(.SEG,VALUE,FIELD)
 ;S VALUE=QRYNUM,FIELD=2 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
 Q
 ;
QRD ;Build QRD segment
 S VALUE="QRD",FIELD=0 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S %P1=$$NOW^XLFDT() S %P1=$$FMTHL7^XLFDT(%P1)
 S VALUE=%P1,FIELD=1 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S VALUE=1,FIELD=2 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S VALUE=1,FIELD=3 D SET^HLOAPI(.SEG,VALUE,FIELD)
 ;S VALUE=QRYNUM,FIELD=4 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S VALUE=1,FIELD=7 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S NAME=$$GET1^DIQ(2,DFN_",",.01)
 S VALUE=$P($G(NAME),",",1),FIELD=8 D SET^HLOAPI(.SEG,VALUE,FIELD,1)
 S VALUE=$P($G(NAME),",",2),FIELD=8 D SET^HLOAPI(.SEG,VALUE,FIELD,2)
 S VALUE=IBICN,FIELD=9 D SET^HLOAPI(.SEG,VALUE,FIELD)
 S FIELD=11 I $G(IBOADMIT) S VALUE=IBOADMIT D SET^HLOAPI(.SEG,VALUE,FIELD) ; ADMIT DATE
 S FIELD=12 I $G(IBODISCH) S VALUE=IBODISCH D SET^HLOAPI(.SEG,VALUE,FIELD) ; Discharge date
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
 Q
 ;
QRF ;Build QRF segment
 S FIELD=0,VALUE="QRF" D SET^HLOAPI(.SEG,VALUE,FIELD)
 S FIELD=1,VALUE="IBECEAC-QRY" D SET^HLOAPI(.SEG,VALUE,FIELD)
 S FIELD=2 I $G(IBADMIT) S VALUE=IBADMIT D SET^HLOAPI(.SEG,VALUE,FIELD) ; ADMIT DATE
 S FIELD=3 I $G(IBDISCH) S VALUE=IBDISCH D SET^HLOAPI(.SEG,VALUE,FIELD) ; Discharge date
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
 Q
SENDQRY ;
 S PARMS("SENDING APPLICATION")="IBECEAC-QRY"
 S WHOTO("RECEIVING APPLICATION")="IBECEAC-RECV"
 S WHOTO("STATION NUMBER")="200DAS"
 S WHOTO("MIDDLEWARE LINK NAME")="IBECEC-QRY"            ;File #870 entry
 S XXX=$$SENDONE^HLOAPI1(.MSG,.PARMS,.WHOTO,.ERROR)
 Q
 ;
 ;--------------------------------------------------INCOMING QRY  --------------------------
QRYIN ; receives incoming HL7 QRY^R02 and returns a DSR
 N ICN,IBECADM,IBSADMIT,IBSDISCH
 S ERR=0,IBSTAT=$$STARTMSG^HLOPRS(.IBMSG,HLMSGIEN,.IBHDR)
 S IBIEN=HLMSGIEN
 I 'IBSTAT  S HLERR="Unable to start parse of message" Q
 I "QRY"'[IBHDR("MESSAGE TYPE") Q
 ;
 ; extract some incoming message data from Cerner message IBARXC-QRY - QRY^R02 
 F  Q:'$$NEXTSEG^HLOPRS(.IBMSG,.SEG)  S IBSEGT=$G(SEG("SEGMENT TYPE")) Q:IBSEGT=""  D
 . I IBSEGT="QRD" D QRDQI
 . I IBSEGT="QRF" D QRFQI
 Q:'ICN
 D DSROUT(ICN,IBIEN,IBECADM)
 K IBCLNDT
 Q
 ;
QRDQI ; INCOMING QRD SEGMENT
 S ICN=$$GET^HLOPRS(.SEG,9,1,1,1)
 S IBSADMIT=$$GET^HLOPRS(.SEG,11,1,1,1)
 S IBSDISCH=$$GET^HLOPRS(.SEG,12,1,1,1)
 Q
 ;
QRFQI ; INCOMING QRF SEGMENT
 S IBECADM=$$GET^HLOPRS(.SEG,2,1,1,1)
 S IBECADM=$$HL7TFM^XLFDT(IBECADM)
 Q
 ;
 ;--------------------------------------------------INCOMING DSR --------------------------
DSRIN ;MAIN ENTRY POINT - incoming DSR message
 ;
 N IBMSG,HDR,SEG,XXX,DFN,IBAGG
 S IBERR=0,IBAGG=1
 S XXX=$$STARTMSG^HLOPRS(.IBMSG,HLMSGIEN,.HDR)
 F  Q:'$$NEXTSEG^HLOPRS(.IBMSG,.SEG)  S IBSEGT=$G(SEG("SEGMENT TYPE")) Q:IBSEGT=""  D
 . I IBSEGT="MSA" D MSA1
 . I IBSEGT="QRD" D QRDDI
 . I IBSEGT="DSP" D DSPDI
 . I IBSEGT="ERR" D ERR1($$GET^HLOPRS(.SEG,6,1))
 Q
 ;
MSA1 ;PULL 351 REFERENCE NUMBER
 S IBCLDA=IBMSG("HDR","MESSAGE CONTROL ID")
 S IB778=$P($$GET^HLOPRS(.SEG,2,1,1)," ",2)
 Q
 ;
QRDDI  ;INCOMING QRD SEGMENT
 ;N IBQRYDT
 S IBQRYDT=$$GET^HLOPRS(.SEG,1,1,1)       ;QUERY DATE/TIME
 S IBICN=$$GET^HLOPRS(.SEG,9,1,1,1)         ;Pt ICN
 S DFN=$$DFN^IBARXMU(IBICN)
 S IBADMIT=$$GET^HLOPRS(.SEG,11,1,1,1)
 S IBDISCH=$$GET^HLOPRS(.SEG,12,1,1,1)
 Q
DSPDI   ;INCOMING DSP SEGMENT
 N IBSETID,IBCLDT,IB901,IB902,IB903,IB904,IBICLDAY,IBICLDT,IBSETID1,IBCLDT1,IB9011,IB9021,IB9031,IB9041,IBCLDAY1,IBICKDT,IBACTC,IBCKNUM,IBICNUM
 N IBCNT,IBDA,IBCNDT,IBQRYS,IBCBDT,IBDA1,IBICLNDT,IBERRMSG,IBODISCH,IBOADMIN,IBQRY,IBCRTST
 S IBERRMSG=$$GET^HLOPRS(.SEG,5,1)    ;Result Messages/Errors
 I IBERRMSG'="" D ERR1(IBERRMSG) Q
 S IBCNT=$$GET^HLOPRS(.SEG,1,1)
 S IBISETID=$$GET^HLOPRS(.SEG,3,1)     ;FT1 Response - bjr
 S IBICLDT=$$GET^HLOPRS(.SEG,3,2)      ;Billing Clock start date - bjr
 S IBICLDT=$$HL7TFM^XLFDT(IBICLDT)        ;convert HL7 date TO FM - bjr
 S IBI901=$$GET^HLOPRS(.SEG,3,3)       ;1st QRT charges - bjr
 S IBI902=$$GET^HLOPRS(.SEG,3,4)       ;2nd QRT charges - bjr
 S IBI903=$$GET^HLOPRS(.SEG,3,5)       ;3rd QRT charges - bjr
 S IBI904=$$GET^HLOPRS(.SEG,3,6)       ;4th QRT charges - bjr
 S IBICLDAY=$$GET^HLOPRS(.SEG,3,7)     ;Inpatient days - bjr
 S IBICLNDT=$$GET^HLOPRS(.SEG,3,8)     ;Billing clock end date - bjr
 S IBICLNDT=$$HL7TFM^XLFDT(IBICLNDT)      ;HL7 TO FM - bjr
 S IBICKDT=IBICLNDT
 ;RRA currently nothing passed in the 4th field - leaving for integration with Cerner
 S IBSETID1=$$GET^HLOPRS(.SEG,4,1)      ;FT2 set id (IF PRESENT)
 S IBCLDT1=$$GET^HLOPRS(.SEG,4,2)     ;Billing Clock start date
 S IBCLDT1=$$HL7TFM^XLFDT(IBCLDT1)      ;convert HL7 date TO FM
 S IB9011=$$GET^HLOPRS(.SEG,4,3)      ;1st QRT charges
 S IB9021=$$GET^HLOPRS(.SEG,4,4)      ;2nd QRT charges
 S IB9031=$$GET^HLOPRS(.SEG,4,5)      ;3rd QRT charges
 S IB9041=$$GET^HLOPRS(.SEG,4,6)      ;4th QRT charges
 S IBCLDAY1=$$GET^HLOPRS(.SEG,4,7)    ;Inpatient days
 ;S IBICKDT=$$GET^HLOPRS(.SEG,4,8)    ;Billing clock end date
 ;S IBICKDT=$$HL7TFM^XLFDT(IBICKDT)    ;convert HL7 date TO FM
 S IBISTAT=$$GET^HLOPRS(.SEG,6,1)    ;Clock Status
 S IBCKNUM=$$GET^HLOPRS(.SEG,7,1)   ;Number of billing clocks sent (FT1)
 S IBICNUM=$$GET^HLOPRS(.SEG,8,1)   ;Number of admit encounters sent (FT2) - bjr
 S IBISITE=$$GET^HLOPRS(.SEG,9,1)   ;Site - bjr
 I 'IBISTAT  D UDCL  Q  ;Quit if no status sent which indicates no clocks from other sites
 S IBDA=";"  F  S IBDA=$O(^IBE(351,"AIVDT",DFN,-IBICLDT,IBDA),-1) Q:'IBDA  Q:$G(IBCBDT)  D
 .S IBCBDT=$$GET1^DIQ(351,IBDA_",",.03,"I")
 .S IBQRYS=$$GET1^DIQ(351,IBDA_",",16,"I")
 .S IBCRTST=$$GET1^DIQ(351,IBDA_",",.04,"I")
 .S IBDA1=IBDA
 I $G(IBQRYS),IBCRTST'=3 Q
 Q:(IBICLDT<1)
 I $G(IBCBDT)=IBICLDT,IBCNT=1 D UPDATE^IBECECU1(IBDA1)  Q  ;Update record if current Billing Clock Start Date matches incoming Billing Clock Start Date
 I IBCNT=1 D NEWREC^IBECECU1  ;IBCNT=1 MEANS THE DSR SEGMENT IS AGGREGATED DATA AND SHOULD BE STORED IN 351
 I IBCNT>1 D EN^IBECECU2(IBICLDT,DFN) ;IBCNT>1 MEANS IT IS INDIVIDUAL SITE DATA USED FOR AGGREGATION AND NEEDS TO BE STORED IN 351.3
 S IBADMIT=$$FMADD^XLFDT(IBICLNDT,1)
 I ($$FMTHL7^XLFDT(IBICLNDT))<IBDISCH,IBCNT=1 D  ;
 .S IBQRY=$O(^IBE(351,"AIVDT",DFN,-IBADMIT,";"),-1) I IBQRY,$P(^IBE(351,IBQRY,1),U,5) Q
 .S IBADMIT=$$FMADD^XLFDT(IBICLNDT,1),IBDISCH=$$FMADD^XLFDT(IBADMIT,365),IBADMIT=$$FMTHL7^XLFDT(IBADMIT),IBOADMIT=IBADMIT
 .S IBDISCH=$S(IBDISCH<DT:IBDISCH,1:"") I IBDISCH S IBDISCH=$$FMTHL7^XLFDT(IBDISCH),IBODISCH=IBDISCH
 .K SEG,ERROR
 .D MSH,QRD,QRF,SENDQRY
 Q
 ;
 ;-------------------------------------------------- OUTGOING DSR --- ---------------------------
DSROUT(ICN,IBIEN,IBADMIT) ;MAIN ENTRY POINT - Outgoing DSR message
 ; IBIEN - Query Request Message IEN (#778) that initiated this response 
 ; ------ Sample message ----
 ;MSH|^~\&|IBECEAC-SEND|695^HL7.IVMVEE.FO-ALBANY.DOMAIN.EXT:5127^DNS|IBECEAC-RECV|200DAS^:^DNS"|20211029135630-0500||DSR^Q03^DSR_Q03|695 1480|T^|2.3|||AL|NE|USA|3211029.135631^20211029145631.228^
 ;MSA|AL|0"
 ;QRD|20211102091619|1|1|0|||1|DRI^DODMORE MESSAGE|1008713999V404928"
 ;DSP|1||FT1^20201101^345^0^0^0^15^-1|||1|1|1"
 N PARMS,SEG,MSG,VALUE,FIELD,QRYNUM,SERROR,SERR,NAME,ERROR,XXX,WHOTO
 N IBSETID,IBCLDT,IB901,IB902,IB903,IB904,IBCLDAY,IBSETID1,IBCLDT1,IB9011,IB9021,IB9031,IB9041,IBCLDAY1,IBCLNDT1,IBACTC,IBCKNUM,IBICNUM
 S DFN=$$DFN^IBARXMU(ICN)
 I +DFN<1 S SERROR="NO PATIENT FOUND WITH SUBMITTED ICN",SERR=1
 S QRYNUM=$$MSGID^HLOPRS(IBIEN)  ; Message Control ID of initiating Query 
 S:$G(SERR)="" SERR=0
 D EN^IBECECX1(DFN),INPT^IBECECX1(DFN)
MSHO   ;  Outgoing MSH
 N PARMS K ^TMP("DSR")
 S PARMS("COUNTRY")="USA"
 S PARMS("MESSAGE TYPE")="DSR"
 S PARMS("EVENT")="Q03"
 S PARMS("SENDING APPLICATION")="IBECEAC-QRYRESP"
 S PARMS("VERSION")="2.3"
 S PARMS("MESSAGE STRUCTURE")="DSR_Q03"
 S MSG="^TMP("_"DSR"
 S X=$$NEWMSG^HLOAPI(.PARMS,.MSG,.ERROR)
MSAO   ;Outgoing MSA
 D SET^HLOAPI(.SEG,"MSA",0)
 D SET^HLOAPI(.SEG,"AL",1)
 D SET^HLOAPI(.SEG,QRYNUM,2)
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
QRDO   ;Outgoing QRD
 D SET^HLOAPI(.SEG,"QRD",0)
 S %P1=$$NOW^XLFDT() S %P1=$$FMTHL7^XLFDT(%P1)
 D SET^HLOAPI(.SEG,+%P1,1)
 D SET^HLOAPI(.SEG,1,2)
 D SET^HLOAPI(.SEG,1,3)
 D SET^HLOAPI(.SEG,+QRYNUM,4)
 D SET^HLOAPI(.SEG,1,7)
 S NAME=$$GET1^DIQ(2,DFN_",",.01)
 D SET^HLOAPI(.SEG,$P($G(NAME),",",1),8,1)
 D SET^HLOAPI(.SEG,$P($G(NAME),",",2),8,2)
 D SET^HLOAPI(.SEG,ICN,9)
 I $G(IBSADMIT) D SET^HLOAPI(.SEG,IBSADMIT,11)
 I $G(IBSDISCH) D SET^HLOAPI(.SEG,IBSDISCH,12)
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
 ;
DSPO   ;Outgoing DSP
 D SET^HLOAPI(.SEG,"DSP",0)
 D SET^HLOAPI(.SEG,1,1)
 D SET^HLOAPI(.SEG,"FT1",3,1)                     ;FT1 Response
 S IBCLDT=$$FMTHL7^XLFDT(+IBCLDT) D SET^HLOAPI(.SEG,$S(IBCLDT>0:IBCLDT,1:$$FMTHL7^XLFDT(DT)),3,2)   ;Billing Clock start date (HL7 format)
 D SET^HLOAPI(.SEG,+IB901,3,3)                    ;1st QRT charges
 D SET^HLOAPI(.SEG,+IB902,3,4)                    ;2nd QRT charges
 D SET^HLOAPI(.SEG,+IB903,3,5)                    ;3rd QRT charges
 D SET^HLOAPI(.SEG,+IB904,3,6)                    ;4th QRT charges
 D SET^HLOAPI(.SEG,+IBCLDAY,3,7)                  ;Inpatient days
 I $G(IBCLNDT) S IBCLNDT=$$FMTHL7^XLFDT(IBCLNDT) D SET^HLOAPI(.SEG,+IBCLNDT,3,8) ;Billing Clock end date (HL7 format)
 ;D SET^HLOAPI(.SEG,+IBSETID1,4)                  ;FT2 set id (IF PRESENT)
 ;D SET^HLOAPI(.SEG,2,4)               ;FT2 set id (IF PRESENT)
 ;D SET^HLOAPI(.SEG,+IBADMIT,4,1)      ;Admit Date (Already HL7 format)
 ;D SET^HLOAPI(.SEG,+IBDISCH,4,2)      ;Discharge Date (Already HL7 format)
 ;D SET^HLOAPI(.SEG,+IBCLDAY,4,3)      ;Inpatient Days
 ;
 D SET^HLOAPI(.SEG,+IBSTAT,6)          ;Active clock sent
 D SET^HLOAPI(.SEG,+IBCKNUM,7)         ;Number of billing clocks sent (FT1)
 D SET^HLOAPI(.SEG,+IBICNUM,8)         ;Number of admit encounters sent (FT2)
 S X=$$ADDSEG^HLOAPI(.MSG,.SEG,.ERROR)
 ;
SENDDSR ;
 S PARMS("SENDING APPLICATION")="IBECEAC-QRYRESP"
 S WHOTO("RECEIVING APPLICATION")="IBECEAC-RCV"
 S WHOTO("STATION NUMBER")="200DAS"
 S WHOTO("MIDDLEWARE LINK NAME")="IBECEC-DSR"            ;File #870 entry
 S XXX=$$SENDONE^HLOAPI1(.MSG,.PARMS,.WHOTO,.ERROR)
 Q
 ;
ERR1(IBERRMSG) ;HANDLE ERROR RESPONSES
 ;
 ;XMY,XMSUB,IBL
 I IBERRMSG["MVI returned no treating facilities for this patient" D UDCL ;no error message necessary - just update the query sent field
 ;MAIL MESSAGE GENERATION CODE ON HOLD FOR FUTURE REQUIREMENTS
 ;K ^TMP($J,"IBCPYAC")
 ;S XMSUB="COPAY PATIENT ACCUMULATOR ISSUE"
 ;S XMY("G.IB PATIENT ACCUMULATOR")=""
 ;S IBL=0
 ;S IBL=IBL+1,^TMP($J,"IBCPYAC",IBL)="ERROR RECEIVED BY DAS DURING QUERY ATTEMPT:"
 ;S IBL=IBL+1,^TMP($J,"IBCPYAC",IBL)=""
 ;S IBL=IBL+1,^TMP($J,"IBCPYAC",IBL)=IBERRMSG
 ;S XMDUZ=DUZ,XMTEXT="^TMP($J,""IBCPYAC"","
 ;D ^XMD
 Q
UDCL ;Update original billing clock so nightly querys are not sent for patients without TFL's
 N IBSTAT,IBCLK,IBDA,IBMSG,IBHDR,SEG,IBSEGT,IBDFN,IBECDAT
 S IBSTAT=$$STARTMSG^HLOPRS(.IBMSG,IB778,.IBHDR)
 F  Q:'$$NEXTSEG^HLOPRS(.IBMSG,.SEG)  S IBSEGT=$G(SEG("SEGMENT TYPE")) Q:IBSEGT=""  D
 . I IBSEGT="QRD" D QRDQI   ;pull the ICN out of the initiating QRY message so we can update the Billing Clock
 Q:'ICN
 S IBDFN=$$DFN^IBARXMU(ICN)
 S IBDA=";" S IBDA=$O(^IBE(351,"ACT",IBDFN,IBDA),-1)  ;locate the most recent active Billing Clock for update
 I 'IBDA S IBECDAT=$O(^IBE(351,"AIVDT",IBDFN,-9999999)) Q:'IBECDAT  S IBDA=$O(^IBE(351,"AIVDT",IBDFN,IBECDAT,";"),-1) Q:$$GET1^DIQ(351,IBDA,.04)  ;Use newest date entry when no status set
 Q:'IBDA
 S $P(^IBE(351,IBDA,1),"^",5)=1  ;Update QUERY SENT
 Q