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

OR3CONV.m

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