DGVTS00 ;7DELTA/KDC - VTS Stand alone Option routine ;07-MAR-2012
;;5.3;REGISTRATION;**853**;07-MAR-2012;Build 104
Q
; This routine was built for the Veterans Transportation Service (VTS) project.
; A flat file is created from the RouteMatch database containing its Veteran population.
; The flat file will contain Veteran name, address and phone number. The routine reads
; a record from the flat file and tries to find the corresponding Veteran in VistA.
; A match is only made if all fields (name, city, state, zip code and phone number) match.
; Otherwise the record that was read in is written out to an exception report file
; containing Veteran's for whom the process could not determine a match. If a match
; is found then the ICN associated with the Veteran is appended to the record that
; was read in and written out to the output file. The output file will be sent to
; RouteMatch to be loaded into their database.
;
Q
;
; Entry point for the process
; A call to allow for the variable ZEOF to catch End of File
;
EN ;
N DLM,STOP,INPUTFILE,REC,FOUND,ICN,IEN,NAME
N RMNAME,FNAME,LNAME,MI,PATADD,FLG,CITY,ZIP
N STATE,PHONE,DFN,RMREC,DA,DIE,DR,IO,STATION
N ICNFILE,REPORTFILE,DIR,INPUT,POP,ADD1,ADD2
; Define the delimiter characters
S DLM=","
;
; Get Primary Station Number from File 389.9 - Station Number (Time Sensitive)
; Node 0 Piece 4 ^VA(389.9
; SITE^VASITE returns the Station Number in the third argument
S STATION=+$P($$SITE^VASITE(),"^",3)
;
;
; Call to open the file
; If any of the files could not be opened the process stops
;
S STOP=0
D OPENFILE Q:STOP
;
; Read records from input file
; Extract fields from the record
; Compare the VistA patient information to the data in the fields
; from the input record
LOOP ;
USE INPUTFILE
READ REC:5 I $$STATUS^%ZISH G CL
I REC=$C(13,10) G LOOP
D EXDATA
D COMP
G LOOP
; Compare information
COMP ;
; Initialize variables
; If variable FOUND is set than we have a successful match
; Variable IEN is used to loop through the patient file for a set
; Veteran name
; (there can be several patients with the same name)
; Variable ICN will be populated with the matching Veterans ICN
;
S FOUND=0
S IEN=0
S ICN=""
S RMNAME=LNAME_","_FNAME
S:MI]"" RMNAME=RMNAME_" "_MI
S NAME=RMNAME
;
; If name field is missing skip compare and go straight to writing
; data to a report file
;
I NAME']"" G CPOUT
;
; Loop through patient name index to try and find the matching
; Veteran
; with the given name or a match was found
CP1 S IEN=$O(^DPT("B",NAME,IEN)) G:FOUND>1 CPOUT G:'IEN CP
;
; Set variable PATADD with the patient's address information
;
S PATADD=$$UP($G(^DPT(IEN,.11)))
;
; Variable FLG is used to indicate if data is a match or not
;
S FLG=0
;
I $P(PATADD,U,4)=CITY,$P(PATADD,U,6)=ZIP S FLG=1
;
; If data did not match loop back to see if there are more patients
; with the given name to check
;
; Reset FLG and compare STATE field
;
I FLG=0 G CP1
S FLG=0
I $P(PATADD,U,5)]"",STATE=$P($G(^DIC(5,$P(PATADD,U,5),0)),U,2) S FLG=1
I STATE="",$P(PATADD,U,5)="" S FLG=1
;
; If data did not match loop back to see if there are more patients
; with the given name to check
;
I FLG=0 G CP1
S FLG=0
;
; compare components of the phone number
;
; If phone number matches set variable FOUND and ICN
I $TR(PHONE,"()-. :")=$TR($P($G(^DPT(IEN,.13)),U),"()-. :") D
. S FOUND=FOUND+1
. ;S ICN=$P($G(^DPT(IEN,"MPI")),U)
. S DFN=IEN
. S ICN=+($$GETICN^MPIF001(DFN))
;
; If MPIF001 returns -1 error - patient not in database
; Set FOUND to indicate Veteran not found and place
; entry on Exception report
;
I +ICN=-1 S FOUND=0 G CPOUT
;
G CP1
;
; Look to see if there are additional patients to examine
;
CP S NAME=$O(^DPT("B",NAME)) G:NAME="" CPOUT
;
; if there was no middle initial then the name must match exactly
;
I MI="",NAME'=RMNAME G CPOUT
I MI]"",NAME'[RMNAME G CPOUT
;
; if there was a middle initial then keep looking as long as the
; VistA patient name totaly contains the name from RouteMatch
;
G CP1
;
; Determine which file to write information in based on the value
; of the variable FOUND
CPOUT ;
I FOUND=0!(FOUND>1) U REPORTFILE W REC,! Q
; If match was found then build record with additional data elements
; to be returned
;
; Record format
; 1. DFN
; 2. Last 4 of SSN
; 3. Last Name
; 4. First Name
; 5. Middle Initial
; 6. Address Line 1
; 7. Address Line 2
; 8. City
; 9. State
; 10. Zip
; 11. Phone
; 12. ICN
;
S RMREC=""
S $P(RMREC,",")=$$TRIM(DFN)
S $P(RMREC,",",2)=$E($P($G(^DPT(DFN,0)),U,9),6,9)
S $P(RMREC,",",3)=$$TRIM(LNAME)
S $P(RMREC,",",4)=$$TRIM(FNAME)
S $P(RMREC,",",5)=$$TRIM(MI)
S $P(RMREC,",",6)=$$TRIM(ADD1)
S $P(RMREC,",",7)=$$TRIM(ADD2)
S $P(RMREC,",",8)=$$TRIM(CITY)
S $P(RMREC,",",9)=$$TRIM(STATE)
S $P(RMREC,",",10)=$$TRIM(ZIP)
S PHONE=$TR(PHONE,"()-. :")
I $L(PHONE)=10 S PHONE="("_$E(PHONE,1,3)_")"_$E(PHONE,4,6)_"-"_$E(PHONE,7,10)
S $P(RMREC,",",11)=$$TRIM(PHONE)
S $P(RMREC,",",12)=$$TRIM(ICN)
;
U ICNFILE W RMREC,!
;
; Match found - Set the Patient Flag indicating
; patient is part of the VTS program
;
L +^DPT(DFN):5 I '$T QUIT
S DIE=2,DA=DFN,DR="3000///1" D ^DIE
L -^DPT(DFN)
;
QUIT
;
; Open files
; Open the input file and the two output files (the exception report
; and the ICN included files
; If the process could not open the files write information to the
; screen and stop the process.
;
OPENFILE ;
R !,"Enter the directory where files are located: ",DIR:60,!
I DIR="" W !,"No directory supplied, process stopped" S STOP=1 Q
R !,"Enter input file name: ",INPUT:60,!!
I INPUT="" W !,"No input file name, process stopped" S STOP=1 Q
; Opening input file
;
;
D OPEN^%ZISH("",DIR,INPUT,"R")
I POP D
. W !,"Unable to open input file: "_DIR_INPUT,!,"Process stopped"
. S STOP=1
;
I STOP=1 Q
S INPUTFILE=IO
;
; Opening ICN included file
;
;
D OPEN^%ZISH("",DIR,STATION_"_ICNOUTPUT.CSV","WN")
I POP D
. W !,"Unable to open output file: "_DIR_STATION_"_ICNOUTPUT.CSV",!,"Process stopped"
. S IO=INPUTFILE
. D CLOSE^%ZISH(INPUTFILE) S STOP=1 Q
;
I STOP=1 Q
S ICNFILE=IO
;
; Opening the exception exception report file
;
;
D OPEN^%ZISH("",DIR,STATION_"_EXCEPTION.CSV","WN")
I POP D
. W !,"Unable to open report file: "_DIR_STATION_"_EXCEPTION.CSV",!,"Process stopped"
. S IO=INPUTFILE
. D CLOSE^%ZISH(INPUTFILE)
. S IO=ICNFILE
. D CLOSE^%ZISH(ICNFILE)
. S STOP=1
S REPORTFILE=IO
Q
;
; Extract fields from the input record
; variable REC contains the input record information
; layout of record is
;
;Last Name
;First Name
;Middle Initial
;Address Line 1
;Address Line 2
;City
;State
;ZIP
;Phone Number
EXDATA ;
S LNAME=$$TRIM($$UP($P(REC,DLM)))
S FNAME=$$TRIM($$UP($P(REC,DLM,2)))
S MI=$$TRIM($$UP($P(REC,DLM,3)))
S ADD1=$$UP($P(REC,DLM,4))
S ADD2=$$UP($P(REC,DLM,5))
S CITY=$$TRIM($$UP($P(REC,DLM,6)))
S STATE=$$TRIM($$UP($P(REC,DLM,7)))
S ZIP=$$TRIM($$UP($P(REC,DLM,8)))
S PHONE=$$UP($P(REC,DLM,9))
Q
; Change lowercase to uppercase
UP(X) Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
;
;Remove leading and trailing spaces
TRIM(DATA) ;
N I,J
F I=1:1 Q:$E(DATA,I)'=" "
F J=$L(DATA):-1 Q:$E(DATA,J)'=" "
Q $E(DATA,I,J)
;
; Close all files and write that the process has completed
;
CL ;
S IO=ICNFILE
D CLOSE^%ZISH(ICNFILE)
S IO=REPORTFILE
D CLOSE^%ZISH(REPORTFILE)
S IO=INPUTFILE
D CLOSE^%ZISH(INPUTFILE)
U 0
WRITE !,"Process complete",!
QUIT
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDGVTS00 7823 printed Nov 22, 2024@18:09:11 Page 2
DGVTS00 ;7DELTA/KDC - VTS Stand alone Option routine ;07-MAR-2012
+1 ;;5.3;REGISTRATION;**853**;07-MAR-2012;Build 104
+2 QUIT
+3 ; This routine was built for the Veterans Transportation Service (VTS) project.
+4 ; A flat file is created from the RouteMatch database containing its Veteran population.
+5 ; The flat file will contain Veteran name, address and phone number. The routine reads
+6 ; a record from the flat file and tries to find the corresponding Veteran in VistA.
+7 ; A match is only made if all fields (name, city, state, zip code and phone number) match.
+8 ; Otherwise the record that was read in is written out to an exception report file
+9 ; containing Veteran's for whom the process could not determine a match. If a match
+10 ; is found then the ICN associated with the Veteran is appended to the record that
+11 ; was read in and written out to the output file. The output file will be sent to
+12 ; RouteMatch to be loaded into their database.
+13 ;
+14 QUIT
+15 ;
+16 ; Entry point for the process
+17 ; A call to allow for the variable ZEOF to catch End of File
+18 ;
EN ;
+1 NEW DLM,STOP,INPUTFILE,REC,FOUND,ICN,IEN,NAME
+2 NEW RMNAME,FNAME,LNAME,MI,PATADD,FLG,CITY,ZIP
+3 NEW STATE,PHONE,DFN,RMREC,DA,DIE,DR,IO,STATION
+4 NEW ICNFILE,REPORTFILE,DIR,INPUT,POP,ADD1,ADD2
+5 ; Define the delimiter characters
+6 SET DLM=","
+7 ;
+8 ; Get Primary Station Number from File 389.9 - Station Number (Time Sensitive)
+9 ; Node 0 Piece 4 ^VA(389.9
+10 ; SITE^VASITE returns the Station Number in the third argument
+11 SET STATION=+$PIECE($$SITE^VASITE(),"^",3)
+12 ;
+13 ;
+14 ; Call to open the file
+15 ; If any of the files could not be opened the process stops
+16 ;
+17 SET STOP=0
+18 DO OPENFILE
if STOP
QUIT
+19 ;
+20 ; Read records from input file
+21 ; Extract fields from the record
+22 ; Compare the VistA patient information to the data in the fields
+23 ; from the input record
LOOP ;
+1 USE INPUTFILE
+2 READ REC:5
IF $$STATUS^%ZISH
GOTO CL
+3 IF REC=$CHAR(13,10)
GOTO LOOP
+4 DO EXDATA
+5 DO COMP
+6 GOTO LOOP
+7 ; Compare information
COMP ;
+1 ; Initialize variables
+2 ; If variable FOUND is set than we have a successful match
+3 ; Variable IEN is used to loop through the patient file for a set
+4 ; Veteran name
+5 ; (there can be several patients with the same name)
+6 ; Variable ICN will be populated with the matching Veterans ICN
+7 ;
+8 SET FOUND=0
+9 SET IEN=0
+10 SET ICN=""
+11 SET RMNAME=LNAME_","_FNAME
+12 if MI]""
SET RMNAME=RMNAME_" "_MI
+13 SET NAME=RMNAME
+14 ;
+15 ; If name field is missing skip compare and go straight to writing
+16 ; data to a report file
+17 ;
+18 IF NAME']""
GOTO CPOUT
+19 ;
+20 ; Loop through patient name index to try and find the matching
+21 ; Veteran
+22 ; with the given name or a match was found
CP1 SET IEN=$ORDER(^DPT("B",NAME,IEN))
if FOUND>1
GOTO CPOUT
if 'IEN
GOTO CP
+1 ;
+2 ; Set variable PATADD with the patient's address information
+3 ;
+4 SET PATADD=$$UP($GET(^DPT(IEN,.11)))
+5 ;
+6 ; Variable FLG is used to indicate if data is a match or not
+7 ;
+8 SET FLG=0
+9 ;
+10 IF $PIECE(PATADD,U,4)=CITY
IF $PIECE(PATADD,U,6)=ZIP
SET FLG=1
+11 ;
+12 ; If data did not match loop back to see if there are more patients
+13 ; with the given name to check
+14 ;
+15 ; Reset FLG and compare STATE field
+16 ;
+17 IF FLG=0
GOTO CP1
+18 SET FLG=0
+19 IF $PIECE(PATADD,U,5)]""
IF STATE=$PIECE($GET(^DIC(5,$PIECE(PATADD,U,5),0)),U,2)
SET FLG=1
+20 IF STATE=""
IF $PIECE(PATADD,U,5)=""
SET FLG=1
+21 ;
+22 ; If data did not match loop back to see if there are more patients
+23 ; with the given name to check
+24 ;
+25 IF FLG=0
GOTO CP1
+26 SET FLG=0
+27 ;
+28 ; compare components of the phone number
+29 ;
+30 ; If phone number matches set variable FOUND and ICN
+31 IF $TRANSLATE(PHONE,"()-. :")=$TRANSLATE($PIECE($GET(^DPT(IEN,.13)),U),"()-. :")
Begin DoDot:1
+32 SET FOUND=FOUND+1
+33 ;S ICN=$P($G(^DPT(IEN,"MPI")),U)
+34 SET DFN=IEN
+35 SET ICN=+($$GETICN^MPIF001(DFN))
End DoDot:1
+36 ;
+37 ; If MPIF001 returns -1 error - patient not in database
+38 ; Set FOUND to indicate Veteran not found and place
+39 ; entry on Exception report
+40 ;
+41 IF +ICN=-1
SET FOUND=0
GOTO CPOUT
+42 ;
+43 GOTO CP1
+44 ;
+45 ; Look to see if there are additional patients to examine
+46 ;
CP SET NAME=$ORDER(^DPT("B",NAME))
if NAME=""
GOTO CPOUT
+1 ;
+2 ; if there was no middle initial then the name must match exactly
+3 ;
+4 IF MI=""
IF NAME'=RMNAME
GOTO CPOUT
+5 IF MI]""
IF NAME'[RMNAME
GOTO CPOUT
+6 ;
+7 ; if there was a middle initial then keep looking as long as the
+8 ; VistA patient name totaly contains the name from RouteMatch
+9 ;
+10 GOTO CP1
+11 ;
+12 ; Determine which file to write information in based on the value
+13 ; of the variable FOUND
CPOUT ;
+1 IF FOUND=0!(FOUND>1)
USE REPORTFILE
WRITE REC,!
QUIT
+2 ; If match was found then build record with additional data elements
+3 ; to be returned
+4 ;
+5 ; Record format
+6 ; 1. DFN
+7 ; 2. Last 4 of SSN
+8 ; 3. Last Name
+9 ; 4. First Name
+10 ; 5. Middle Initial
+11 ; 6. Address Line 1
+12 ; 7. Address Line 2
+13 ; 8. City
+14 ; 9. State
+15 ; 10. Zip
+16 ; 11. Phone
+17 ; 12. ICN
+18 ;
+19 SET RMREC=""
+20 SET $PIECE(RMREC,",")=$$TRIM(DFN)
+21 SET $PIECE(RMREC,",",2)=$EXTRACT($PIECE($GET(^DPT(DFN,0)),U,9),6,9)
+22 SET $PIECE(RMREC,",",3)=$$TRIM(LNAME)
+23 SET $PIECE(RMREC,",",4)=$$TRIM(FNAME)
+24 SET $PIECE(RMREC,",",5)=$$TRIM(MI)
+25 SET $PIECE(RMREC,",",6)=$$TRIM(ADD1)
+26 SET $PIECE(RMREC,",",7)=$$TRIM(ADD2)
+27 SET $PIECE(RMREC,",",8)=$$TRIM(CITY)
+28 SET $PIECE(RMREC,",",9)=$$TRIM(STATE)
+29 SET $PIECE(RMREC,",",10)=$$TRIM(ZIP)
+30 SET PHONE=$TRANSLATE(PHONE,"()-. :")
+31 IF $LENGTH(PHONE)=10
SET PHONE="("_$EXTRACT(PHONE,1,3)_")"_$EXTRACT(PHONE,4,6)_"-"_$EXTRACT(PHONE,7,10)
+32 SET $PIECE(RMREC,",",11)=$$TRIM(PHONE)
+33 SET $PIECE(RMREC,",",12)=$$TRIM(ICN)
+34 ;
+35 USE ICNFILE
WRITE RMREC,!
+36 ;
+37 ; Match found - Set the Patient Flag indicating
+38 ; patient is part of the VTS program
+39 ;
+40 LOCK +^DPT(DFN):5
IF '$TEST
QUIT
+41 SET DIE=2
SET DA=DFN
SET DR="3000///1"
DO ^DIE
+42 LOCK -^DPT(DFN)
+43 ;
+44 QUIT
+45 ;
+46 ; Open files
+47 ; Open the input file and the two output files (the exception report
+48 ; and the ICN included files
+49 ; If the process could not open the files write information to the
+50 ; screen and stop the process.
+51 ;
OPENFILE ;
+1 READ !,"Enter the directory where files are located: ",DIR:60,!
+2 IF DIR=""
WRITE !,"No directory supplied, process stopped"
SET STOP=1
QUIT
+3 READ !,"Enter input file name: ",INPUT:60,!!
+4 IF INPUT=""
WRITE !,"No input file name, process stopped"
SET STOP=1
QUIT
+5 ; Opening input file
+6 ;
+7 ;
+8 DO OPEN^%ZISH("",DIR,INPUT,"R")
+9 IF POP
Begin DoDot:1
+10 WRITE !,"Unable to open input file: "_DIR_INPUT,!,"Process stopped"
+11 SET STOP=1
End DoDot:1
+12 ;
+13 IF STOP=1
QUIT
+14 SET INPUTFILE=IO
+15 ;
+16 ; Opening ICN included file
+17 ;
+18 ;
+19 DO OPEN^%ZISH("",DIR,STATION_"_ICNOUTPUT.CSV","WN")
+20 IF POP
Begin DoDot:1
+21 WRITE !,"Unable to open output file: "_DIR_STATION_"_ICNOUTPUT.CSV",!,"Process stopped"
+22 SET IO=INPUTFILE
+23 DO CLOSE^%ZISH(INPUTFILE)
SET STOP=1
QUIT
End DoDot:1
+24 ;
+25 IF STOP=1
QUIT
+26 SET ICNFILE=IO
+27 ;
+28 ; Opening the exception exception report file
+29 ;
+30 ;
+31 DO OPEN^%ZISH("",DIR,STATION_"_EXCEPTION.CSV","WN")
+32 IF POP
Begin DoDot:1
+33 WRITE !,"Unable to open report file: "_DIR_STATION_"_EXCEPTION.CSV",!,"Process stopped"
+34 SET IO=INPUTFILE
+35 DO CLOSE^%ZISH(INPUTFILE)
+36 SET IO=ICNFILE
+37 DO CLOSE^%ZISH(ICNFILE)
+38 SET STOP=1
End DoDot:1
+39 SET REPORTFILE=IO
+40 QUIT
+41 ;
+42 ; Extract fields from the input record
+43 ; variable REC contains the input record information
+44 ; layout of record is
+45 ;
+46 ;Last Name
+47 ;First Name
+48 ;Middle Initial
+49 ;Address Line 1
+50 ;Address Line 2
+51 ;City
+52 ;State
+53 ;ZIP
+54 ;Phone Number
EXDATA ;
+1 SET LNAME=$$TRIM($$UP($PIECE(REC,DLM)))
+2 SET FNAME=$$TRIM($$UP($PIECE(REC,DLM,2)))
+3 SET MI=$$TRIM($$UP($PIECE(REC,DLM,3)))
+4 SET ADD1=$$UP($PIECE(REC,DLM,4))
+5 SET ADD2=$$UP($PIECE(REC,DLM,5))
+6 SET CITY=$$TRIM($$UP($PIECE(REC,DLM,6)))
+7 SET STATE=$$TRIM($$UP($PIECE(REC,DLM,7)))
+8 SET ZIP=$$TRIM($$UP($PIECE(REC,DLM,8)))
+9 SET PHONE=$$UP($PIECE(REC,DLM,9))
+10 QUIT
+11 ; Change lowercase to uppercase
UP(X) QUIT $TRANSLATE(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+1 ;
+2 ;Remove leading and trailing spaces
TRIM(DATA) ;
+1 NEW I,J
+2 FOR I=1:1
if $EXTRACT(DATA,I)'=" "
QUIT
+3 FOR J=$LENGTH(DATA):-1
if $EXTRACT(DATA,J)'=" "
QUIT
+4 QUIT $EXTRACT(DATA,I,J)
+5 ;
+6 ; Close all files and write that the process has completed
+7 ;
CL ;
+1 SET IO=ICNFILE
+2 DO CLOSE^%ZISH(ICNFILE)
+3 SET IO=REPORTFILE
+4 DO CLOSE^%ZISH(REPORTFILE)
+5 SET IO=INPUTFILE
+6 DO CLOSE^%ZISH(INPUTFILE)
+7 USE 0
+8 WRITE !,"Process complete",!
+9 QUIT