OR3CONV ;SLC/MLI-OE/RR v3 conversion entry points ;8/11/06 13:31
;;3.0;ORDER ENTRY/RESULTS REPORTING;**14,215,260,243,296**;Dec 17, 1997;Build 19
;
; This routine contains the entry points to convert orders from
; all package (OE/RR, pharmacy, dietetics, etc.).
;
; Entry points exist for:
; A. background conversion of orders (steps described in tag): (BGJ)
; B. on-the-fly conversion if record is accessed before background
; conversion gets to it. (OTF)
;
; Only OTF is a supported call. Remaining calls in routine are
; only called from within this routine (no external calls made in).
;
; Supporting calls exist in OR3CONV1 as follows:
; A. stop conversion process cleanly once in bgj (STOP)
; B. restarting background process if it did not complete. (RESTART)
; C. check status of conversion process (STATUS)
;
Q
;
QUEUE ; queue background process to run. DO NOT CALL MANUALLY!
; called from OR3POST and RESTART^OR3CONV1
;
; check entry...disallow calling tag once conversion has begun
N X
S X=$G(^ORD(100.99,1,"CONV"))
I '$D(ZTSAVE("ORESTART")),$P(X,"^",1) W !!,"Conversion already done!" Q
I '$D(ZTSAVE("ORESTART")),($P(X,"^",10)]"") D Q
. W !,"The conversion has already started."
. W !,"Please call RESTART^OR3CONV1 to restart the conversion!"
. Q
;
; if restart, ZTSAVE("ORESTART") set on entry - ask time to queue
S ZTIO="",ZTRTN="BGJ^OR3CONV"
I '$D(ZTSAVE("ORESTART")) S ZTDTH=$$NOW^XLFDT()
S ZTDESC="OE/RR v3 orders conversion...use STATUS^OR3CONV1 to track progress"
;S:$D(ZTSAVE("ORESTART")) ORESTART=ZTSAVE("ORESTART") D BGJ^OR3CONV ; *****for testing only*****
D ^%ZTLOAD
I $G(ZTSK) D
. D BMES^XPDUTL("Orders conversion tasked - #"_ZTSK)
. D SET(10,ZTSK)
E D
. D BMES^XPDUTL("***Problem encountered queuing conversion***")
. D MES^XPDUTL(" D QUEUE^OR3CONV to start manually.")
K ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
Q
;
BGJ ; process via background job in order below
; if restart, set ORPROCES = to step last on, call BGJ1
; 0. initialize list of patients to convert, then convert orders for:
; 1. current inpatients
; 2. patients with future scheduled admissions
; 3. patients on waiting list
; 4. patients with discharges in last 4 weeks
; 5. patients with appointments in last 4 weeks or next 4 weeks
; 6. everyone else (loop through DPT for remaining patients)
; 7. orders associated with entities not in the PATIENT file
;
I '$D(ZTQUEUED) W !,"Use RESTART^OR3CONV1!!!" Q ; prevent calling tag
;
N ORPROCES,ORSTOP
S ORSTOP=0 D SET(11,0) ; reset stop conversion parameter to no
I $D(ORESTART) D
. S ORPROCES=+$P(^ORD(100.99,1,"CONV"),"^",8)
E D
. S ORPROCES=0
. D SET(6,$$NOW^XLFDT())
F Q:ORPROCES>7 D Q:ORSTOP
. D SET(8,ORPROCES) ; update process currently on
. D @ORPROCES Q:ORSTOP
. S ORPROCES=ORPROCES+1
I ORSTOP D SET(10,"") ; delete out task job
Q
;
0 ; populate list of patients to convert
I '$D(ORESTART) D SET(1,0)
D PTCONV^OR3CONV1
Q
;
1 ; order conversion for inpatients
N DFN,ORWARD,X
S ORWARD=$S($D(ORESTART):ORESTART,1:"") K ORESTART
F S ORWARD=$O(^DPT("CN",ORWARD)) Q:ORWARD']""!ORSTOP D
. D SET(4,ORWARD)
. F DFN=0:0 S DFN=$O(^DPT("CN",ORWARD,DFN)) Q:'DFN!ORSTOP D
. . D SET(5,DFN)
. . S X=$$CONVERT(DFN,1)
. D SET(9,ORWARD)
D SET(3,$$NOW^XLFDT())
Q
;
;
2 ; patients with future scheduled admissions
N ORDATE,ORIEN,X
S ORDATE=$S($G(ORESTART):ORESTART,1:$$NOW^XLFDT()) K ORESTART
F S ORDATE=$O(^DGS(41.1,"C",ORDATE)) Q:'ORDATE!ORSTOP D
. F ORIEN=0:0 S ORIEN=$O(^DGS(41.1,"C",ORDATE,ORIEN)) Q:'ORIEN!ORSTOP D
. . S X=$G(^DGS(41.1,ORIEN,0))
. . I X']"" Q
. . S X=$$CONVERT(+X,1)
. . D SET(9,ORDATE)
Q
;
;
3 ; patients on waiting list
N DFN,ORIEN,ORIEN1,ORFLAG,X
S DFN=+$G(ORESTART) K ORESTART
F S DFN=$O(^DGWAIT("C",DFN)) Q:'DFN!ORSTOP D
. S ORFLAG=0
. F ORIEN=0:0 S ORIEN=$O(^DGWAIT("C",DFN,ORIEN)) Q:'ORIEN D Q:ORFLAG
. . F ORIEN1=0:0 S ORIEN1=$O(^DGWAIT("C",DFN,ORIEN,ORIEN1)) Q:'ORIEN1 D
. . . I $G(^DGWAIT(ORIEN,"P",ORIEN1,"ADM")) Q ; no longer active
. . . S X=$$CONVERT(DFN,1),ORFLAG=1
. . . D SET(9,DFN)
Q
;
;
4 ; patients with discharges in last 4 weeks
N DFN,ORDISCH,X
S ORDISCH=$S($G(ORESTART):ORESTART,1:$$FMADD^XLFDT(DT,-29)) K ORESTART
F S ORDISCH=$O(^DGPM("AMV3",ORDISCH)) Q:'ORDISCH!(ORDISCH>DT)!ORSTOP D
. F DFN=0:0 S DFN=$O(^DGPM("AMV3",ORDISCH,DFN)) Q:'DFN D
. . S X=$$CONVERT(DFN,1)
. . D SET(9,ORDISCH)
Q
;
;
5 ; patients with appointments past 4 weeks through next 4 weeks
; this call is no longer used
N DFN,OREND,ORERR,ORI,ORLOC,ORSTART,X
S ORSTART=$$FMADD^XLFDT(DT,-29),OREND=$$FMADD^XLFDT(DT,+29)
S ORLOC=+$G(ORESTART) K ORESTART
K ^TMP($J,"SDAMA202","GETPLIST")
F S ORLOC=$O(^SC(ORLOC)) Q:'ORLOC!ORSTOP D
. D GETPLIST^SDAMA202(ORLOC,"4","",ORSTART,OREND)
. S ORERR=$$CLINERR^ORQRY01
. I $L(ORERR) W !,ORERR S ORSTOP=1 Q
. S ORI=0
. F S ORI=$O(^TMP($J,"SDAMA202","GETPLIST",ORI)) Q:ORI<1 D
.. S DFN=+$G(^TMP($J,"SDAMA202","GETPLIST",ORI,4))
.. I DFN S X=$$CONVERT(DFN,1)
. D SET(9,ORLOC)
K ^TMP($J,"SDAMA202","GETPLIST")
Q
;
;
6 ; rest of patients
N DFN,X
S DFN=+$G(ORESTART) K ORESTART
F S DFN=$O(^ORD(100.99,1,"PTCONV",DFN)) Q:'DFN!ORSTOP D
. S X=$$CONVERT(DFN,1)
. D SET(9,DFN)
Q
;
;
7 ; orders not associated with DPT entries
N ORVP
S ORVP=$S($G(ORESTART):ORESTART,1:"") K ORESTART
F S ORVP=$O(^OR(100,"AO",ORVP)) Q:ORVP=""!ORSTOP D
. D ORDERS^OR3C100(ORVP)
. D EN^LR7OV2(ORVP,0)
I ORSTOP Q
D SET(7,$$NOW^XLFDT())
D CLEANUP^OR3CONV1
Q
;
;
OTF(DFN,ORQUIET) ; on-the-fly conversion
;
; *** Supported entry point for package to call to see if orders ***
; *** for patient have been converted and convert if not done yet ***
;
; Input: DFN as IEN of PATIENT file entry to convert orders for
; ORQUIET as 1 conversion should be silent
;
; Output: -1^error message if problem encountered
; 0 if patient already converted prior to call
; 1 if patient was successfully converted as part of call
;
S DFN=$G(DFN),ORQUIET=+$G(ORQUIET)
I $$ALLDONE() Q 0 ; conversion already complete
I DFN'=+DFN!'$D(^DPT(+DFN,0)) Q "-1^Error in DFN passed to OTF^OR3CONV"
Q $$CONVERT(DFN,ORQUIET,1) ; convert orders for patient
;
;
CONVERT(DFN,ORQUIET,OROTF) ; convert orders by patient, set flag when done
;
; Input - DFN as IEN of PATIENT file
; ORQUIET as 1 if conversion to be quiet
; OROTF as 1 if conversion called on-the-fly
; Output - -1^error message if problem encountered
; 1 if patient successfully converted
;
; new variables from bgj calls to ensure not reset during conv calls
N ORDATE,ORDATE,ORDISCH,OREND,ORIEN,ORIEN1,ORLOC,ORPROCES,ORSTART,ORWARD
;
N ORERRMSG,ORPTLK,ORVP
S ORVP=DFN_";DPT("
S OROTF=+$G(OROTF)
I 'OROTF,$$STOP() D ; field set to request stop of bgj
. S ORSTOP=1
. D SET(10,"")
I $$PTDONE(DFN) Q 0 ; patient already converted
S ORPTLK=$$LOCK^ORX2(DFN)
I 'ORPTLK D Q ORERRMSG ; record is locked
. I 'ORQUIET W !!,$P(ORPTLK,U,2) H 1
. S ORERRMSG="-1^"_$P(ORPTLK,U,2)
;
I $$ORCONV(ORVP) D
. N DFN
. I 'ORQUIET D WRITE(+ORVP,"OE/RR")
. D ORDERS^OR3C100(ORVP)
I $$PSCONV(DFN) D
. I 'ORQUIET D WRITE(DFN,"pharmacy")
. D EN1^PSOHLUP(+DFN,'ORQUIET)
I $$LRCONV() D
. N DFN
. I 'ORQUIET D WRITE(+ORVP,"lab")
. D EN^LR7OV2(ORVP,'ORQUIET)
D UNLOCK^ORX2(+DFN)
D DONE(DFN)
Q 1
;
ORCONV(ORVP) ; return 1 if OR orders need to be converted, otherwise 0
I $O(^OR(100,"AO",ORVP,0)) Q 1
Q 0
;
PSCONV(DFN) ; return 1 to convert pharmacy orders for patient, otherwise 0
;I $P($G(^PS(55,DFN,0)),U,6)'=2!'$P($G(^(5.1)),U,11) Q 1
Q 0
;
LRCONV() ; return 1 to convert
Q 1
;
WRITE(DFN,TYPE) ; write converting message
W !,"Converting ",TYPE," orders for ",$P($G(^DPT(DFN,0)),"^",1)
Q
;
ALLDONE() ; return 1 if conversion done, otherwise 0
Q $G(^ORD(100.99,1,"CONV"))
;
PTDONE(DFN) ; return 1 if patient already converted or PTCONV mult not done
I $D(^ORD(100.99,1,"PTCONV",DFN)) Q 0
I +$P($G(^ORD(100.99,1,"CONV")),"^",8)=0 Q 0
Q 1
;
STOP() ; check stop conversion flag
Q $P($G(^ORD(100.99,1,"CONV")),"^",11)
;
SET(PIECE,VALUE) ; update order parameter file field with value
N X
S X=$G(^ORD(100.99,1,"CONV"))
S $P(X,"^",PIECE)=VALUE
I PIECE=1 S $P(X,"^",2)=$$NOW^XLFDT()
I PIECE=3 S $P(X,"^",4,5)="^"
I PIECE=7 S $P(X,"^",1)=1,$P(X,"^",8,10)="^^"
I PIECE=8 S $P(X,"^",9)=""
S ^ORD(100.99,1,"CONV")=X
Q
;
DONE(DFN) ; remove entry from multiple
N COUNT,NODE,LAST,X
S X=$G(^ORD(100.99,1,"PTCONV",0)) Q:X']"" ; not done step 0
K ^ORD(100.99,1,"PTCONV",DFN),^ORD(100.99,1,"PTCONV","B",DFN)
LOCK L +^ORD(100.99,1,"PTCONV",0):5 I '$T G LOCK
S COUNT=$P(X,"^",4)-1,LAST=$O(^ORD(100.99,1,"PTCONV","A"),-1)
S $P(^ORD(100.99,1,"PTCONV",0),"^",3,4)=LAST_"^"_$S(COUNT>0:COUNT,1:0)
L -^ORD(100.99,1,"PTCONV",0)
S $P(^("CONV"),"^",12)=$P(^ORD(100.99,1,"CONV"),"^",12)+1
Q
OR3CONV ;SLC/MLI-OE/RR v3 conversion entry points ;8/11/06 13:31
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**14,215,260,243,296**;Dec 17, 1997;Build 19
+2 ;
+3 ; This routine contains the entry points to convert orders from
+4 ; all package (OE/RR, pharmacy, dietetics, etc.).
+5 ;
+6 ; Entry points exist for:
+7 ; A. background conversion of orders (steps described in tag): (BGJ)
+8 ; B. on-the-fly conversion if record is accessed before background
+9 ; conversion gets to it. (OTF)
+10 ;
+11 ; Only OTF is a supported call. Remaining calls in routine are
+12 ; only called from within this routine (no external calls made in).
+13 ;
+14 ; Supporting calls exist in OR3CONV1 as follows:
+15 ; A. stop conversion process cleanly once in bgj (STOP)
+16 ; B. restarting background process if it did not complete. (RESTART)
+17 ; C. check status of conversion process (STATUS)
+18 ;
+19 QUIT
+20 ;
QUEUE ; queue background process to run. DO NOT CALL MANUALLY!
+1 ; called from OR3POST and RESTART^OR3CONV1
+2 ;
+3 ; check entry...disallow calling tag once conversion has begun
+4 NEW X
+5 SET X=$GET(^ORD(100.99,1,"CONV"))
+6 IF '$DATA(ZTSAVE("ORESTART"))
IF $PIECE(X,"^",1)
WRITE !!,"Conversion already done!"
QUIT
+7 IF '$DATA(ZTSAVE("ORESTART"))
IF ($PIECE(X,"^",10)]"")
Begin DoDot:1
+8 WRITE !,"The conversion has already started."
+9 WRITE !,"Please call RESTART^OR3CONV1 to restart the conversion!"
+10 QUIT
End DoDot:1
QUIT
+11 ;
+12 ; if restart, ZTSAVE("ORESTART") set on entry - ask time to queue
+13 SET ZTIO=""
SET ZTRTN="BGJ^OR3CONV"
+14 IF '$DATA(ZTSAVE("ORESTART"))
SET ZTDTH=$$NOW^XLFDT()
+15 SET ZTDESC="OE/RR v3 orders conversion...use STATUS^OR3CONV1 to track progress"
+16 ;S:$D(ZTSAVE("ORESTART")) ORESTART=ZTSAVE("ORESTART") D BGJ^OR3CONV ; *****for testing only*****
+17 DO ^%ZTLOAD
+18 IF $GET(ZTSK)
Begin DoDot:1
+19 DO BMES^XPDUTL("Orders conversion tasked - #"_ZTSK)
+20 DO SET(10,ZTSK)
End DoDot:1
+21 IF '$TEST
Begin DoDot:1
+22 DO BMES^XPDUTL("***Problem encountered queuing conversion***")
+23 DO MES^XPDUTL(" D QUEUE^OR3CONV to start manually.")
End DoDot:1
+24 KILL ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
+25 QUIT
+26 ;
BGJ ; process via background job in order below
+1 ; if restart, set ORPROCES = to step last on, call BGJ1
+2 ; 0. initialize list of patients to convert, then convert orders for:
+3 ; 1. current inpatients
+4 ; 2. patients with future scheduled admissions
+5 ; 3. patients on waiting list
+6 ; 4. patients with discharges in last 4 weeks
+7 ; 5. patients with appointments in last 4 weeks or next 4 weeks
+8 ; 6. everyone else (loop through DPT for remaining patients)
+9 ; 7. orders associated with entities not in the PATIENT file
+10 ;
+11 ; prevent calling tag
IF '$DATA(ZTQUEUED)
WRITE !,"Use RESTART^OR3CONV1!!!"
QUIT
+12 ;
+13 NEW ORPROCES,ORSTOP
+14 ; reset stop conversion parameter to no
SET ORSTOP=0
DO SET(11,0)
+15 IF $DATA(ORESTART)
Begin DoDot:1
+16 SET ORPROCES=+$PIECE(^ORD(100.99,1,"CONV"),"^",8)
End DoDot:1
+17 IF '$TEST
Begin DoDot:1
+18 SET ORPROCES=0
+19 DO SET(6,$$NOW^XLFDT())
End DoDot:1
+20 FOR
IF ORPROCES>7
QUIT
Begin DoDot:1
+21 ; update process currently on
DO SET(8,ORPROCES)
+22 DO @ORPROCES
IF ORSTOP
QUIT
+23 SET ORPROCES=ORPROCES+1
End DoDot:1
IF ORSTOP
QUIT
+24 ; delete out task job
IF ORSTOP
DO SET(10,"")
+25 QUIT
+26 ;
0 ; populate list of patients to convert
+1 IF '$DATA(ORESTART)
DO SET(1,0)
+2 DO PTCONV^OR3CONV1
+3 QUIT
+4 ;
1 ; order conversion for inpatients
+1 NEW DFN,ORWARD,X
+2 SET ORWARD=$SELECT($DATA(ORESTART):ORESTART,1:"")
KILL ORESTART
+3 FOR
SET ORWARD=$ORDER(^DPT("CN",ORWARD))
IF ORWARD']""!ORSTOP
QUIT
Begin DoDot:1
+4 DO SET(4,ORWARD)
+5 FOR DFN=0:0
SET DFN=$ORDER(^DPT("CN",ORWARD,DFN))
IF 'DFN!ORSTOP
QUIT
Begin DoDot:2
+6 DO SET(5,DFN)
+7 SET X=$$CONVERT(DFN,1)
End DoDot:2
+8 DO SET(9,ORWARD)
End DoDot:1
+9 DO SET(3,$$NOW^XLFDT())
+10 QUIT
+11 ;
+12 ;
2 ; patients with future scheduled admissions
+1 NEW ORDATE,ORIEN,X
+2 SET ORDATE=$SELECT($GET(ORESTART):ORESTART,1:$$NOW^XLFDT())
KILL ORESTART
+3 FOR
SET ORDATE=$ORDER(^DGS(41.1,"C",ORDATE))
IF 'ORDATE!ORSTOP
QUIT
Begin DoDot:1
+4 FOR ORIEN=0:0
SET ORIEN=$ORDER(^DGS(41.1,"C",ORDATE,ORIEN))
IF 'ORIEN!ORSTOP
QUIT
Begin DoDot:2
+5 SET X=$GET(^DGS(41.1,ORIEN,0))
+6 IF X']""
QUIT
+7 SET X=$$CONVERT(+X,1)
+8 DO SET(9,ORDATE)
End DoDot:2
End DoDot:1
+9 QUIT
+10 ;
+11 ;
3 ; patients on waiting list
+1 NEW DFN,ORIEN,ORIEN1,ORFLAG,X
+2 SET DFN=+$GET(ORESTART)
KILL ORESTART
+3 FOR
SET DFN=$ORDER(^DGWAIT("C",DFN))
IF 'DFN!ORSTOP
QUIT
Begin DoDot:1
+4 SET ORFLAG=0
+5 FOR ORIEN=0:0
SET ORIEN=$ORDER(^DGWAIT("C",DFN,ORIEN))
IF 'ORIEN
QUIT
Begin DoDot:2
+6 FOR ORIEN1=0:0
SET ORIEN1=$ORDER(^DGWAIT("C",DFN,ORIEN,ORIEN1))
IF 'ORIEN1
QUIT
Begin DoDot:3
+7 ; no longer active
IF $GET(^DGWAIT(ORIEN,"P",ORIEN1,"ADM"))
QUIT
+8 SET X=$$CONVERT(DFN,1)
SET ORFLAG=1
+9 DO SET(9,DFN)
End DoDot:3
End DoDot:2
IF ORFLAG
QUIT
End DoDot:1
+10 QUIT
+11 ;
+12 ;
4 ; patients with discharges in last 4 weeks
+1 NEW DFN,ORDISCH,X
+2 SET ORDISCH=$SELECT($GET(ORESTART):ORESTART,1:$$FMADD^XLFDT(DT,-29))
KILL ORESTART
+3 FOR
SET ORDISCH=$ORDER(^DGPM("AMV3",ORDISCH))
IF 'ORDISCH!(ORDISCH>DT)!ORSTOP
QUIT
Begin DoDot:1
+4 FOR DFN=0:0
SET DFN=$ORDER(^DGPM("AMV3",ORDISCH,DFN))
IF 'DFN
QUIT
Begin DoDot:2
+5 SET X=$$CONVERT(DFN,1)
+6 DO SET(9,ORDISCH)
End DoDot:2
End DoDot:1
+7 QUIT
+8 ;
+9 ;
5 ; patients with appointments past 4 weeks through next 4 weeks
+1 ; this call is no longer used
+2 NEW DFN,OREND,ORERR,ORI,ORLOC,ORSTART,X
+3 SET ORSTART=$$FMADD^XLFDT(DT,-29)
SET OREND=$$FMADD^XLFDT(DT,+29)
+4 SET ORLOC=+$GET(ORESTART)
KILL ORESTART
+5 KILL ^TMP($JOB,"SDAMA202","GETPLIST")
+6 FOR
SET ORLOC=$ORDER(^SC(ORLOC))
IF 'ORLOC!ORSTOP
QUIT
Begin DoDot:1
+7 DO GETPLIST^SDAMA202(ORLOC,"4","",ORSTART,OREND)
+8 SET ORERR=$$CLINERR^ORQRY01
+9 IF $LENGTH(ORERR)
WRITE !,ORERR
SET ORSTOP=1
QUIT
+10 SET ORI=0
+11 FOR
SET ORI=$ORDER(^TMP($JOB,"SDAMA202","GETPLIST",ORI))
IF ORI<1
QUIT
Begin DoDot:2
+12 SET DFN=+$GET(^TMP($JOB,"SDAMA202","GETPLIST",ORI,4))
+13 IF DFN
SET X=$$CONVERT(DFN,1)
End DoDot:2
+14 DO SET(9,ORLOC)
End DoDot:1
+15 KILL ^TMP($JOB,"SDAMA202","GETPLIST")
+16 QUIT
+17 ;
+18 ;
6 ; rest of patients
+1 NEW DFN,X
+2 SET DFN=+$GET(ORESTART)
KILL ORESTART
+3 FOR
SET DFN=$ORDER(^ORD(100.99,1,"PTCONV",DFN))
IF 'DFN!ORSTOP
QUIT
Begin DoDot:1
+4 SET X=$$CONVERT(DFN,1)
+5 DO SET(9,DFN)
End DoDot:1
+6 QUIT
+7 ;
+8 ;
7 ; orders not associated with DPT entries
+1 NEW ORVP
+2 SET ORVP=$SELECT($GET(ORESTART):ORESTART,1:"")
KILL ORESTART
+3 FOR
SET ORVP=$ORDER(^OR(100,"AO",ORVP))
IF ORVP=""!ORSTOP
QUIT
Begin DoDot:1
+4 DO ORDERS^OR3C100(ORVP)
+5 DO EN^LR7OV2(ORVP,0)
End DoDot:1
+6 IF ORSTOP
QUIT
+7 DO SET(7,$$NOW^XLFDT())
+8 DO CLEANUP^OR3CONV1
+9 QUIT
+10 ;
+11 ;
OTF(DFN,ORQUIET) ; on-the-fly conversion
+1 ;
+2 ; *** Supported entry point for package to call to see if orders ***
+3 ; *** for patient have been converted and convert if not done yet ***
+4 ;
+5 ; Input: DFN as IEN of PATIENT file entry to convert orders for
+6 ; ORQUIET as 1 conversion should be silent
+7 ;
+8 ; Output: -1^error message if problem encountered
+9 ; 0 if patient already converted prior to call
+10 ; 1 if patient was successfully converted as part of call
+11 ;
+12 SET DFN=$GET(DFN)
SET ORQUIET=+$GET(ORQUIET)
+13 ; conversion already complete
IF $$ALLDONE()
QUIT 0
+14 IF DFN'=+DFN!'$DATA(^DPT(+DFN,0))
QUIT "-1^Error in DFN passed to OTF^OR3CONV"
+15 ; convert orders for patient
QUIT $$CONVERT(DFN,ORQUIET,1)
+16 ;
+17 ;
CONVERT(DFN,ORQUIET,OROTF) ; convert orders by patient, set flag when done
+1 ;
+2 ; Input - DFN as IEN of PATIENT file
+3 ; ORQUIET as 1 if conversion to be quiet
+4 ; OROTF as 1 if conversion called on-the-fly
+5 ; Output - -1^error message if problem encountered
+6 ; 1 if patient successfully converted
+7 ;
+8 ; new variables from bgj calls to ensure not reset during conv calls
+9 NEW ORDATE,ORDATE,ORDISCH,OREND,ORIEN,ORIEN1,ORLOC,ORPROCES,ORSTART,ORWARD
+10 ;
+11 NEW ORERRMSG,ORPTLK,ORVP
+12 SET ORVP=DFN_";DPT("
+13 SET OROTF=+$GET(OROTF)
+14 ; field set to request stop of bgj
IF 'OROTF
IF $$STOP()
Begin DoDot:1
+15 SET ORSTOP=1
+16 DO SET(10,"")
End DoDot:1
+17 ; patient already converted
IF $$PTDONE(DFN)
QUIT 0
+18 SET ORPTLK=$$LOCK^ORX2(DFN)
+19 ; record is locked
IF 'ORPTLK
Begin DoDot:1
+20 IF 'ORQUIET
WRITE !!,$PIECE(ORPTLK,U,2)
HANG 1
+21 SET ORERRMSG="-1^"_$PIECE(ORPTLK,U,2)
End DoDot:1
QUIT ORERRMSG
+22 ;
+23 IF $$ORCONV(ORVP)
Begin DoDot:1
+24 NEW DFN
+25 IF 'ORQUIET
DO WRITE(+ORVP,"OE/RR")
+26 DO ORDERS^OR3C100(ORVP)
End DoDot:1
+27 IF $$PSCONV(DFN)
Begin DoDot:1
+28 IF 'ORQUIET
DO WRITE(DFN,"pharmacy")
+29 DO EN1^PSOHLUP(+DFN,'ORQUIET)
End DoDot:1
+30 IF $$LRCONV()
Begin DoDot:1
+31 NEW DFN
+32 IF 'ORQUIET
DO WRITE(+ORVP,"lab")
+33 DO EN^LR7OV2(ORVP,'ORQUIET)
End DoDot:1
+34 DO UNLOCK^ORX2(+DFN)
+35 DO DONE(DFN)
+36 QUIT 1
+37 ;
ORCONV(ORVP) ; return 1 if OR orders need to be converted, otherwise 0
+1 IF $ORDER(^OR(100,"AO",ORVP,0))
QUIT 1
+2 QUIT 0
+3 ;
PSCONV(DFN) ; return 1 to convert pharmacy orders for patient, otherwise 0
+1 ;I $P($G(^PS(55,DFN,0)),U,6)'=2!'$P($G(^(5.1)),U,11) Q 1
+2 QUIT 0
+3 ;
LRCONV() ; return 1 to convert
+1 QUIT 1
+2 ;
WRITE(DFN,TYPE) ; write converting message
+1 WRITE !,"Converting ",TYPE," orders for ",$PIECE($GET(^DPT(DFN,0)),"^",1)
+2 QUIT
+3 ;
ALLDONE() ; return 1 if conversion done, otherwise 0
+1 QUIT $GET(^ORD(100.99,1,"CONV"))
+2 ;
PTDONE(DFN) ; return 1 if patient already converted or PTCONV mult not done
+1 IF $DATA(^ORD(100.99,1,"PTCONV",DFN))
QUIT 0
+2 IF +$PIECE($GET(^ORD(100.99,1,"CONV")),"^",8)=0
QUIT 0
+3 QUIT 1
+4 ;
STOP() ; check stop conversion flag
+1 QUIT $PIECE($GET(^ORD(100.99,1,"CONV")),"^",11)
+2 ;
SET(PIECE,VALUE) ; update order parameter file field with value
+1 NEW X
+2 SET X=$GET(^ORD(100.99,1,"CONV"))
+3 SET $PIECE(X,"^",PIECE)=VALUE
+4 IF PIECE=1
SET $PIECE(X,"^",2)=$$NOW^XLFDT()
+5 IF PIECE=3
SET $PIECE(X,"^",4,5)="^"
+6 IF PIECE=7
SET $PIECE(X,"^",1)=1
SET $PIECE(X,"^",8,10)="^^"
+7 IF PIECE=8
SET $PIECE(X,"^",9)=""
+8 SET ^ORD(100.99,1,"CONV")=X
+9 QUIT
+10 ;
DONE(DFN) ; remove entry from multiple
+1 NEW COUNT,NODE,LAST,X
+2 ; not done step 0
SET X=$GET(^ORD(100.99,1,"PTCONV",0))
IF X']""
QUIT
+3 KILL ^ORD(100.99,1,"PTCONV",DFN),^ORD(100.99,1,"PTCONV","B",DFN)
LOCK LOCK +^ORD(100.99,1,"PTCONV",0):5
IF '$TEST
GOTO LOCK
+1 SET COUNT=$PIECE(X,"^",4)-1
SET LAST=$ORDER(^ORD(100.99,1,"PTCONV","A"),-1)
+2 SET $PIECE(^ORD(100.99,1,"PTCONV",0),"^",3,4)=LAST_"^"_$SELECT(COUNT>0:COUNT,1:0)
+3 LOCK -^ORD(100.99,1,"PTCONV",0)
+4 SET $PIECE(^("CONV"),"^",12)=$PIECE(^ORD(100.99,1,"CONV"),"^",12)+1
+5 QUIT