SCCVEAP2 ;ALB/RMO,TMP - Appointment Conversion cont.; [ 04/05/95 10:19 AM ]
;;5.3;Scheduling;**211**;Aug 13, 1993
;
VISIT(SCDTM,SCCV) ;Create visit when encounter already exists
; Input -- SCDTM Appointment date/time
; SCCV Conversion array
; Output -- Visit file IEN
N SCVSIT,SCDATA,SCCVT,SCOE
IF '$G(SCCV("OE",0)) G VISITQ
S SCOE=$G(SCCV("OE"))
S SCVSIT("DFN")=$P(SCCV("OE",0),U,2)
IF 'SCVSIT("DFN") G VISITQ
;
S SCVSIT("CLN")=$S('$G(SCCV("CSC")):$P(SCCV("OE",0),U,3),1:SCCV("CSC"))
;
S SCVSIT("DIV")=$P(SCCV("OE",0),U,11)
S SCVSIT("ELG")=$P(SCCV("OE",0),U,13)
S SCVSIT("LOC")=$P(SCCV("OE",0),U,4)
S SCVSIT("TYP")=$P(SCCV("OE",0),U,10)
S SCVSIT("STA")=$P(SCCV("OE",0),U,12)
S SCVSIT("ORG")=$G(SCCV("ORG"))
;
D SETSCCVT(.SCCVT,.SCCONS)
IF $G(SCCV("PAR")) S SCVSIT("PAR")=SCCV("PAR")
;
; -- use parent's visit if a/e, location same, clinic stop same
IF $G(SCVSIT("PAR")),SCVSIT("ORG")=2 D
. N SCOEP0
. S SCOEP0=$G(^SCE(SCVSIT("PAR"),0))
. IF $P(SCOEP0,U,5),SCVSIT("LOC")=$P(SCOEP0,U,4),SCVSIT("CLN")=$P(SCOEP0,U,3) S SCVSIT("VST")=$P(SCOEP0,U,5)
;
IF '$G(SCVSIT("VST")) D VISIT^SDVSIT0(SCDTM,.SCVSIT)
;
IF $G(SCVSIT("VST")) S SCTOT(1.02)=$G(SCTOT(1.02))+1
;
IF $G(SCVSIT("VST")),'$P(SCCV("OE",0),U,5) D
. ; -- fix invalid date/time of a/e to sync w/visit
. IF SCVSIT("ORG")=2,+SCCV("OE",0)'=SCDTM S SCDATA(.01)=SCDTM
. S SCDATA(.05)=SCVSIT("VST")
. D UPD^SCCVDBU(409.68,SCOE,.SCDATA)
;
S SCCV("OE",0)=$G(^SCE(SCOE,0))
S SCCV("VST")=$G(SCVSIT("VST"))
;
VISITQ Q $G(SCVSIT("VST"))
;
ANC(SCOEP,DFN,SCDTM,SCCLN,SCCV,SCLOG) ;Create stp code enctr/visit for ancillary tests
; Input -- SCOEP Parent encounter (if known)
; DFN Patient IEN
; SCDTM Appointment date/time
; SCCLN Clinic IEN
; SCCV Conversion array
; SCLOG Scheduling conversion log IEN [optional]
; Output -- None
N SCANC,SCOE,SCSCD,SCSCDI,SCVSIT,SCT,SCADD
I $G(SCCV("PT",0))=""!$S(SCCV("EVT"):$G(SCCV("OE",0))="",1:0) G ANCQ
I $P(SCCV("PT",0),U,3)'="" S SCANC(108)=$P(SCCV("PT",0),U,3) ; lab
I $P(SCCV("PT",0),U,4)'="" S SCANC(105)=$P(SCCV("PT",0),U,4) ; x-ray
I $P(SCCV("PT",0),U,5)'="" S SCANC(107)=$P(SCCV("PT",0),U,5) ; ekg
S SCSCD=""
F S SCSCD=$O(SCANC(SCSCD)) Q:'SCSCD D
. S SCSCDI=+$O(^DIC(40.7,"C",SCSCD,0))
. ;
. S SCADD=$$CHK(DFN,SCDTM,SCCLN,.SCCV,SCSCDI,.SCOE)
. I SCADD D
. . ;Increment number of ancillaries found (estimating only)
. . S SCVSIT("DFN")=DFN
. . I 'SCCVEVT D Q
. . . F SCT=2,SCADD+6 D
. . . . N DFN
. . . . D INCRTOT^SCCVEGU1(.SCTOT,SCT,1),EN^SCCVZZ("AE-"_SCT,SCOE,SCANC(SCSCD),$P($G(SCCV("PT",0)),U),+$G(SCOEP),SCVSIT("DFN"))
. . ;
. . I SCADD=1 D
. . . S SCVSIT("CLN")=SCSCDI
. . . S SCVSIT("DIV")=$P(SCCV("OE",0),U,11)
. . . S SCVSIT("ELG")=$P(SCCV("OE",0),U,13)
. . . S SCVSIT("LOC")=SCCLN
. . . S SCVSIT("TYP")=$P(SCCV("OE",0),U,10)
. . . S SCVSIT("PAR")=$G(SCOEP)
. . . S SCVSIT("ORG")=2,SCVSIT("REF")=""
. . . D SETSCCVT(.SCCVT,.SCCONS)
. . . S SCOE=$$SDOE^SDVSIT(SCANC(SCSCD),.SCVSIT,"",$G(SCOEP))
. . . I '$G(SCVSIT("VST")) D Q
. . . . D CREATERR^SCCVLOG1(DFN,SCDTM,SCOE,2,SCCLN,SCSCD,$G(SCLOG))
. . . . S:$G(SCOE) ^XTMP("SCCV-ERR-"_+SCLOG,"NO-VIS",SCOE)=""
. . . . S SCTOT(2.06)=$G(SCTOT(2.06))+1
. . . Q:'SCOE
. . . S SCTOT(1.02)=$G(SCTOT(1.02))+1
. . . N SCCVX
. . . S SCCVX("HIST")=0
. . . S SCCVX("NEW")=1
. . . D ENC^SCCVEAP1(SCOE,.SCCVX)
. . ;
. . I SCADD=2,SCOE D
. . . N SCCVX,SCCVY
. . . S SCCVY("OE")=SCOE
. . . S SCCVY("OE",0)=$G(^SCE(SCOE,0))
. . . S SCCVY("PAR")=$P(SCCVY("OE",0),U,6)
. . . S SCCVY("ORG")=2
. . . S SCVSIT("VST")=$$VISIT(+SCCVY("OE",0),.SCCVY) ; create visit
. . . I 'SCVSIT("VST") D Q
. . . . D CREATERR^SCCVLOG1(DFN,+SCCVY("OE",0),SCOE,2,$P(SCCVY("OE",0),U,4),SCSCD,$G(SCLOG))
. . . . S ^XTMP("SCCV-ERR-"_+SCLOG,"NO-VIS",SCOE)=""
. . . . S SCTOT(2.06)=$G(SCTOT(2.06))+1
. . . N SCCVX
. . . S SCCVX("VST")=SCVSIT("VST") D ENC^SCCVEAP1(SCOE,.SCCVX)
;
ANCQ Q
;
CHK(DFN,SCDTM,SCCLN,SCCV,SCSCDI,SCOE) ;Check if stop code should be added for ancillary test
; Input -- DFN Patient IEN
; SCDTM Appointment date/time
; SCCLN Clinic IEN
; SCCV Conversion array
; SCSCDI Clinic Stop Code IEN
; Output -- 1=Add enctr and visit 2=Add only visit and 0=No,don't add
; SCOE IEN of the encounter for the anc test
N Y,SCAEDTM,SCDA,SCOEC,SCOE00,SDQ
S Y=1,SCOE=""
;
I $P($G(^SC(SCCLN,0)),U,17)="Y" S Y=0 G CHKQ ; non-count clinic
;
; The following line is commented out because although it would be a valid check, it is much too tight and thus inconsistent with the rest of the conversion
;I $$REQ^SDM1A(SCDTM)="CO",'$P($G(SCCV("PT",0)),U,7) S Y=0 G CHKQ ; check out required but no checkout date, don't process
;
S (SCOEC,SDQ)=0
F S SCOEC=$O(^SCE("APAR",+$G(SCOEP),SCOEC)) Q:'SCOEC D Q:SDQ
. S SCOE00=$G(^SCE(SCOEC,0))
. I $P(SCOE00,U,3)=SCSCDI D
. . S SDQ=1
. . I 'SCCVEVT,$P(SCOE00,U,8)=2 S Y=0 Q ;Will be counted with add/edits
. . I SCCVEVT<2 D Q ;Estimate/convert
. . . I $P(SCOE00,U,5) S Y=0 Q ;Already added
. . . S Y=2,SCOE=SCOEC ;Add visit only
. . I SCCVEVT=2 D Q ;Re-convert
. . . D RECNVT^SCCVEAP3(SCOEC,SCOE00,.SCCONS)
. . . I $D(^SCE(SCOEC,0)) S Y=2,SCOE=SCOEC Q ;Re-add visit only
. . . S Y=1 ;Re-add visit and encounter
;
CHKQ Q $G(Y)
;
CHLD(SCOEP,SCCV,SCLOG) ;Convert children
; Input -- SCOEP Parent outpatient encounter IEN
; SCCV Conversion array
; SCLOG Scheduling conversion log IEN [optional]
; Output -- None
N SCERRMSG,SCOE0,SCOEC,SCX,SDVIEN
S SCOEC=0
F S SCOEC=$O(^SCE("APAR",SCOEP,SCOEC)) Q:'SCOEC D
. S SCOE0=$G(^SCE(SCOEC,0))
. S SDVIEN=$$SDVIEN^SCCVU(+$P(SCOE0,U,2),+SCOE0)
. I 'SCCV("EVT"),$P(SCOE0,U,9) D Q:'SCX
. . F SCX=1:1:$L($P(SCOE0,U,9),":") I $P($G(^SDV(SDVIEN,"CS",+$P($P(SCOE0,U,9),":",SCX),0)),U,8)=SCOEC S SCX=0 Q ;When estimating, these should be counted in the add/edit loop
. I $P(SCOE0,U,8)=2,$P(SCOE0,U,9),'$P(SCOE0,U,5) D ;convert child add/edit
. . ;There should be only 1 ":" piece before 10/1/96, but this was
. . ; included in the case of bad data
. . F SCX=1:1:$L($P(SCOE0,U,9),":") D EN^SCCVEAE1(SCCV("EVT"),SDVIEN,+$P($P(SCOE0,U,9),":",SCX),SCOEP,$G(SCLOG))
Q
;
SETSCCVT(SCCVT,SCCONS) ; Set the SCCVT array for source and service type
S SCCVT("SOR")=SCCONS("SRCE")
S SCCVT("SVC")="E"
I $G(SCCV("ORG"))=3,$G(SCCV("LOC")) S SCCVT("LOC")=SCCV("LOC")
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSCCVEAP2 6664 printed Dec 13, 2024@02:38:45 Page 2
SCCVEAP2 ;ALB/RMO,TMP - Appointment Conversion cont.; [ 04/05/95 10:19 AM ]
+1 ;;5.3;Scheduling;**211**;Aug 13, 1993
+2 ;
VISIT(SCDTM,SCCV) ;Create visit when encounter already exists
+1 ; Input -- SCDTM Appointment date/time
+2 ; SCCV Conversion array
+3 ; Output -- Visit file IEN
+4 NEW SCVSIT,SCDATA,SCCVT,SCOE
+5 IF '$GET(SCCV("OE",0))
GOTO VISITQ
+6 SET SCOE=$GET(SCCV("OE"))
+7 SET SCVSIT("DFN")=$PIECE(SCCV("OE",0),U,2)
+8 IF 'SCVSIT("DFN")
GOTO VISITQ
+9 ;
+10 SET SCVSIT("CLN")=$SELECT('$GET(SCCV("CSC")):$PIECE(SCCV("OE",0),U,3),1:SCCV("CSC"))
+11 ;
+12 SET SCVSIT("DIV")=$PIECE(SCCV("OE",0),U,11)
+13 SET SCVSIT("ELG")=$PIECE(SCCV("OE",0),U,13)
+14 SET SCVSIT("LOC")=$PIECE(SCCV("OE",0),U,4)
+15 SET SCVSIT("TYP")=$PIECE(SCCV("OE",0),U,10)
+16 SET SCVSIT("STA")=$PIECE(SCCV("OE",0),U,12)
+17 SET SCVSIT("ORG")=$GET(SCCV("ORG"))
+18 ;
+19 DO SETSCCVT(.SCCVT,.SCCONS)
+20 IF $GET(SCCV("PAR"))
SET SCVSIT("PAR")=SCCV("PAR")
+21 ;
+22 ; -- use parent's visit if a/e, location same, clinic stop same
+23 IF $GET(SCVSIT("PAR"))
IF SCVSIT("ORG")=2
Begin DoDot:1
+24 NEW SCOEP0
+25 SET SCOEP0=$GET(^SCE(SCVSIT("PAR"),0))
+26 IF $PIECE(SCOEP0,U,5)
IF SCVSIT("LOC")=$PIECE(SCOEP0,U,4)
IF SCVSIT("CLN")=$PIECE(SCOEP0,U,3)
SET SCVSIT("VST")=$PIECE(SCOEP0,U,5)
End DoDot:1
+27 ;
+28 IF '$GET(SCVSIT("VST"))
DO VISIT^SDVSIT0(SCDTM,.SCVSIT)
+29 ;
+30 IF $GET(SCVSIT("VST"))
SET SCTOT(1.02)=$GET(SCTOT(1.02))+1
+31 ;
+32 IF $GET(SCVSIT("VST"))
IF '$PIECE(SCCV("OE",0),U,5)
Begin DoDot:1
+33 ; -- fix invalid date/time of a/e to sync w/visit
+34 IF SCVSIT("ORG")=2
IF +SCCV("OE",0)'=SCDTM
SET SCDATA(.01)=SCDTM
+35 SET SCDATA(.05)=SCVSIT("VST")
+36 DO UPD^SCCVDBU(409.68,SCOE,.SCDATA)
End DoDot:1
+37 ;
+38 SET SCCV("OE",0)=$GET(^SCE(SCOE,0))
+39 SET SCCV("VST")=$GET(SCVSIT("VST"))
+40 ;
VISITQ QUIT $GET(SCVSIT("VST"))
+1 ;
ANC(SCOEP,DFN,SCDTM,SCCLN,SCCV,SCLOG) ;Create stp code enctr/visit for ancillary tests
+1 ; Input -- SCOEP Parent encounter (if known)
+2 ; DFN Patient IEN
+3 ; SCDTM Appointment date/time
+4 ; SCCLN Clinic IEN
+5 ; SCCV Conversion array
+6 ; SCLOG Scheduling conversion log IEN [optional]
+7 ; Output -- None
+8 NEW SCANC,SCOE,SCSCD,SCSCDI,SCVSIT,SCT,SCADD
+9 IF $GET(SCCV("PT",0))=""!$SELECT(SCCV("EVT"):$GET(SCCV("OE",0))="",1:0)
GOTO ANCQ
+10 ; lab
IF $PIECE(SCCV("PT",0),U,3)'=""
SET SCANC(108)=$PIECE(SCCV("PT",0),U,3)
+11 ; x-ray
IF $PIECE(SCCV("PT",0),U,4)'=""
SET SCANC(105)=$PIECE(SCCV("PT",0),U,4)
+12 ; ekg
IF $PIECE(SCCV("PT",0),U,5)'=""
SET SCANC(107)=$PIECE(SCCV("PT",0),U,5)
+13 SET SCSCD=""
+14 FOR
SET SCSCD=$ORDER(SCANC(SCSCD))
if 'SCSCD
QUIT
Begin DoDot:1
+15 SET SCSCDI=+$ORDER(^DIC(40.7,"C",SCSCD,0))
+16 ;
+17 SET SCADD=$$CHK(DFN,SCDTM,SCCLN,.SCCV,SCSCDI,.SCOE)
+18 IF SCADD
Begin DoDot:2
+19 ;Increment number of ancillaries found (estimating only)
+20 SET SCVSIT("DFN")=DFN
+21 IF 'SCCVEVT
Begin DoDot:3
+22 FOR SCT=2,SCADD+6
Begin DoDot:4
+23 NEW DFN
+24 DO INCRTOT^SCCVEGU1(.SCTOT,SCT,1)
DO EN^SCCVZZ("AE-"_SCT,SCOE,SCANC(SCSCD),$PIECE($GET(SCCV("PT",0)),U),+$GET(SCOEP),SCVSIT("DFN"))
End DoDot:4
End DoDot:3
QUIT
+25 ;
+26 IF SCADD=1
Begin DoDot:3
+27 SET SCVSIT("CLN")=SCSCDI
+28 SET SCVSIT("DIV")=$PIECE(SCCV("OE",0),U,11)
+29 SET SCVSIT("ELG")=$PIECE(SCCV("OE",0),U,13)
+30 SET SCVSIT("LOC")=SCCLN
+31 SET SCVSIT("TYP")=$PIECE(SCCV("OE",0),U,10)
+32 SET SCVSIT("PAR")=$GET(SCOEP)
+33 SET SCVSIT("ORG")=2
SET SCVSIT("REF")=""
+34 DO SETSCCVT(.SCCVT,.SCCONS)
+35 SET SCOE=$$SDOE^SDVSIT(SCANC(SCSCD),.SCVSIT,"",$GET(SCOEP))
+36 IF '$GET(SCVSIT("VST"))
Begin DoDot:4
+37 DO CREATERR^SCCVLOG1(DFN,SCDTM,SCOE,2,SCCLN,SCSCD,$GET(SCLOG))
+38 if $GET(SCOE)
SET ^XTMP("SCCV-ERR-"_+SCLOG,"NO-VIS",SCOE)=""
+39 SET SCTOT(2.06)=$GET(SCTOT(2.06))+1
End DoDot:4
QUIT
+40 if 'SCOE
QUIT
+41 SET SCTOT(1.02)=$GET(SCTOT(1.02))+1
+42 NEW SCCVX
+43 SET SCCVX("HIST")=0
+44 SET SCCVX("NEW")=1
+45 DO ENC^SCCVEAP1(SCOE,.SCCVX)
End DoDot:3
+46 ;
+47 IF SCADD=2
IF SCOE
Begin DoDot:3
+48 NEW SCCVX,SCCVY
+49 SET SCCVY("OE")=SCOE
+50 SET SCCVY("OE",0)=$GET(^SCE(SCOE,0))
+51 SET SCCVY("PAR")=$PIECE(SCCVY("OE",0),U,6)
+52 SET SCCVY("ORG")=2
+53 ; create visit
SET SCVSIT("VST")=$$VISIT(+SCCVY("OE",0),.SCCVY)
+54 IF 'SCVSIT("VST")
Begin DoDot:4
+55 DO CREATERR^SCCVLOG1(DFN,+SCCVY("OE",0),SCOE,2,$PIECE(SCCVY("OE",0),U,4),SCSCD,$GET(SCLOG))
+56 SET ^XTMP("SCCV-ERR-"_+SCLOG,"NO-VIS",SCOE)=""
+57 SET SCTOT(2.06)=$GET(SCTOT(2.06))+1
End DoDot:4
QUIT
+58 NEW SCCVX
+59 SET SCCVX("VST")=SCVSIT("VST")
DO ENC^SCCVEAP1(SCOE,.SCCVX)
End DoDot:3
End DoDot:2
End DoDot:1
+60 ;
ANCQ QUIT
+1 ;
CHK(DFN,SCDTM,SCCLN,SCCV,SCSCDI,SCOE) ;Check if stop code should be added for ancillary test
+1 ; Input -- DFN Patient IEN
+2 ; SCDTM Appointment date/time
+3 ; SCCLN Clinic IEN
+4 ; SCCV Conversion array
+5 ; SCSCDI Clinic Stop Code IEN
+6 ; Output -- 1=Add enctr and visit 2=Add only visit and 0=No,don't add
+7 ; SCOE IEN of the encounter for the anc test
+8 NEW Y,SCAEDTM,SCDA,SCOEC,SCOE00,SDQ
+9 SET Y=1
SET SCOE=""
+10 ;
+11 ; non-count clinic
IF $PIECE($GET(^SC(SCCLN,0)),U,17)="Y"
SET Y=0
GOTO CHKQ
+12 ;
+13 ; The following line is commented out because although it would be a valid check, it is much too tight and thus inconsistent with the rest of the conversion
+14 ;I $$REQ^SDM1A(SCDTM)="CO",'$P($G(SCCV("PT",0)),U,7) S Y=0 G CHKQ ; check out required but no checkout date, don't process
+15 ;
+16 SET (SCOEC,SDQ)=0
+17 FOR
SET SCOEC=$ORDER(^SCE("APAR",+$GET(SCOEP),SCOEC))
if 'SCOEC
QUIT
Begin DoDot:1
+18 SET SCOE00=$GET(^SCE(SCOEC,0))
+19 IF $PIECE(SCOE00,U,3)=SCSCDI
Begin DoDot:2
+20 SET SDQ=1
+21 ;Will be counted with add/edits
IF 'SCCVEVT
IF $PIECE(SCOE00,U,8)=2
SET Y=0
QUIT
+22 ;Estimate/convert
IF SCCVEVT<2
Begin DoDot:3
+23 ;Already added
IF $PIECE(SCOE00,U,5)
SET Y=0
QUIT
+24 ;Add visit only
SET Y=2
SET SCOE=SCOEC
End DoDot:3
QUIT
+25 ;Re-convert
IF SCCVEVT=2
Begin DoDot:3
+26 DO RECNVT^SCCVEAP3(SCOEC,SCOE00,.SCCONS)
+27 ;Re-add visit only
IF $DATA(^SCE(SCOEC,0))
SET Y=2
SET SCOE=SCOEC
QUIT
+28 ;Re-add visit and encounter
SET Y=1
End DoDot:3
QUIT
End DoDot:2
End DoDot:1
if SDQ
QUIT
+29 ;
CHKQ QUIT $GET(Y)
+1 ;
CHLD(SCOEP,SCCV,SCLOG) ;Convert children
+1 ; Input -- SCOEP Parent outpatient encounter IEN
+2 ; SCCV Conversion array
+3 ; SCLOG Scheduling conversion log IEN [optional]
+4 ; Output -- None
+5 NEW SCERRMSG,SCOE0,SCOEC,SCX,SDVIEN
+6 SET SCOEC=0
+7 FOR
SET SCOEC=$ORDER(^SCE("APAR",SCOEP,SCOEC))
if 'SCOEC
QUIT
Begin DoDot:1
+8 SET SCOE0=$GET(^SCE(SCOEC,0))
+9 SET SDVIEN=$$SDVIEN^SCCVU(+$PIECE(SCOE0,U,2),+SCOE0)
+10 IF 'SCCV("EVT")
IF $PIECE(SCOE0,U,9)
Begin DoDot:2
+11 ;When estimating, these should be counted in the add/edit loop
FOR SCX=1:1:$LENGTH($PIECE(SCOE0,U,9),":")
IF $PIECE($GET(^SDV(SDVIEN,"CS",+$PIECE($PIECE(SCOE0,U,9),":",SCX),0)),U,8)=SCOEC
SET SCX=0
QUIT
End DoDot:2
if 'SCX
QUIT
+12 ;convert child add/edit
IF $PIECE(SCOE0,U,8)=2
IF $PIECE(SCOE0,U,9)
IF '$PIECE(SCOE0,U,5)
Begin DoDot:2
+13 ;There should be only 1 ":" piece before 10/1/96, but this was
+14 ; included in the case of bad data
+15 FOR SCX=1:1:$LENGTH($PIECE(SCOE0,U,9),":")
DO EN^SCCVEAE1(SCCV("EVT"),SDVIEN,+$PIECE($PIECE(SCOE0,U,9),":",SCX),SCOEP,$GET(SCLOG))
End DoDot:2
End DoDot:1
+16 QUIT
+17 ;
SETSCCVT(SCCVT,SCCONS) ; Set the SCCVT array for source and service type
+1 SET SCCVT("SOR")=SCCONS("SRCE")
+2 SET SCCVT("SVC")="E"
+3 IF $GET(SCCV("ORG"))=3
IF $GET(SCCV("LOC"))
SET SCCVT("LOC")=SCCV("LOC")
+4 QUIT
+5 ;