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

IVMCQ2.m

Go to the documentation of this file.
  1. IVMCQ2 ;ALB/KCL - API FOR FINANCIAL QUERIES (continued) ; 27-APR-95
  1. ;;2.0;INCOME VERIFICATION MATCH;**17**;21-OCT-94
  1. ;
  1. ;
  1. MONITOR ; Description: This entry point is used to monitor the IVM FINANCIAL
  1. ; QUERY LOG file and check for query transmissions that have not been
  1. ; responded to for more than 2 days. If a query is > 2 days old, the
  1. ; corresponding entry in the IVM FINANCIAL QUERY LOG file will be
  1. ; updated/closed and a new financial query may be sent.
  1. ;
  1. N IVMQLOG,QRYIEN,%
  1. ;
  1. ; roll through query log entries with 'open' status
  1. S QRYIEN=0 F S QRYIEN=$O(^IVM(301.62,"AC",0,QRYIEN)) Q:'QRYIEN D
  1. .;
  1. .; obtain record from IVM FINANCIAL QUERY LOG
  1. .Q:'$$GET(+QRYIEN,.IVMQLOG)
  1. .;
  1. .; quit if query msg not old enough
  1. .Q:IVMQLOG("SENT")>$$FMADD^XLFDT(DT,-2)
  1. .;
  1. .; update/auto-close query in IVM FINANCIAL QUERY LOG file
  1. .D NOW^%DTC,UPD(IVMQLOG("DFN"),+QRYIEN,%,6,2)
  1. .;
  1. .; quit if new query is not needed
  1. .Q:'$$NEED^IVMCQ(IVMQLOG("DFN"))
  1. .;
  1. .; send new query
  1. .I $$QUERY^IVMCQ1(IVMQLOG("DFN"),IVMQLOG("TRANBY"),IVMQLOG("NOTIFY"),IVMQLOG("OPTION"))
  1. ;
  1. Q
  1. ;
  1. ;
  1. FIND(DFN,IVMMSG,IVMRECD,IVMCR,IVMCS) ; Description: Used to find and update
  1. ; entry in IVM FINANCIAL QUERY LOG file.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ; IVMMSG - query message id
  1. ; IVMRECD - date/time query response received
  1. ; IVMCR - query closure reason code
  1. ; IVMCS - query closure source (1|DCD -- 2|DHCP)
  1. ;
  1. ; Output: none
  1. ;
  1. I '$G(DFN)!'$G(IVMCR)!'$G(IVMCS) G FINDQ
  1. N IVM,IVMD
  1. S IVM=0 F S IVM=$O(^IVM(301.62,"B",DFN,IVM)) Q:'IVM D
  1. .S IVMD=$G(^IVM(301.62,+IVM,0))
  1. .Q:$P(IVMD,"^",5)'=$G(IVMMSG) ; message, query ID's not same
  1. .D UPD(DFN,+IVM,$G(IVMRECD),IVMCR,IVMCS)
  1. FINDQ Q
  1. ;
  1. ;
  1. UPD(DFN,IVMDA,IVMRECD,IVMCR,IVMCS) ; Description: Used to update record found in IVM FINANCIAL QUERY LOG file.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ; IVMMSG - query message id
  1. ; IVMRECD - date/time query response received
  1. ; IVMCR - query closure reason code
  1. ; IVMCS - query closure source (1|DCD -- 2|DHCP)
  1. ;
  1. ; Output: none
  1. ;
  1. I '$G(DFN)!'$G(IVMDA)!'$G(IVMCR)!'$G(IVMCS) G FINDQ
  1. N DA,DIE,DR,IVMCRP,IVMOPT
  1. S IVMCRP=$O(^IVM(301.94,"AC",IVMCR,0)) S:'IVMCRP IVMCRP=IVMCR
  1. S DIE="^IVM(301.62,",DA=IVMDA
  1. S DR=".03////1"_$S($G(IVMRECD):";.06////"_IVMRECD,1:"")
  1. S DR=DR_";1.01////"_IVMCRP_";1.02///NOW;1.03////"_IVMCS
  1. D ^DIE
  1. ;
  1. ; determine if query reply requires user notification
  1. I '$$NOTIFY(IVMDA)
  1. ;
  1. UPDQ Q
  1. ;
  1. ;
  1. FINDMSG(MSGID) ;
  1. ; Description: Used to find a record in the IVM FINANCIAL QUERY LOG
  1. ; file, given the unique message id assigned to the query by the
  1. ; HL7 package.
  1. ;
  1. ; Input:
  1. ; MSGID - The unique id assigned to the query by the HL7 package and
  1. ; stored in the IVM FINANCIAL QUERY LOG as the HL7 MESSAGE
  1. ; CONTROL ID field.
  1. ;
  1. ; Output:
  1. ; Function Value - If successful, returns the ien of the record in
  1. ; the file, otherwise returns 0 on failure.
  1. ;
  1. Q:($G(MSGID)="") 0
  1. Q +$O(^IVM(301.62,"C",MSGID,0))
  1. ;
  1. ;
  1. GET(IEN,IVMQRY) ;
  1. ; Description: Used to obtain a record in the IVM FINANCIAL QUERY LOG
  1. ; file. The values are returned in the IVMQRY() array.
  1. ;
  1. ; Input:
  1. ; IEN - internal entry number of a record in the IVM FINANCIAL QUERY LOG file.
  1. ;
  1. ; Output:
  1. ; Function Value - 1 on success, 0 on failure.
  1. ; IVMQRY() array, pass by reference. Subscripts are:
  1. ; "DFN" - PATIENT field
  1. ; "SENT" - QUERY TRANS DT/TM field
  1. ; "STATUS" - QUERY STATUS field
  1. ; "TRANBY" - TRANSMITTED BY field
  1. ; "MSGID" - HL7 MESSAGE CONTROL ID field
  1. ; "RESPONSE" - QUERY RESPONSE REC'D DT/TM field
  1. ; "OPTION" - DHCP OPTION field
  1. ; "NOTIFY" - NOTIFY FLAG field
  1. ; "CLOSURE RSN" - CLOSURE REASON field
  1. ; "CLOSURE" - CLOSURE DT/TM field
  1. ; "CLOSURE SRC" - CLOSURE SOURCE field
  1. ;
  1. N IVMNODE
  1. K IVMQRY S IVMQRY=""
  1. Q:'$G(IEN) 0
  1. ;
  1. S IVMNODE=$G(^IVM(301.62,IEN,0))
  1. Q:IVMNODE="" 0
  1. ;
  1. S IVMQRY("DFN")=$P(IVMNODE,"^")
  1. S IVMQRY("SENT")=$P(IVMNODE,"^",2)
  1. S IVMQRY("STATUS")=$P(IVMNODE,"^",3)
  1. S IVMQRY("TRANBY")=$P(IVMNODE,"^",4)
  1. S IVMQRY("MSGID")=$P(IVMNODE,"^",5)
  1. S IVMQRY("RESPONSE")=$P(IVMNODE,"^",6)
  1. S IVMQRY("OPTION")=$P(IVMNODE,"^",7)
  1. S IVMQRY("NOTIFY")=$P(IVMNODE,"^",8)
  1. ;
  1. S IVMNODE=$G(^IVM(301.62,IEN,1))
  1. S IVMQRY("CLOSURE RSN")=$P(IVMNODE,"^")
  1. S IVMQRY("CLOSURE")=$P(IVMNODE,"^",2)
  1. S IVMQRY("CLOSURE SRC")=$P(IVMNODE,"^",3)
  1. ;
  1. Q 1
  1. ;
  1. ;
  1. DELETE(IEN) ;
  1. ; Description: Delete record in the IVM FINANCIAL QUERY LOG file,
  1. ; given the internal entry number (IEN).
  1. ;
  1. ; Input:
  1. ; IEN - The internal entry number of the record.
  1. ;
  1. ; Output:
  1. ; Function Value - 1 on success, 0 on failure.
  1. ;
  1. Q:'$G(IEN) 0
  1. N DIK,DA
  1. S DIK="^IVM(301.62,"
  1. S DA=IEN
  1. D ^DIK
  1. Q 1
  1. ;
  1. ;
  1. LASTQRY(DFN) ; Description: Used to find the last financial query for a patient.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ;
  1. ; Output:
  1. ; Function Value - If successful, returns the ien of the record in
  1. ; the file, otherwise returns 0 on failure.
  1. ;
  1. Q:'$G(DFN) 0
  1. N QRYDT
  1. S QRYDT=$O(^IVM(301.62,"ADT1",DFN,9999999.999999),-1)
  1. Q:'QRYDT 0
  1. Q $O(^IVM(301.62,"ADT1",DFN,QRYDT,0))
  1. ;
  1. ;
  1. OPEN(DFN) ; Description: Used to determine if a patient has a financial query that is open (QUERY STATUS=TRANSMITTED).
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ;
  1. ; Output:
  1. ; Function Value - returns 1 if open query, otherwise returns 0.
  1. ;
  1. N IVMQRY,IVMIEN,OPEN
  1. S OPEN=0
  1. S IVMIEN=$$LASTQRY($G(DFN))
  1. I IVMIEN,$$GET(IVMIEN,.IVMQRY) D
  1. .I 'IVMQRY("STATUS") S OPEN=1
  1. Q OPEN
  1. ;
  1. SENT(DFN,IVMDT) ; Description: Used to determine if a query was sent for a patien on a specific date.
  1. ;
  1. ; Input:
  1. ; DFN - IEN of patient record in PATIENT file
  1. ; IVMDT - (optional) Date/Time - default TODAY
  1. ;
  1. ; Output:
  1. ; Function Value: returns 1 if query sent on date, 0 otherwise.
  1. ;
  1. N IVMIDT,IVMIEN,IVMLDT,IVMQRY,SAMEDAY
  1. ;
  1. S SAMEDAY=0
  1. I '$G(DFN) G SENTQ
  1. S IVMIDT=$S($G(IVMDT)>0:IVMDT,1:DT) S:'$P(IVMIDT,".",2) IVMIDT=IVMIDT_.999999
  1. S IVMIEN=$$LASTQRY(DFN)
  1. I IVMIEN,$$GET(IVMIEN,.IVMQRY) D
  1. .I $P(IVMIDT,".")=$P(IVMQRY("SENT"),".") S SAMEDAY=1
  1. ;
  1. SENTQ Q SAMEDAY
  1. ;
  1. ;
  1. QRYQUE(DFN) ; Description: Queue off job to send a financial query to the
  1. ; the HEC. This does first check to see if a query is needed.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ;
  1. ; Output: none
  1. ;
  1. N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
  1. S ZTDESC="IVM Financial Query" ; task description
  1. S ZTDTH=$H ; task start time
  1. S ZTRTN="QUERY^IVMCQ2(DFN)" ; entry point of tasked routine
  1. S ZTSAVE("DFN")="" ; input parameters
  1. S ZTIO="" ; i/o device - (not needed)
  1. D ^%ZTLOAD
  1. Q
  1. ;
  1. QRYQUE2(DFN,DUZ,NOTIFY,OPTION) ; Description: Queue off job to send a financial query to the
  1. ; the HEC. This version does NOT first check to see if a query is
  1. ; needed, but does check to see if a query is currently open.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ; DUZ (optional)
  1. ; NOTIFY - (optional) 1 if the user requested notification when reply received
  1. ; OPTION - (optional) the option where the query was requested
  1. ;
  1. ; Output: none
  1. ;
  1. N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
  1. S ZTDESC="IVM Financial Query" ; task description
  1. S ZTDTH=$H ; task start time
  1. S ZTRTN="QUERY2^IVMCQ1(DFN,$G(DUZ),$G(NOTIFY),$G(OPTION),,1)" ; entry point of tasked routine
  1. S ZTSAVE("DFN")="",ZTSAVE("DUZ")="",ZTSAVE("NOTIFY")="",ZTSAVE("OPTION")=""
  1. S ZTIO="" ; i/o device - (not needed)
  1. D ^%ZTLOAD
  1. Q
  1. ;
  1. QUERY(DFN) ; Description: Determine if a financial query should be sent to the HEC.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient record in PATIENT file
  1. ;
  1. ; Output: none
  1. ;
  1. ;
  1. I '$G(DFN) Q
  1. I '$$NEED^IVMCQ(DFN,0) Q
  1. ;
  1. ; send query for patient
  1. I $$QUERY^IVMCQ1(DFN)
  1. ;
  1. Q
  1. ;
  1. ;
  1. NOTIFY(QRYIEN) ; Description: Send notification message of reply received for financial query.
  1. ;
  1. ; Input:
  1. ; QRYIEN - ien of record in IVM FINANCIAL QUERY LOG file
  1. ;
  1. ; Output:
  1. ; Function Value: 1 on success, 0 on failure
  1. ;
  1. N DIFROM,IVMTEXT,PATIENT,QARRAY,SUCCESS,XMDUZ,XMTEXT,XMSUB,XMY,XMZ
  1. ;
  1. S SUCCESS=0
  1. ;
  1. I '$G(QRYIEN) G MSGQ
  1. ;
  1. ; obtain record from IVM FINANCIAL QUERY LOG
  1. I '$$GET(QRYIEN,.QARRAY) G MSGQ
  1. ;
  1. ; check NOTIFY FLAG
  1. I '$G(QARRAY("NOTIFY")) G MSGQ
  1. ;
  1. ; obtain patient identifiers
  1. I '$$GETPAT^IVMUFNC($G(QARRAY("DFN")),.PATIENT) G MSGQ
  1. ;
  1. ; build notification message
  1. S XMDUZ="IVM PACKAGE"
  1. S XMY(QARRAY("TRANBY")_"@"_$G(^XMB("NETNAME")))=""
  1. S XMSUB="Financial Query Reply for: "_PATIENT("NAME")_" ("_PATIENT("SSN")_")"
  1. S XMTEXT="IVMTEXT("
  1. S IVMTEXT(1)="A reply to the financial query that you sent has been received."
  1. S IVMTEXT(2)=" "
  1. S IVMTEXT(3)=" Patient Name: "_PATIENT("NAME")
  1. S IVMTEXT(4)=" Patient SSN: "_PATIENT("SSN")
  1. S IVMTEXT(5)=" "
  1. S IVMTEXT(6)=" Query Transmission Date/Time: "_$$EXTERNAL^DILFD(301.62,.02,"F",QARRAY("SENT"))
  1. S IVMTEXT(7)=" Query Response Date/Time: "_$$EXTERNAL^DILFD(301.62,.06,"F",QARRAY("RESPONSE"))
  1. S IVMTEXT(8)=" "
  1. S IVMTEXT(9)=" Closure Reason: "_$$EXTERNAL^DILFD(301.62,1.01,"F",QARRAY("CLOSURE RSN"))
  1. S IVMTEXT(10)=" Closure Source: "_$$EXTERNAL^DILFD(301.62,1.03,"F",QARRAY("CLOSURE SRC"))
  1. ;
  1. D ^XMD
  1. ;
  1. S SUCCESS=1
  1. ;
  1. MSGQ Q SUCCESS