SCCVEAP1 ;ALB/RMO,TMP - Appointment Conversion cont.; [ 04/05/95 10:19 AM ]
;;5.3;Scheduling;**211,1015**;Aug 13, 1993;Build 21
;
CON(SCCVEVT,DFN,SCDTM) ; Should conversion event be processed for appointment
; Input -- SCCVEVT Conversion event
; DFN Patient IEN
; SCDTM Appointment date/time
;
; Output -- 1=Yes and 0=No
;
N SCECSTAT,Y,SCOE,SCAPT0
S SCAPT0=$G(^DPT(DFN,"S",SCDTM,0))
S SCOE=+$P(SCAPT0,U,20)
S SCECSTAT=$P(SCAPT0,U,23)
;
S Y=1
IF Y,$P(SCDTM,".")>SCCVACRP S Y=0 ; Greater than ACRP date
IF SCCVEVT=1,SCECSTAT S Y=0 ; Convert/already converted
IF Y,SCCVEVT=2,'SCECSTAT S Y=0 ; Re-convert/never converted
IF Y,'SCCVEVT,SCECSTAT S Y=0 ; Estimate/already converted
;
; -- if check out required then must have a co completion date/time
IF Y,$$REQ^SDM1A(SCDTM)="CO",'$P($G(^SCE(SCOE,0)),U,7) S Y=0
;
; -- following is commented out ; left for reference purposes
; -- if no enc and no ^sc appt node (purged) then don't convert
;IF Y,'SCOE,'$$FIND^SDAM2(DFN,SCDTM,+SCAPT0) S Y=0
Q +$G(Y)
;
EN(SCCVEVT,DFN,SCDTM,SCCLN,SCDA,SCLOG) ; Entry point to convert an appointment
; Input -- SCCVEVT Conversion event
; 0=Estimate 1=Convert 2=Re-convert
; DFN Patient IEN
; SCDTM Appointment date/time
; SCCLN Clinic IEN
; SCDA Clinic appt patient sub-file IEN [optional]
; SCLOG Scheduling conversion log IEN [optional]
;
N SCCV,SCOE,SCCONS,SCEST
;
S SCCONS("SRCE")="SD TO PCE DB CONV"
S SCCONS("PKG")=$O(^DIC(9.4,"C","SD",0))
;
; Check if appointment should be processed
IF '$$CON(SCCVEVT,DFN,SCDTM) G ENQ
;
; Set-up conversion array and variables
D SET^SCCVEAP3(SCCVEVT,+$G(SCLOG),DFN,SCDTM,SCCLN,.SCDA,.SCOE,.SCCV)
;
I 'SCCVEVT,$G(SCCV("ERR")) G ENQ ; if error found - ignore for estimate
;
; Don't process no new enctr or visit needed & no error to log
I '$G(SCCV("NEW")),'$D(SCCV("ERR")) G ENQ
;
; -- saved for reference
; I $S('SCCVEVT:'$G(SCCV("NEW")),'$G(SCCV("NEW")):'$D(SCCV("ERR")),1:0) G ENQ
;
; Increment number of appointments found (estimating only)
I 'SCCVEVT D
. D INCRTOT^SCCVEGU1(.SCTOT,3,1)
. D EN^SCCVZZ("APPT-3",SCOE,SCDTM,$P($G(SCCV("PT",0)),U),+$P($G(SCCV("OE",0)),U,6))
;
; Log error if there is no encounter or visit/exit if no encounter
I SCCVEVT,$S('$G(SCOE):1,1:'$P($G(SCCV("OE",0)),U,5)) D G:'$G(SCOE) ENQ
. N SCE,SCERRIP,Y
. S SCERRIP(1)=$P($G(^DPT(DFN,0)),U)
. S Y=SCDTM D D^DIQ S SCERRIP(2)=Y
. S SCERRIP(3)=$P($G(^SC(SCCLN,0)),U)
. S SCERRIP(4)=$S('$G(SCOE):"Outpatient encounter",1:"Visit")
. S SCERRIP(5)=$$OTHERR^SCCVU2($G(SCCV("ERR")))
. S SCE("DFN")=DFN,SCE("ENC")=$G(SCOE),SCE("VSIT")="",SCE("DATE")=SCDTM
. D GETERR^SCCVLOG1(4049005.002,.SCE,.SCERRIP,$G(SCLOG),0,.SCERRMSG)
. S SCTOT(2.06)=$G(SCTOT(2.06))+1
. S:$G(SCOE) ^XTMP("SCCV-ERR-"_+$G(SCLOG),"NO-VIS",SCOE)=""
;
G:$G(SCCV("ERR")) ENQ
;
; Create stop codes, visit for ancillary tests
D ANC^SCCVEAP2($G(SCOE),DFN,SCDTM,SCCLN,.SCCV,$G(SCLOG))
;
; Convert children
D CHLD^SCCVEAP2(SCOE,.SCCV,$G(SCLOG))
;
; Invoke DATA-TO-PCE call, store any errors
I $S('SCCVEVT:1,1:$P($G(^SCE(SCOE,0)),U,5)) D DATA2PCE^SCCVPCE(SCOE,.SCCONS,SCCVEVT,$G(SCOEP),"","",.SCEST)
;
I 'SCCVEVT D G ENQ ;Estimate exits here
.F Z=1:1:3 I $P(SCEST,U,Z) D INCRTOT^SCCVEGU1(.SCTOT,Z+8,$P(SCEST,U,Z)) D EN^SCCVZZ("APPT-"_(Z+8),SCOE,SCDTM,$P($G(SCCV("PT",0)),U),+$P($G(SCCV("OE",0)),U,6),$P(SCEST,U,Z))
;
; Convert additional appt data
D ENC(SCOE,.SCCV)
;
; Update appointment as converted
D DONE(DFN,SCDTM,1)
;
; Update last entry and number of records
I $G(SCLOG) D UPDREC^SCCVLOG(SCLOG,SCOE,"CST")
I '$G(SCLOG) S SCTOT("OK")=1
;
ENQ Q
;
ENC(SCOE,SCCV) ; Update additional appt data for encounter
; Input -- SCOE Outpatient encounter IEN
; SCCV Conversion array
; Output -- None
N SCDATA,SCOEC
I $G(SCCV("VST")),'$P(^SCE(SCOE,0),U,5) S SCDATA(.05)=SCCV("VST")
S:$G(SCCV("NEW"))=1 SCDATA(901)=1 ; Created by conversion
;
I $G(SCCV("HIST")) D ; Stop code created historically
. I '$P($G(^SCE(SCOE,"CNV")),U,3),$P($G(^(0)),U,3) S SCDATA(903)=1
. Q:'$O(^SCE("APAR",SCOE,0))
. S SCOEC=0 F S SCOEC=$O(^SCE("APAR",SCOE,SCOEC)) Q:'SCOEC S SCOEC(SCOEC)=""
;
I $P($G(^SCE(SCOE,0)),U,5) D ENCCNV(.SCDATA)
I $D(SCDATA) D UPD^SCCVDBU(409.68,SCOE,.SCDATA) ;Update parent
;
I $O(SCOEC(0)) D ; update children of encounter
. N SCDATC
. S SCOEC=0
. F S SCOEC=$O(SCOEC(SCOEC)) Q:'SCOEC D
.. N SCDATC
.. I '$G(^SCE(SCOEC,"CNV")),$G(SCCV("NEW"))=1 S SCDATC(901)=1
.. I $P($G(^SCE(SCOEC,0)),U,3),'$P($G(^("CNV")),U,3) S SCDATC(903)=1
.. I $P($G(^SCE(SCOEC,0)),U,5) D ENCCNV(.SCDATC)
.. I $D(SCDATC) D UPD^SCCVDBU(409.68,SCOEC,.SCDATC)
;
ENCQ Q
;
DONE(DFN,SCDTM,SCECSTAT) ; Update appointment encounter conversion status
; Input -- DFN Patient IEN
; SCDTM Appointment date/time
; SCECSTAT Encounter conversion status
; Output -- None
N SCDATA,SCIENS
S SCIENS=SCDTM_","_DFN
S:'$P($G(^DPT(DFN,"S",SCDTM,0)),U,23) SCDATA(23.1)=SCECSTAT ; encounter conversion status
I $D(SCDATA) D UPD^SCCVDBU(2.98,SCIENS,.SCDATA)
Q
;
ENCCNV(DATA) ; Set nodes to update 'conversion processed' fields in encounter
S DATA(904)=1,DATA(905)=+$E($$NOW^XLFDT(),1,12)
I $G(SCCV("NEW"))=2 S DATA(101)=$G(DUZ),DATA(102)=DATA(905)
Q
;
SCCVEAP1 ;ALB/RMO,TMP - Appointment Conversion cont.; [ 04/05/95 10:19 AM ]
+1 ;;5.3;Scheduling;**211,1015**;Aug 13, 1993;Build 21
+2 ;
CON(SCCVEVT,DFN,SCDTM) ; Should conversion event be processed for appointment
+1 ; Input -- SCCVEVT Conversion event
+2 ; DFN Patient IEN
+3 ; SCDTM Appointment date/time
+4 ;
+5 ; Output -- 1=Yes and 0=No
+6 ;
+7 NEW SCECSTAT,Y,SCOE,SCAPT0
+8 SET SCAPT0=$GET(^DPT(DFN,"S",SCDTM,0))
+9 SET SCOE=+$PIECE(SCAPT0,U,20)
+10 SET SCECSTAT=$PIECE(SCAPT0,U,23)
+11 ;
+12 SET Y=1
+13 ; Greater than ACRP date
IF Y
IF $PIECE(SCDTM,".")>SCCVACRP
SET Y=0
+14 ; Convert/already converted
IF SCCVEVT=1
IF SCECSTAT
SET Y=0
+15 ; Re-convert/never converted
IF Y
IF SCCVEVT=2
IF 'SCECSTAT
SET Y=0
+16 ; Estimate/already converted
IF Y
IF 'SCCVEVT
IF SCECSTAT
SET Y=0
+17 ;
+18 ; -- if check out required then must have a co completion date/time
+19 IF Y
IF $$REQ^SDM1A(SCDTM)="CO"
IF '$PIECE($GET(^SCE(SCOE,0)),U,7)
SET Y=0
+20 ;
+21 ; -- following is commented out ; left for reference purposes
+22 ; -- if no enc and no ^sc appt node (purged) then don't convert
+23 ;IF Y,'SCOE,'$$FIND^SDAM2(DFN,SCDTM,+SCAPT0) S Y=0
+24 QUIT +$GET(Y)
+25 ;
EN(SCCVEVT,DFN,SCDTM,SCCLN,SCDA,SCLOG) ; Entry point to convert an appointment
+1 ; Input -- SCCVEVT Conversion event
+2 ; 0=Estimate 1=Convert 2=Re-convert
+3 ; DFN Patient IEN
+4 ; SCDTM Appointment date/time
+5 ; SCCLN Clinic IEN
+6 ; SCDA Clinic appt patient sub-file IEN [optional]
+7 ; SCLOG Scheduling conversion log IEN [optional]
+8 ;
+9 NEW SCCV,SCOE,SCCONS,SCEST
+10 ;
+11 SET SCCONS("SRCE")="SD TO PCE DB CONV"
+12 SET SCCONS("PKG")=$ORDER(^DIC(9.4,"C","SD",0))
+13 ;
+14 ; Check if appointment should be processed
+15 IF '$$CON(SCCVEVT,DFN,SCDTM)
GOTO ENQ
+16 ;
+17 ; Set-up conversion array and variables
+18 DO SET^SCCVEAP3(SCCVEVT,+$GET(SCLOG),DFN,SCDTM,SCCLN,.SCDA,.SCOE,.SCCV)
+19 ;
+20 ; if error found - ignore for estimate
IF 'SCCVEVT
IF $GET(SCCV("ERR"))
GOTO ENQ
+21 ;
+22 ; Don't process no new enctr or visit needed & no error to log
+23 IF '$GET(SCCV("NEW"))
IF '$DATA(SCCV("ERR"))
GOTO ENQ
+24 ;
+25 ; -- saved for reference
+26 ; I $S('SCCVEVT:'$G(SCCV("NEW")),'$G(SCCV("NEW")):'$D(SCCV("ERR")),1:0) G ENQ
+27 ;
+28 ; Increment number of appointments found (estimating only)
+29 IF 'SCCVEVT
Begin DoDot:1
+30 DO INCRTOT^SCCVEGU1(.SCTOT,3,1)
+31 DO EN^SCCVZZ("APPT-3",SCOE,SCDTM,$PIECE($GET(SCCV("PT",0)),U),+$PIECE($GET(SCCV("OE",0)),U,6))
End DoDot:1
+32 ;
+33 ; Log error if there is no encounter or visit/exit if no encounter
+34 IF SCCVEVT
IF $SELECT('$GET(SCOE):1,1:'$PIECE($GET(SCCV("OE",0)),U,5))
Begin DoDot:1
+35 NEW SCE,SCERRIP,Y
+36 SET SCERRIP(1)=$PIECE($GET(^DPT(DFN,0)),U)
+37 SET Y=SCDTM
DO D^DIQ
SET SCERRIP(2)=Y
+38 SET SCERRIP(3)=$PIECE($GET(^SC(SCCLN,0)),U)
+39 SET SCERRIP(4)=$SELECT('$GET(SCOE):"Outpatient encounter",1:"Visit")
+40 SET SCERRIP(5)=$$OTHERR^SCCVU2($GET(SCCV("ERR")))
+41 SET SCE("DFN")=DFN
SET SCE("ENC")=$GET(SCOE)
SET SCE("VSIT")=""
SET SCE("DATE")=SCDTM
+42 DO GETERR^SCCVLOG1(4049005.002,.SCE,.SCERRIP,$GET(SCLOG),0,.SCERRMSG)
+43 SET SCTOT(2.06)=$GET(SCTOT(2.06))+1
+44 IF $GET(SCOE)
SET ^XTMP("SCCV-ERR-"_+$GET(SCLOG),"NO-VIS",SCOE)=""
End DoDot:1
IF '$GET(SCOE)
GOTO ENQ
+45 ;
+46 IF $GET(SCCV("ERR"))
GOTO ENQ
+47 ;
+48 ; Create stop codes, visit for ancillary tests
+49 DO ANC^SCCVEAP2($GET(SCOE),DFN,SCDTM,SCCLN,.SCCV,$GET(SCLOG))
+50 ;
+51 ; Convert children
+52 DO CHLD^SCCVEAP2(SCOE,.SCCV,$GET(SCLOG))
+53 ;
+54 ; Invoke DATA-TO-PCE call, store any errors
+55 IF $SELECT('SCCVEVT:1,1:$PIECE($GET(^SCE(SCOE,0)),U,5))
DO DATA2PCE^SCCVPCE(SCOE,.SCCONS,SCCVEVT,$GET(SCOEP),"","",.SCEST)
+56 ;
+57 ;Estimate exits here
IF 'SCCVEVT
Begin DoDot:1
+58 FOR Z=1:1:3
IF $PIECE(SCEST,U,Z)
DO INCRTOT^SCCVEGU1(.SCTOT,Z+8,$PIECE(SCEST,U,Z))
DO EN^SCCVZZ("APPT-"_(Z+8),SCOE,SCDTM,$PIECE($GET(SCCV("PT",0)),U),+$PIECE($GET(SCCV("OE",0)),U,6),$PIECE(SCEST,U,Z))
End DoDot:1
GOTO ENQ
+59 ;
+60 ; Convert additional appt data
+61 DO ENC(SCOE,.SCCV)
+62 ;
+63 ; Update appointment as converted
+64 DO DONE(DFN,SCDTM,1)
+65 ;
+66 ; Update last entry and number of records
+67 IF $GET(SCLOG)
DO UPDREC^SCCVLOG(SCLOG,SCOE,"CST")
+68 IF '$GET(SCLOG)
SET SCTOT("OK")=1
+69 ;
ENQ QUIT
+1 ;
ENC(SCOE,SCCV) ; Update additional appt data for encounter
+1 ; Input -- SCOE Outpatient encounter IEN
+2 ; SCCV Conversion array
+3 ; Output -- None
+4 NEW SCDATA,SCOEC
+5 IF $GET(SCCV("VST"))
IF '$PIECE(^SCE(SCOE,0),U,5)
SET SCDATA(.05)=SCCV("VST")
+6 ; Created by conversion
IF $GET(SCCV("NEW"))=1
SET SCDATA(901)=1
+7 ;
+8 ; Stop code created historically
IF $GET(SCCV("HIST"))
Begin DoDot:1
+9 IF '$PIECE($GET(^SCE(SCOE,"CNV")),U,3)
IF $PIECE($GET(^(0)),U,3)
SET SCDATA(903)=1
+10 IF '$ORDER(^SCE("APAR",SCOE,0))
QUIT
+11 SET SCOEC=0
FOR
SET SCOEC=$ORDER(^SCE("APAR",SCOE,SCOEC))
IF 'SCOEC
QUIT
SET SCOEC(SCOEC)=""
End DoDot:1
+12 ;
+13 IF $PIECE($GET(^SCE(SCOE,0)),U,5)
DO ENCCNV(.SCDATA)
+14 ;Update parent
IF $DATA(SCDATA)
DO UPD^SCCVDBU(409.68,SCOE,.SCDATA)
+15 ;
+16 ; update children of encounter
IF $ORDER(SCOEC(0))
Begin DoDot:1
+17 NEW SCDATC
+18 SET SCOEC=0
+19 FOR
SET SCOEC=$ORDER(SCOEC(SCOEC))
IF 'SCOEC
QUIT
Begin DoDot:2
+20 NEW SCDATC
+21 IF '$GET(^SCE(SCOEC,"CNV"))
IF $GET(SCCV("NEW"))=1
SET SCDATC(901)=1
+22 IF $PIECE($GET(^SCE(SCOEC,0)),U,3)
IF '$PIECE($GET(^("CNV")),U,3)
SET SCDATC(903)=1
+23 IF $PIECE($GET(^SCE(SCOEC,0)),U,5)
DO ENCCNV(.SCDATC)
+24 IF $DATA(SCDATC)
DO UPD^SCCVDBU(409.68,SCOEC,.SCDATC)
End DoDot:2
End DoDot:1
+25 ;
ENCQ QUIT
+1 ;
DONE(DFN,SCDTM,SCECSTAT) ; Update appointment encounter conversion status
+1 ; Input -- DFN Patient IEN
+2 ; SCDTM Appointment date/time
+3 ; SCECSTAT Encounter conversion status
+4 ; Output -- None
+5 NEW SCDATA,SCIENS
+6 SET SCIENS=SCDTM_","_DFN
+7 ; encounter conversion status
IF '$PIECE($GET(^DPT(DFN,"S",SCDTM,0)),U,23)
SET SCDATA(23.1)=SCECSTAT
+8 IF $DATA(SCDATA)
DO UPD^SCCVDBU(2.98,SCIENS,.SCDATA)
+9 QUIT
+10 ;
ENCCNV(DATA) ; Set nodes to update 'conversion processed' fields in encounter
+1 SET DATA(904)=1
SET DATA(905)=+$EXTRACT($$NOW^XLFDT(),1,12)
+2 IF $GET(SCCV("NEW"))=2
SET DATA(101)=$GET(DUZ)
SET DATA(102)=DATA(905)
+3 QUIT
+4 ;