BEHOENIN ;MSC/IND/DKM - Installation Support ;06-Sep-2011 14:33;PLS
;;1.1;BEH COMPONENTS;**005001,005004,005005,005008**;Mar 20, 2007
;=================================================================
PREINIT ;EP - Preinitialization
Q
POSTINIT ;EP - Postinitialization
Q
; Add a report to the ORRPW ADT VISITS report header.
ADDCHILD(RPT) ;
N X,Y
S X=$$FIND1^DIC(101.24,,"X","ORRPW ADT VISITS")
S Y=$$FIND1^DIC(101.24,,"X",RPT)
I X,Y D:'$O(^ORD(101.24,X,10,"B",Y,0))
.N FDA
.S FDA(101.241,"+1,"_X_",",.01)="`"_Y
.D UPDATE^DIE("E","FDA")
Q
GETUNLK ;
N DATA,DAYS
S GBL=$NA(^TMP("BEHOENCX"))
S DAYS=$$GET^XPAR("SYS","BEHOENCX VISIT LOCKED")
D:'DAYS ADD^XPAR("SYS","BEHOENCX VISIT LOCKED",,3)
D ENVAL^XPAR(GBL,"BEHOENCX VISIT LOCK OVERRIDE",,,1)
D REMUNLK
Q
;
REMUNLK ;
N ENT
S ENT=""
F S ENT=$O(^TMP("BEHOENCX",ENT)) Q:ENT="" D
.D NDEL^XPAR(ENT,"BEHOENCX VISIT LOCK OVERRIDE")
Q
SETUNLK ;
N ENT,INT,VAL
S ENT=""
F S ENT=$O(^TMP("BEHOENCX",ENT)) Q:ENT="" D
.S INT=0 F S INT=$O(^TMP("BEHOENCX",ENT,INT)) Q:'INT D
..S VAL=$$GET^XPAR("SYS","BEHOENCX VISIT LOCKED")
..S VAL=$S(VAL:VAL,1:2)
..S VAL=$$FMADD^XLFDT($$DT^XLFDT(),VAL)
..D ADD^XPAR(ENT,"BEHOENCX VISIT LOCK OVERRIDE","`"_INT,VAL)
K ^TMP("BEHOENCX")
Q
VPOV ;Repoint any text provider narratives
;First,find the date this patch was first installed
N P6
S P6="" S P6=$O(^XPD(9.7,"B","EHR*1.1*6",P6)) Q:P6="" D
.S IDATE=$P(^XPD(9.7,P6,0),U,3)
.Q:IDATE=""
.D FIXNAR
Q
FIXNAR ;Loop through and find all POVs since patch 6 was installed
;check for text in the .o4 field and fix
N DAT,CNT,VIEN,VPOV,NAR,NIEN
S DAT=IDATE,CNT=0
F S DAT=$O(^AUPNVSIT("B",DAT)) Q:'DAT D
.F VIEN=0:0 S VIEN=$O(^AUPNVSIT("B",DAT,VIEN)) Q:'VIEN D
..F VPOV=0:0 S VPOV=$O(^AUPNVPOV("AD",VIEN,VPOV)) Q:'VPOV D
...N X
...S X=$G(^AUPNVPOV(VPOV,0))
...S NAR=$P(X,U,4)
...I +NAR=0 D
....S NIEN=$$FNDNARR(NAR,1)
....S $P(^AUPNVPOV(VPOV,0),U,4)=NIEN,CNT=CNT+1
....D MES("Repaired VPOV record #"_VPOV)
D MES("Bad entries detected and repaired: "_CNT)
Q
; Display message in MSG and optionally set quit flag to QUIT
MES(MSG,QUIT) ; EP
D BMES^XPDUTL(" "_$G(MSG))
S:$G(QUIT) XPDQUIT=QUIT
Q
; Find/create narrative text in narrative file, returning IEN
FNDNARR(NARR,CREATE) ;EP
N IEN,FDA,TRC,RET
Q:'$L(NARR) ""
S NARR=$$STRPNAR^BEHOENPC(NARR) ;P7
S IEN=0,TRC=$E(NARR,1,30),NARR=$E(NARR,1,160),CREATE=$G(CREATE,1)
F S IEN=$O(^AUTNPOV("B",TRC,IEN)) Q:'IEN Q:$P($G(^AUTNPOV(IEN,0)),U)=NARR
Q:IEN!'CREATE IEN
S FDA(9999999.27,"+1,",.01)=NARR
D UPDATE^DIE("E","FDA","IEN")
Q +$G(IEN(1))
BEHOENIN ;MSC/IND/DKM - Installation Support ;06-Sep-2011 14:33;PLS
+1 ;;1.1;BEH COMPONENTS;**005001,005004,005005,005008**;Mar 20, 2007
+2 ;=================================================================
PREINIT ;EP - Preinitialization
+1 QUIT
POSTINIT ;EP - Postinitialization
+1 QUIT
+2 ; Add a report to the ORRPW ADT VISITS report header.
ADDCHILD(RPT) ;
+1 NEW X,Y
+2 SET X=$$FIND1^DIC(101.24,,"X","ORRPW ADT VISITS")
+3 SET Y=$$FIND1^DIC(101.24,,"X",RPT)
+4 IF X
IF Y
IF '$ORDER(^ORD(101.24,X,10,"B",Y,0))
Begin DoDot:1
+5 NEW FDA
+6 SET FDA(101.241,"+1,"_X_",",.01)="`"_Y
+7 DO UPDATE^DIE("E","FDA")
End DoDot:1
+8 QUIT
GETUNLK ;
+1 NEW DATA,DAYS
+2 SET GBL=$NAME(^TMP("BEHOENCX"))
+3 SET DAYS=$$GET^XPAR("SYS","BEHOENCX VISIT LOCKED")
+4 IF 'DAYS
DO ADD^XPAR("SYS","BEHOENCX VISIT LOCKED",,3)
+5 DO ENVAL^XPAR(GBL,"BEHOENCX VISIT LOCK OVERRIDE",,,1)
+6 DO REMUNLK
+7 QUIT
+8 ;
REMUNLK ;
+1 NEW ENT
+2 SET ENT=""
+3 FOR
SET ENT=$ORDER(^TMP("BEHOENCX",ENT))
IF ENT=""
QUIT
Begin DoDot:1
+4 DO NDEL^XPAR(ENT,"BEHOENCX VISIT LOCK OVERRIDE")
End DoDot:1
+5 QUIT
SETUNLK ;
+1 NEW ENT,INT,VAL
+2 SET ENT=""
+3 FOR
SET ENT=$ORDER(^TMP("BEHOENCX",ENT))
IF ENT=""
QUIT
Begin DoDot:1
+4 SET INT=0
FOR
SET INT=$ORDER(^TMP("BEHOENCX",ENT,INT))
IF 'INT
QUIT
Begin DoDot:2
+5 SET VAL=$$GET^XPAR("SYS","BEHOENCX VISIT LOCKED")
+6 SET VAL=$SELECT(VAL:VAL,1:2)
+7 SET VAL=$$FMADD^XLFDT($$DT^XLFDT(),VAL)
+8 DO ADD^XPAR(ENT,"BEHOENCX VISIT LOCK OVERRIDE","`"_INT,VAL)
End DoDot:2
End DoDot:1
+9 KILL ^TMP("BEHOENCX")
+10 QUIT
VPOV ;Repoint any text provider narratives
+1 ;First,find the date this patch was first installed
+2 NEW P6
+3 SET P6=""
SET P6=$ORDER(^XPD(9.7,"B","EHR*1.1*6",P6))
IF P6=""
QUIT
Begin DoDot:1
+4 SET IDATE=$PIECE(^XPD(9.7,P6,0),U,3)
+5 IF IDATE=""
QUIT
+6 DO FIXNAR
End DoDot:1
+7 QUIT
FIXNAR ;Loop through and find all POVs since patch 6 was installed
+1 ;check for text in the .o4 field and fix
+2 NEW DAT,CNT,VIEN,VPOV,NAR,NIEN
+3 SET DAT=IDATE
SET CNT=0
+4 FOR
SET DAT=$ORDER(^AUPNVSIT("B",DAT))
IF 'DAT
QUIT
Begin DoDot:1
+5 FOR VIEN=0:0
SET VIEN=$ORDER(^AUPNVSIT("B",DAT,VIEN))
IF 'VIEN
QUIT
Begin DoDot:2
+6 FOR VPOV=0:0
SET VPOV=$ORDER(^AUPNVPOV("AD",VIEN,VPOV))
IF 'VPOV
QUIT
Begin DoDot:3
+7 NEW X
+8 SET X=$GET(^AUPNVPOV(VPOV,0))
+9 SET NAR=$PIECE(X,U,4)
+10 IF +NAR=0
Begin DoDot:4
+11 SET NIEN=$$FNDNARR(NAR,1)
+12 SET $PIECE(^AUPNVPOV(VPOV,0),U,4)=NIEN
SET CNT=CNT+1
+13 DO MES("Repaired VPOV record #"_VPOV)
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+14 DO MES("Bad entries detected and repaired: "_CNT)
+15 QUIT
+16 ; Display message in MSG and optionally set quit flag to QUIT
MES(MSG,QUIT) ; EP
+1 DO BMES^XPDUTL(" "_$GET(MSG))
+2 IF $GET(QUIT)
SET XPDQUIT=QUIT
+3 QUIT
+4 ; Find/create narrative text in narrative file, returning IEN
FNDNARR(NARR,CREATE) ;EP
+1 NEW IEN,FDA,TRC,RET
+2 IF '$LENGTH(NARR)
QUIT ""
+3 ;P7
SET NARR=$$STRPNAR^BEHOENPC(NARR)
+4 SET IEN=0
SET TRC=$EXTRACT(NARR,1,30)
SET NARR=$EXTRACT(NARR,1,160)
SET CREATE=$GET(CREATE,1)
+5 FOR
SET IEN=$ORDER(^AUTNPOV("B",TRC,IEN))
IF 'IEN
QUIT
IF $PIECE($GET(^AUTNPOV(IEN,0)),U)=NARR
QUIT
+6 IF IEN!'CREATE
QUIT IEN
+7 SET FDA(9999999.27,"+1,",.01)=NARR
+8 DO UPDATE^DIE("E","FDA","IEN")
+9 QUIT +$GET(IEN(1))