TIUPNCV ;SLC/DJP-SF/JLI ;3/3/98 14:00
;;1.0;TEXT INTEGRATION UTILITIES;**9**;Jun 20, 1997
;
DRIVER ;Entry point; initializes counters
S TIUFPRIV=1
S:'$D(U) U="^" S (GMRPCTR,TIUCTR,ERRCTR)=0 S:'$D(GMRPST) GMRPST=0
;above- if not a Restart, initializes counter
S $P(^TIU(8925.97,1,0),U,2)=$$NOW^XLFDT
S GMRPFINI=$P($G(^TIU(8925.97,1,0)),U,8)
S TIUSTRT=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN")
;
RESTART ;Restarts Progress Note conversion
S GMRPIFN=GMRPST
F S GMRPIFN=$O(^GMR(121,GMRPIFN)) Q:'GMRPIFN Q:GMRPIFN=$G(GMRPFINI) D
. D MAIN
S TIUEND=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN")
;
CLEANUP ;Releases Bulletin & kills variables and scratch files
W !!?20,"***** CONVERSION HAS FINISHED *****",!
STOP D REPORT^TIUPNCV4
K GMRPCTR,TIUCTR,GMRPST,GMRPIFN,GMRPFL,TIUFPRIV
K ^TMP("TIUIFN")
I $P($G(^TIU(8925.97,1,2)),U,3)'>0
I S $P(^TIU(8925.97,1,0),U,3)=$$NOW^XLFDT
S $P(^TIU(8925.97,1,2),U,3)=0
Q
;
MAIN ;Main loop for each record
I $P($G(^TIU(8925.97,1,2)),U,3)>0
I S TIUEND=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN") G STOP
N PN S GMRPCTR=GMRPCTR+1
;
MAIN1 ;
Q:'+$P($G(^GMR(121,GMRPIFN,1)),U,3)
Q:$P($G(^GMR(121,GMRPIFN,5)),U)="1"
;do not convert unsigned/uncosigned notes
;
;ignore if test patient note
Q:$E($P($G(^DPT(+$P($G(^GMR(121,GMRPIFN,0)),U,2),0)),U,9),1,5)="00000"
;
Q:$D(^GMR(121,"CNV",GMRPIFN)) ;already converted
;
S GMR0=$G(^GMR(121,GMRPIFN,0)) ;using naked ref below
S GMR1=$G(^(1)),GMR5=$G(^(5)),GMR9=$G(^(9)),GMR100=$G(^(100))
F I=1,2,3,5,6 S PN($P(".01^.02^.03^.04^.05^.06",U,I))=$P(GMR0,U,I)
F I=1:1:5 S PN($P("1^2^3^4^4.1",U,I))=$P(GMR1,U,I)
F I=1:1:4 S PN($P("5^6^7^7.1",U,I))=$P(GMR5,U,I)
S PN(9)=$P(GMR9,U)
S PN(100)=$P(GMR100,U)
I (PN(.02)="")!(PN(.03)="")!(PN(.05)="")!(PN(1)="")!(PN(2)="") D Q
. S PROBLEM="Progress Note - IFN #"_GMRPIFN_" is incomplete."
. D ERRORLOG^TIUPNCV3 K BADREC,PN,PROBLEM Q
I PN(100),'$D(^GMR(121,"CNV",PN(100))) D Q
. S PROBLEM="Progress note - IFN # "_GMRPIFN_", addendum to unconverted parent note IFN # "_PN(100)
. D ERRORLOG^TIUPNCV3 K BADREC,PN,PROBLEM Q
;
D TIUFLDS
;
D TITLE^TIUPNCV3 I $D(BADREC) D CLEANREC Q
;
D RTNODE I $D(TIU("BAD")) D CLEANREC Q
;
D SETFIELD^TIUPNCV1 I $D(BADREC) D WIPEOUT Q
;
;Builds the TIU record
S DIE="^TIU(8925,",DA=TIUIFN D COPY I $D(BADREC) D WIPEOUT Q
D TEXT
D SIGSET ; D:TIU(1505)'="" SIGSET D:TIU(1511)'="" COSET
D ^TIUPNCVX ;*** May uncomment for direct X-ref set ***
;S DA=TIUIFN,DIK="^TIU(8925," D IX1^DIK ; DO SETS ON X-REFS FOR ENTRY
S $P(^TIU(8925.97,1,0),U,5)=GMRPIFN ;last PN successfully processed
S $P(^TIU(8925.97,1,2),U,2)=TIUIFN ;last IEN used within ^TIU(8925,
I TIUCTR=1 S $P(^TIU(8925.97,1,2),U,1)=TIUIFN ;first IEN in ^TIU(8925,
S TIUCTR=TIUCTR+1
S $P(^TIU(8925.97,1,0),U,6)=TIUCTR ;records # of TIU documents built
S ^GMR(121,"CNV",GMRPIFN)=TIUIFN
I '(TIUIFN#500) W "."
D CLEANREC
Q
;
CLEANREC ;Cleans partition after entry of record
K TIU,ESIG,PN,ATH,P1,P2,P3,P4,P5,C1,C2,C3,PNT,BADREC,TIUD,TIUNM,TIUT
K TMSG,TYP,COSIGN,TIUCOMPO,TIUCTYP,TYPE
K ^TMP("TIUBRK",GMRPIFN)
Q
;
WIPEOUT ;Clears ^TIU(8925 if record is found to be incomplete
S DIK="^TIU(8925,",DA=TIUIFN D ^DIK
K ^TMP("TIUIFN",GMRPIFN)
I $G(TIU(.03)) S X=TIU(.03) D SUB^AUPNVSIT
D CLEANREC
Q
;
TIUFLDS ;Sets TIU variables with PN data
;
; TIU(.01) SET IN TITLESET TIUPNCV3
S TIU(.02)=PN(.02) ; .02 PATIENT - .02 PATIENT
; TIU(.03) SET IN VISIT TIUPNCV1
; TIU(.04) SET IN TITLESET TIUPNCV3
; TIU(.05) SET IN SIGVAR/COSVAR TIUPNCV1
S TIU(.06)=$S(+PN(100):$G(^GMR(121,"CNV",+PN(100))),1:"")
S TIU(.07)=PN(.03) ; USE DATE/TIME OF NOTE FOR EPISODE DATE TIME
S TIU(.13)="E"
S TIU(1201)=PN(.01) ; 1201 ENTRY DATE/TIME - .01 FILE ENTRY DATE
S (TIU(1202),TIU(1204))=PN(2) ; 1202 AUTHOR/DICTATOR - 2 AUTHOR
; expected signer 1204 in TIU is PN(2)- AUTHOR in GMR
S (TIU(1205),TIU(1211))=PN(9) ; 1205 HOSPITAL LOCATION - 9 LOCATION
S TIU(1301)=PN(.03) ; 1301 REFERENCE DATE - .03 DATE/TIME OF PROG NOTE
S TIU(1302)=PN(.05) ; 1302 ENTERED BY - .05 TRANSCRIBER
S TIU(1303)="C"
S TIU(1501)=PN(4) ; 1501 SIGNATURE DATE/TIME - 4 DATE/TIME SIGNED
S TIU(1502)=PN(3) ; 1502 SIGNED BY - 3 E-SIG (AUTHOR)
S (TIU(1503),TIU(1504),TIU(1505))=""
S TIU(1506)=PN(5) ; 1506 COSIGNATURE NEEDED - 5 COSIGNATURE REQUIRED
S TIU(1507)=PN(7) ; 1507 COSIGNATURE DATE/TIME - 7 DATE/TIME COSIGNED
S (TIU(1208),TIU(1508))=PN(6) ; 1508 COSIGNED BY - 6 COSIGNER
S (TIU(1509),TIU(1510),TIU(1511))=""
S (TIU(1512),TIU("SIGCHART"))=PN(4.1) ;1512 - 4.1 SIGNATURE IN CHART
S (TIU(1513),TIU("COSCHART"))=PN(7.1) ;1513 - 7.1 COSIGNATURE IN CHART
S TIU("MHCONV")=PN(.06)
S TIU("PARENT")=$S(+PN(100):$G(^GMR(121,"CNV",+PN(100))),1:"")
S TIU("SPECDT")=$P(TIU(1201),".",1)
S TIU("TITLE")=PN(1)
Q
;
RTNODE ;Sets 0 Node for TIU record
S TIUFPRIV=1
S (DIC,DLAYGO)=8925,DIC(0)="LN",X=""""_"`"_TIU(.01)_""""
D ^DIC I +Y<1 S TIU("BAD")=1 Q
S TIUIFN=+Y,^TMP("TIUIFN",GMRPIFN)=TIUIFN
Q
;
COPY ;Writes data from ^GMR(121,GMRPIFN --> ^TIU(8925,TIUIFN
S ^TIU(8925,TIUIFN,0)=TIU(.01)_U_TIU(.02)_U_TIU(.03)_U_TIU(.04)_U_TIU(.05)_U_TIU(.06)_U_TIU(.07)_U_U_U_U_U_U_TIU(.13)
S ^TIU(8925,TIUIFN,12)=TIU(1201)_U_TIU(1202)_U_U_TIU(1204)_U_TIU(1205)_U_U_U_TIU(1208)_U_U_U_TIU(1211)
S ^TIU(8925,TIUIFN,13)=TIU(1301)_U_TIU(1302)_U_TIU(1303)
I $D(TIUNEWTY) S DR=".01////"_TIUNEWTY D ^DIE K TIUNEWTY
Q
;
TEXT ;Copies text
I $D(^TMP("TIUHOLD",GMRPIFN)) M ^TIU(8925,TIUIFN,"TEXT")=^TMP("TIUHOLD",GMRPIFN,10) K ^TMP("TIUHOLD",GMRPIFN),^TMP("TIUMERGE",GMRPIFN) Q
Q
;
SIGSET ;Sets ^TIU(8925 signature fields
N X
I TIU(1502)>0 S TIU(1503)=$$ENCRYPT^TIULC1(TIU(1503),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")")),TIU(1504)=$$ENCRYPT^TIULC1(TIU(1504),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
I TIU(1508)>0 S TIU(1509)=$$ENCRYPT^TIULC1(TIU(1509),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")")),TIU(1510)=$$ENCRYPT^TIULC1(TIU(1510),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
S X=TIU(1501)_U_TIU(1502)_U_TIU(1503)_U_TIU(1504)_U_TIU(1505)
S ^TIU(8925,TIUIFN,15)=X_U_TIU(1506)_U_TIU(1507)_U_TIU(1508)_U_TIU(1509)_U_TIU(1510)_U_TIU(1511)_U_TIU(1512)_U_TIU(1513)
Q
TIUPNCV ;SLC/DJP-SF/JLI ;3/3/98 14:00
+1 ;;1.0;TEXT INTEGRATION UTILITIES;**9**;Jun 20, 1997
+2 ;
DRIVER ;Entry point; initializes counters
+1 SET TIUFPRIV=1
+2 IF '$DATA(U)
SET U="^"
SET (GMRPCTR,TIUCTR,ERRCTR)=0
IF '$DATA(GMRPST)
SET GMRPST=0
+3 ;above- if not a Restart, initializes counter
+4 SET $PIECE(^TIU(8925.97,1,0),U,2)=$$NOW^XLFDT
+5 SET GMRPFINI=$PIECE($GET(^TIU(8925.97,1,0)),U,8)
+6 SET TIUSTRT=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN")
+7 ;
RESTART ;Restarts Progress Note conversion
+1 SET GMRPIFN=GMRPST
+2 FOR
SET GMRPIFN=$ORDER(^GMR(121,GMRPIFN))
IF 'GMRPIFN
QUIT
IF GMRPIFN=$GET(GMRPFINI)
QUIT
Begin DoDot:1
+3 DO MAIN
End DoDot:1
+4 SET TIUEND=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN")
+5 ;
CLEANUP ;Releases Bulletin & kills variables and scratch files
+1 WRITE !!?20,"***** CONVERSION HAS FINISHED *****",!
STOP DO REPORT^TIUPNCV4
+1 KILL GMRPCTR,TIUCTR,GMRPST,GMRPIFN,GMRPFL,TIUFPRIV
+2 KILL ^TMP("TIUIFN")
+3 IF $PIECE($GET(^TIU(8925.97,1,2)),U,3)'>0
+4 IF $TEST
SET $PIECE(^TIU(8925.97,1,0),U,3)=$$NOW^XLFDT
+5 SET $PIECE(^TIU(8925.97,1,2),U,3)=0
+6 QUIT
+7 ;
MAIN ;Main loop for each record
+1 IF $PIECE($GET(^TIU(8925.97,1,2)),U,3)>0
+2 IF $TEST
SET TIUEND=$$DATE^TIULS($$NOW^TIULC,"MM/DD/YY HR:MIN")
GOTO STOP
+3 NEW PN
SET GMRPCTR=GMRPCTR+1
+4 ;
MAIN1 ;
+1 IF '+$PIECE($GET(^GMR(121,GMRPIFN,1)),U,3)
QUIT
+2 IF $PIECE($GET(^GMR(121,GMRPIFN,5)),U)="1"
QUIT
+3 ;do not convert unsigned/uncosigned notes
+4 ;
+5 ;ignore if test patient note
+6 IF $EXTRACT($PIECE($GET(^DPT(+$PIECE($GET(^GMR(121,GMRPIFN,0)),U,2),0)),U,9),1,5)="00000"
QUIT
+7 ;
+8 ;already converted
IF $DATA(^GMR(121,"CNV",GMRPIFN))
QUIT
+9 ;
+10 ;using naked ref below
SET GMR0=$GET(^GMR(121,GMRPIFN,0))
+11 SET GMR1=$GET(^(1))
SET GMR5=$GET(^(5))
SET GMR9=$GET(^(9))
SET GMR100=$GET(^(100))
+12 FOR I=1,2,3,5,6
SET PN($PIECE(".01^.02^.03^.04^.05^.06",U,I))=$PIECE(GMR0,U,I)
+13 FOR I=1:1:5
SET PN($PIECE("1^2^3^4^4.1",U,I))=$PIECE(GMR1,U,I)
+14 FOR I=1:1:4
SET PN($PIECE("5^6^7^7.1",U,I))=$PIECE(GMR5,U,I)
+15 SET PN(9)=$PIECE(GMR9,U)
+16 SET PN(100)=$PIECE(GMR100,U)
+17 IF (PN(.02)="")!(PN(.03)="")!(PN(.05)="")!(PN(1)="")!(PN(2)="")
Begin DoDot:1
+18 SET PROBLEM="Progress Note - IFN #"_GMRPIFN_" is incomplete."
+19 DO ERRORLOG^TIUPNCV3
KILL BADREC,PN,PROBLEM
QUIT
End DoDot:1
QUIT
+20 IF PN(100)
IF '$DATA(^GMR(121,"CNV",PN(100)))
Begin DoDot:1
+21 SET PROBLEM="Progress note - IFN # "_GMRPIFN_", addendum to unconverted parent note IFN # "_PN(100)
+22 DO ERRORLOG^TIUPNCV3
KILL BADREC,PN,PROBLEM
QUIT
End DoDot:1
QUIT
+23 ;
+24 DO TIUFLDS
+25 ;
+26 DO TITLE^TIUPNCV3
IF $DATA(BADREC)
DO CLEANREC
QUIT
+27 ;
+28 DO RTNODE
IF $DATA(TIU("BAD"))
DO CLEANREC
QUIT
+29 ;
+30 DO SETFIELD^TIUPNCV1
IF $DATA(BADREC)
DO WIPEOUT
QUIT
+31 ;
+32 ;Builds the TIU record
+33 SET DIE="^TIU(8925,"
SET DA=TIUIFN
DO COPY
IF $DATA(BADREC)
DO WIPEOUT
QUIT
+34 DO TEXT
+35 ; D:TIU(1505)'="" SIGSET D:TIU(1511)'="" COSET
DO SIGSET
+36 ;*** May uncomment for direct X-ref set ***
DO ^TIUPNCVX
+37 ;S DA=TIUIFN,DIK="^TIU(8925," D IX1^DIK ; DO SETS ON X-REFS FOR ENTRY
+38 ;last PN successfully processed
SET $PIECE(^TIU(8925.97,1,0),U,5)=GMRPIFN
+39 ;last IEN used within ^TIU(8925,
SET $PIECE(^TIU(8925.97,1,2),U,2)=TIUIFN
+40 ;first IEN in ^TIU(8925,
IF TIUCTR=1
SET $PIECE(^TIU(8925.97,1,2),U,1)=TIUIFN
+41 SET TIUCTR=TIUCTR+1
+42 ;records # of TIU documents built
SET $PIECE(^TIU(8925.97,1,0),U,6)=TIUCTR
+43 SET ^GMR(121,"CNV",GMRPIFN)=TIUIFN
+44 IF '(TIUIFN#500)
WRITE "."
+45 DO CLEANREC
+46 QUIT
+47 ;
CLEANREC ;Cleans partition after entry of record
+1 KILL TIU,ESIG,PN,ATH,P1,P2,P3,P4,P5,C1,C2,C3,PNT,BADREC,TIUD,TIUNM,TIUT
+2 KILL TMSG,TYP,COSIGN,TIUCOMPO,TIUCTYP,TYPE
+3 KILL ^TMP("TIUBRK",GMRPIFN)
+4 QUIT
+5 ;
WIPEOUT ;Clears ^TIU(8925 if record is found to be incomplete
+1 SET DIK="^TIU(8925,"
SET DA=TIUIFN
DO ^DIK
+2 KILL ^TMP("TIUIFN",GMRPIFN)
+3 IF $GET(TIU(.03))
SET X=TIU(.03)
DO SUB^AUPNVSIT
+4 DO CLEANREC
+5 QUIT
+6 ;
TIUFLDS ;Sets TIU variables with PN data
+1 ;
+2 ; TIU(.01) SET IN TITLESET TIUPNCV3
+3 ; .02 PATIENT - .02 PATIENT
SET TIU(.02)=PN(.02)
+4 ; TIU(.03) SET IN VISIT TIUPNCV1
+5 ; TIU(.04) SET IN TITLESET TIUPNCV3
+6 ; TIU(.05) SET IN SIGVAR/COSVAR TIUPNCV1
+7 SET TIU(.06)=$SELECT(+PN(100):$GET(^GMR(121,"CNV",+PN(100))),1:"")
+8 ; USE DATE/TIME OF NOTE FOR EPISODE DATE TIME
SET TIU(.07)=PN(.03)
+9 SET TIU(.13)="E"
+10 ; 1201 ENTRY DATE/TIME - .01 FILE ENTRY DATE
SET TIU(1201)=PN(.01)
+11 ; 1202 AUTHOR/DICTATOR - 2 AUTHOR
SET (TIU(1202),TIU(1204))=PN(2)
+12 ; expected signer 1204 in TIU is PN(2)- AUTHOR in GMR
+13 ; 1205 HOSPITAL LOCATION - 9 LOCATION
SET (TIU(1205),TIU(1211))=PN(9)
+14 ; 1301 REFERENCE DATE - .03 DATE/TIME OF PROG NOTE
SET TIU(1301)=PN(.03)
+15 ; 1302 ENTERED BY - .05 TRANSCRIBER
SET TIU(1302)=PN(.05)
+16 SET TIU(1303)="C"
+17 ; 1501 SIGNATURE DATE/TIME - 4 DATE/TIME SIGNED
SET TIU(1501)=PN(4)
+18 ; 1502 SIGNED BY - 3 E-SIG (AUTHOR)
SET TIU(1502)=PN(3)
+19 SET (TIU(1503),TIU(1504),TIU(1505))=""
+20 ; 1506 COSIGNATURE NEEDED - 5 COSIGNATURE REQUIRED
SET TIU(1506)=PN(5)
+21 ; 1507 COSIGNATURE DATE/TIME - 7 DATE/TIME COSIGNED
SET TIU(1507)=PN(7)
+22 ; 1508 COSIGNED BY - 6 COSIGNER
SET (TIU(1208),TIU(1508))=PN(6)
+23 SET (TIU(1509),TIU(1510),TIU(1511))=""
+24 ;1512 - 4.1 SIGNATURE IN CHART
SET (TIU(1512),TIU("SIGCHART"))=PN(4.1)
+25 ;1513 - 7.1 COSIGNATURE IN CHART
SET (TIU(1513),TIU("COSCHART"))=PN(7.1)
+26 SET TIU("MHCONV")=PN(.06)
+27 SET TIU("PARENT")=$SELECT(+PN(100):$GET(^GMR(121,"CNV",+PN(100))),1:"")
+28 SET TIU("SPECDT")=$PIECE(TIU(1201),".",1)
+29 SET TIU("TITLE")=PN(1)
+30 QUIT
+31 ;
RTNODE ;Sets 0 Node for TIU record
+1 SET TIUFPRIV=1
+2 SET (DIC,DLAYGO)=8925
SET DIC(0)="LN"
SET X=""""_"`"_TIU(.01)_""""
+3 DO ^DIC
IF +Y<1
SET TIU("BAD")=1
QUIT
+4 SET TIUIFN=+Y
SET ^TMP("TIUIFN",GMRPIFN)=TIUIFN
+5 QUIT
+6 ;
COPY ;Writes data from ^GMR(121,GMRPIFN --> ^TIU(8925,TIUIFN
+1 SET ^TIU(8925,TIUIFN,0)=TIU(.01)_U_TIU(.02)_U_TIU(.03)_U_TIU(.04)_U_TIU(.05)_U_TIU(.06)_U_TIU(.07)_U_U_U_U_U_U_TIU(.13)
+2 SET ^TIU(8925,TIUIFN,12)=TIU(1201)_U_TIU(1202)_U_U_TIU(1204)_U_TIU(1205)_U_U_U_TIU(1208)_U_U_U_TIU(1211)
+3 SET ^TIU(8925,TIUIFN,13)=TIU(1301)_U_TIU(1302)_U_TIU(1303)
+4 IF $DATA(TIUNEWTY)
SET DR=".01////"_TIUNEWTY
DO ^DIE
KILL TIUNEWTY
+5 QUIT
+6 ;
TEXT ;Copies text
+1 IF $DATA(^TMP("TIUHOLD",GMRPIFN))
MERGE ^TIU(8925,TIUIFN,"TEXT")=^TMP("TIUHOLD",GMRPIFN,10)
KILL ^TMP("TIUHOLD",GMRPIFN),^TMP("TIUMERGE",GMRPIFN)
QUIT
+2 QUIT
+3 ;
SIGSET ;Sets ^TIU(8925 signature fields
+1 NEW X
+2 IF TIU(1502)>0
SET TIU(1503)=$$ENCRYPT^TIULC1(TIU(1503),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
SET TIU(1504)=$$ENCRYPT^TIULC1(TIU(1504),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
+3 IF TIU(1508)>0
SET TIU(1509)=$$ENCRYPT^TIULC1(TIU(1509),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
SET TIU(1510)=$$ENCRYPT^TIULC1(TIU(1510),1,$$CHKSUM^TIULC("^TIU(8925,"_TIUIFN_",""TEXT"")"))
+4 SET X=TIU(1501)_U_TIU(1502)_U_TIU(1503)_U_TIU(1504)_U_TIU(1505)
+5 SET ^TIU(8925,TIUIFN,15)=X_U_TIU(1506)_U_TIU(1507)_U_TIU(1508)_U_TIU(1509)_U_TIU(1510)_U_TIU(1511)_U_TIU(1512)_U_TIU(1513)
+6 QUIT