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

IVMUFNC.m

Go to the documentation of this file.
  1. IVMUFNC ;ALB/MLI/PHH/SCK,TDM - IVM GENERIC FUNCTIONS ; 6/30/08 4:11pm
  1. ;;2.0;INCOME VERIFICATION MATCH;**3,11,17,34,95,94,115**;21-OCT-94;Build 28
  1. ;;Per VHA Directive 10-93-142, this routine should not be modified.
  1. ;
  1. ; This routine contains generic calls for use throughout IVM
  1. ;
  1. INIT(EID,HL,INT) ; initialize variables for 1.6 HL7/IVM
  1. S EID=$G(EID),INT=$G(INT)
  1. S HLDAP="IVM" D INIT^HLFNC2(EID,.HL,INT)
  1. S (HLEVN,IVMCT)=0 ; initialize segment and message counters
  1. ;;D NOW^%DTC S HLSDT=%
  1. Q
  1. ;
  1. ;
  1. CLEAN ; clean-up variables for HL7/IVM (as defined by call to INIT)
  1. D KILL^HLTRANS
  1. K HLEVN,HLMTN,HLSDT,IVMCT
  1. Q
  1. ;
  1. ;
  1. BATCH ; put BHS and BTS segments into TMP global
  1. ;
  1. ; Input - HLMTN as HL7 message type being sent in this batch (REQUIRED)
  1. ; HLEVN as number of HL7 messages in batch (REQUIRED)
  1. ; IVMCT as subscript in TMP global where BTS segment goes (REQ)
  1. ; HLSEC (optional) as security (see BHS^HLFNC1)
  1. ; HLMSA (optional) as message ack variables (see BHS^HLFNC1)
  1. ;
  1. ; ****Also assumes all HL7 variables returned from****
  1. ; INIT^HLTRANS are defined
  1. ;
  1. Q ; LINE ADDED FOR HL7 1.6
  1. S HLSEC=$G(HLSEC),HLMSA=$G(HLMSA)
  1. S ^TMP("HLS",$J,HLSDT,0)=$$BHS^HLFNC1(HLMTN,HLSEC,HLMSA)
  1. S ^TMP("HLS",$J,HLSDT,IVMCT)="BTS"_HLFS_HLEVN ; trailer
  1. Q
  1. ;
  1. ;
  1. IVM(DFN,IVMDT) ; extrinsic function - should this pt be transmitted to IVM?
  1. ;
  1. ; Input - DFN as internal entry number of PATIENT file
  1. ; IVMDT as date of test (default DT)
  1. ;
  1. ; Output - 1 if pt should be sent to IVM, 0 otherwise
  1. ;
  1. N X,Y
  1. S DFN=$G(DFN) I '$D(^DPT(+DFN,0)) G IVMQ
  1. S IVMDT=$S($G(IVMDT):IVMDT,1:DT)
  1. S X=$$LST^DGMTU(DFN,IVMDT)
  1. I $E($P(X,"^",2),1,3)'=$E(IVMDT,1,3) K IVMDT G IVMQ ; not in same year
  1. S X=$G(^DGMT(408.31,+X,0)) I 'X G IVMQ ; can't find MT entry for date
  1. I $P(X,"^",3)=6 S:'$$INS(DFN,IVMDT) Y=1 G IVMQ ; C/no insurance...send
  1. I $P(X,"^",3)'=4 G IVMQ ; not cat A
  1. I ($P(X,"^",4)-$P(X,"^",15)>$P(X,"^",12))!$P(X,"^",10) G IVMQ ; income-deduct expenses>threshold (hardship) or adjudicated
  1. S Y=1
  1. IVMQ Q +$G(Y)
  1. ;
  1. ;
  1. INS(DFN,IVMDT) ; extrinsic function to see if pt has active insurance
  1. ;
  1. ; Input - DFN as internal entry number of PATIENT file
  1. ; IVMDT [optional] as date to compute ins coverage for
  1. ;
  1. ; Output - 1 if yes, 0 if no
  1. ;
  1. Q $S($$INSUR^IBBAPI(DFN,$G(IVMDT))=1:1,1:0)
  1. ;
  1. ;
  1. MAIL(IVMGRP) ; Transmit to members of Mail Group. Before D MAIL^IVMUFNC()
  1. ; set XMSUB = to subject and set IVMTEXT array to message.
  1. ;
  1. ;Input:
  1. ; IVMGRP - optional parameter, = to name of a mailgroup to send the
  1. ; message to. If not sent, the IVM Site Parameter file is
  1. ; used to determine the mailgroup.
  1. ;
  1. N DIFROM,XMDUZ,XMTEXT,XMSTRIP,XMROU,XMY,XMZ,XMDF
  1. S XMDF=""
  1. S XMDUZ="IVM PACKAGE"
  1. S XMTEXT="IVMTEXT("
  1. I '$L($G(IVMGRP)) D
  1. .S IVMGRP=$P($G(^XMB(3.8,+$P($G(^IVM(301.9,1,0)),"^",2),0)),"^")
  1. S XMY("G."_IVMGRP_"@"_^XMB("NETNAME"))=""
  1. D ^XMD
  1. K IVMTEXT,XMDUZ,XMSUB,XMTEXT,XMY
  1. Q
  1. ;
  1. ;
  1. LTD(DFN,IVMQUERY) ; Find Last Treatment Date
  1. ; Input: DFN -- pointer to the patient in file #2
  1. ; IVMQUERY("LTD") -- # of the QUERY that is currently open or
  1. ; undefined, zero, or null if no QUERY opened for
  1. ; last treatment date
  1. ; Output: LTD -- Last Treatment Date (really last date seen at
  1. ; the facility)
  1. ;
  1. N LTD,SDSTOP,X,Z,IVMQ
  1. ;
  1. ; - need a patient
  1. S IVMQ=$G(IVMQUERY("LTD"))
  1. I '$G(DFN) S LTD=0 G LTDQ
  1. ;
  1. ; - if current inpatient, set LTD = today and quit
  1. I $G(^DPT(DFN,.105)) S LTD=DT G LTDQ
  1. ;
  1. ; - get the last discharge date
  1. S LTD=+$O(^DGPM("ATID3",DFN,"")) S:LTD LTD=9999999.9999999-LTD\1 S:LTD>DT LTD=DT
  1. ;
  1. ; - get the last registration date and compare to LTD
  1. S X=+$O(^DPT(DFN,"DIS",0)) I X S X=9999999-X\1 S:X>LTD LTD=X
  1. ;
  1. ; - get the last appointment or stop after LTD (if any)
  1. K ^TMP("DIERR",$J)
  1. I $G(IVMQ) D ACTIVE^SDQ(.IVMQ,"FALSE","SET") ;clear QUERY results
  1. I '$G(IVMQ) D
  1. .D OPEN^SDQ(.IVMQ) Q:'$G(IVMQ)
  1. .D INDEX^SDQ(.IVMQ,"PATIENT/DATE","SET")
  1. .D SCANCB^SDQ(.IVMQ,"I $S($P(SDOE0,U,8)=2:1,$P(SDOE0,U,8)=1:$$APPT^IVMUFNC(SDOE0),1:0) S LTD=SDOE0\1,SDSTOP=1","SET")
  1. .S IVMQUERY("LTD")=IVMQ
  1. ;
  1. D PAT^SDQ(.IVMQ,DFN,"SET")
  1. D DATE^SDQ(.IVMQ,LTD+.000001,9999999,"SET")
  1. D ACTIVE^SDQ(.IVMQ,"TRUE","SET")
  1. D SCAN^SDQ(.IVMQ,"BACKWARD")
  1. K ^TMP("DIERR",$J)
  1. ;
  1. LTDQ ;
  1. Q $S(LTD:$$HLDATE^HLFNC(LTD),1:HLQ)
  1. ;
  1. APPT(SDOE0) ;Determine if appt associated with encounter is in a valid state
  1. ; Quit when Outpatient Encounter STATUS is CHECKED OUT
  1. Q:$P(SDOE0,U,12)=2 1
  1. ; Quit when Outpatient Encounter STATUS is ACTION REQUIRED and the
  1. ; Appointment Status is SCHEDULED/KEPT
  1. N DGARRAY,SDCNT,SDSTAT,SDDTTM S DGARRAY("FLDS")=3,DGARRAY(4)=+$P(SDOE0,U,2)
  1. S DGARRAY(1)=$P(SDOE0,U),DGARRAY("SORT")="P",DGARRAY("MAX")=1
  1. S SDCNT=$$SDAPI^SDAMA301(.DGARRAY),SDSTAT=""
  1. I SDCNT>0 D
  1. .S SDDTTM=$O(^TMP($J,"SDAMA301",DGARRAY(4),0))
  1. .I SDDTTM S SDSTAT=$P($P($G(^TMP($J,"SDAMA301",DGARRAY(4),SDDTTM)),U,3),";")
  1. K ^TMP($J,"SDAMA301")
  1. Q:(($P(SDOE0,U,12)=14)&(SDSTAT="R")) 1
  1. Q 0
  1. ;
  1. OUTTR(IVMINT,IVMPAR,IVMST) ; - Transform IVMINT to a displayable value
  1. ; Input: IVMINT -- internal value of demographic element
  1. ; received from IVM
  1. ; IVMPAR -- Zeroth node of the entry in file #301.92
  1. ; for the demographic element IVMINT
  1. ; IVMST -- [optional] pointer to the STATE (#5) file
  1. ; Required to transform the county code
  1. ; Output: IVMOUT -- Displayable value for IVMINT
  1. ;
  1. N IVMOUT,Z S IVMOUT=IVMINT
  1. I $G(IVMINT)=""!($G(IVMPAR)="") S IVMOUT="" G OUTTRQ
  1. ;
  1. ; - use special transform for county
  1. I $G(IVMST),$P(IVMPAR,"^",2)="PID12" S IVMOUT=$P($G(^DIC(5,IVMST,1,IVMINT,0)),"^")
  1. ;
  1. ; - transform the internal value if necessary
  1. I $P(IVMPAR,"^",6) S IVMOUT=$$EXPAND($P(IVMPAR,"^",4),$P(IVMPAR,"^",5),IVMINT)
  1. ;
  1. OUTTRQ Q IVMOUT
  1. ;
  1. ;
  1. EXPAND(FILE,FIELD,VALUE) ; - returns internal data in an output format
  1. N Y,C S Y=VALUE
  1. I 'FILE!('FIELD)!(VALUE="") G EXPQ
  1. S Y=VALUE,C=$P(^DD(FILE,FIELD,0),"^",2) D Y^DIQ
  1. EXPQ Q Y
  1. ;
  1. ;
  1. GETPAT(DFN,IVMPAT) ;
  1. ; Description: Used to obtain identifying information for a patient
  1. ; in the PATIENT file and place it in the IVMPAT() array.
  1. ;
  1. ; Input:
  1. ; DFN - ien of patient in PATIENT file
  1. ;
  1. ; Output:
  1. ; Function Value - 1 on success, 0 on failure
  1. ; IVMPAT - (pass by reference) On success, this array will contain
  1. ; the patient identifing information. Array subscripts are:
  1. ; "DFN" - ien PATIENT file
  1. ; "NAME" - patient name
  1. ; "SSN" - patient Social Security Number
  1. ; "DOB" - patient date of birth (FM format)
  1. ; "SEX" - patient sex
  1. ; "ICN" - patient ICN
  1. ;
  1. N IVMNODE
  1. Q:'$G(DFN) 0
  1. K IVMPAT S IVMPAT=""
  1. ;
  1. ; obtain patient record
  1. S IVMNODE=$G(^DPT(DFN,0))
  1. Q:IVMNODE="" 0
  1. ;
  1. S IVMPAT("DFN")=DFN
  1. S IVMPAT("NAME")=$P(IVMNODE,"^")
  1. S IVMPAT("SEX")=$P(IVMNODE,"^",2)
  1. S IVMPAT("DOB")=$P(IVMNODE,"^",3)
  1. S IVMPAT("SSN")=$P(IVMNODE,"^",9)
  1. S IVMPAT("ICN")=$$GETICN^MPIF001(DFN)
  1. Q 1
  1. ;
  1. LOOKUP(SSN,DOB,SEX,ERROR) ;
  1. ;Description: This function will do a search for the patient based on
  1. ;the identifying information provided. The function will be successful
  1. ;only if a single patient is found matching the identifiers provided.
  1. ;
  1. ;Inputs:
  1. ; SSN - patient Social Security Number
  1. ; DOB - patient date of birth (FM format)
  1. ; SEX - patient sex
  1. ;Outputs:
  1. ; Function Value - patient DFN if successful, 0 otherwise
  1. ; ERROR - if unsuccessful, an error message is returned (optional, pass by reference)
  1. ;
  1. N DFN,NODE
  1. ;
  1. I $G(SSN)="" S ERROR="INVALID SSN" Q 0
  1. S DFN=$O(^DPT("SSN",SSN,0))
  1. I 'DFN S ERROR="SSN NOT FOUND" Q 0
  1. I $O(^DPT("SSN",SSN,DFN)) S ERROR="MULTIPLE PATIENTS MATCHING SSN" Q 0
  1. S NODE=$G(^DPT(DFN,0))
  1. I $P(NODE,"^",2)'=SEX S ERROR="SEX DOES NOT MATCH" Q 0
  1. I $E($P(NODE,"^",3),1,3)'=$E(DOB,1,3) S ERROR="DOB DOES NOT MATCH" Q 0
  1. I $E($P(NODE,"^",3),4,5),$E($P(NODE,"^",3),4,5)'=$E(DOB,4,5) S ERROR="DOB DOES NOT MATCH" Q 0
  1. Q DFN
  1. ;
  1. MATCH(DFN,ICN,DOB,SEX,CFLG,ERROR) ;
  1. ;Description: This function will try to match the patient based on
  1. ;the identifying information provided. The function will be
  1. ;successful only if the patient is found matching the identifiers
  1. ;provided.
  1. ;
  1. ;Inputs:
  1. ; DFN - patient DFN
  1. ; ICN - patient ICN
  1. ; DOB - patient date of birth (FM format)
  1. ; SEX - patient sex
  1. ; CFLG - Compare Flag (Default="IDS", I=ICN, D=DOB, S=Sex)
  1. ;Outputs:
  1. ; Function Value: 1 - patient matched successfully, 0 - otherwise
  1. ; ERROR - if unsuccessful, an error message is returned (optional, pass by reference)
  1. N NODE
  1. I $G(DFN)="" S ERROR="INVALID DFN" Q 0
  1. I $G(CFLG)="" S CFLG="IDS"
  1. S NODE=$G(^DPT(DFN,0)) I NODE="" S ERROR="DFN NOT FOUND" Q 0
  1. I CFLG["I",$$GETICN^MPIF001(DFN)'=$G(ICN) S ERROR="ICN DOES NOT MATCH" Q 0
  1. I CFLG["S",$P(NODE,"^",2)'=$G(SEX) S ERROR="SEX DOES NOT MATCH" Q 0
  1. I CFLG["D",$E($P(NODE,"^",3),1,3)'=$E($G(DOB),1,3) S ERROR="DOB DOES NOT MATCH" Q 0
  1. I CFLG["D",$E($P(NODE,"^",3),4,5),$E($P(NODE,"^",3),4,5)'=$E($G(DOB),4,5) S ERROR="DOB DOES NOT MATCH" Q 0
  1. Q 1
  1. PARSPID3(PID3,PID3ARY) ;
  1. ;Description: This function will parse seq 3 of PID segment
  1. ;Input : PID3 - Array for seq. 3 of PID segment
  1. ;Output: PID3ARY("NI") - Value - ICN
  1. ; PID3ARY("PI") - Value - DFN
  1. I $D(PID3(3)) D
  1. .I $O(PID3(3,"")) D Q
  1. ..S COMP=0 F S COMP=$O(PID3(3,COMP)) Q:COMP="" D
  1. ...I $P(PID3(3,COMP),$E(HLECH),5)="PI" S PID3ARY("PI")=$P(PID3(3,COMP),$E(HLECH))
  1. ...I $P(PID3(3,COMP),$E(HLECH),5)="NI" S PID3ARY("NI")=$P(PID3(3,COMP),$E(HLECH))
  1. .I $P(PID3(3),$E(HLECH),5)="PI" S PID3ARY("PI")=$P(PID3(3),$E(HLECH))
  1. Q