source: FOIAVistA/tag/r/SCHEDULING-SD-SC/SDSTAT.m@ 1424

Last change on this file since 1424 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 4.1 KB
Line 
1SDSTAT ;MJK/ALB - Appt Status Update Protocol for ADT ; 7/14/92
2 ;;5.3;Scheduling;**31,132,396**;Aug 13, 1993
3 ;
4EN ; -- main entry point called by ADT event driver
5 ; -- process adm and d/c only
6 I '$D(^UTILITY("DGPM",$J,1)),'$D(^(3)) G ENQ
7 I '$O(^DPT(DFN,"S",0)) G ENQ
8 N SDBEG,SDEND,PREV,AFTER,SDP,SDA,SDTYPE,SDCA K ^TMP("SDSTAT",$J),^TMP("SDOE STAT",$J)
9 W:'$G(DGQUIET) !!,"Updating appointment status..."
10 S ^TMP("SDSTAT",$J,0)=0,^TMP("SDOE STAT",$J,0)=0
11 F SDTYPE=1,3 S SDMVT="" F S SDMVT=$O(^UTILITY("DGPM",$J,SDTYPE,SDMVT)) Q:'SDMVT S SDP=$G(^(SDMVT,"P")),SDA=$G(^("A")) D
12 .S PREV=$S(+SDP:+SDP,1:9999999),AFTER=$S(+SDA:+SDA,1:9999999)
13 .I SDTYPE=3,+SDP=+SDA Q ; d/c & same d/t then quit
14 .I SDTYPE=3,$P($G(^DIC(42,+$P($G(^DGPM(+$P($S(SDP]"":SDP,1:SDA),U,14),0)),U,6),0)),U,3)="D" Q ; d/c & admitted to dom ward then quit
15 .I SDTYPE=1,+SDP=+SDA,$P(SDP,U,6)=$P(SDA,U,6) Q ; adm -> same d/t & same ward then quit
16 .I SDTYPE=1,+SDP=+SDA S PREV=+SDP,AFTER=$S(+$G(^DGPM(+$P(SDP,U,17),0)):+^(0),1:9999999) ; adm & same d/t then reset date range
17 .S SDBEG=$S(PREV>AFTER:AFTER,1:PREV),SDEND=$S(PREV>AFTER:PREV,1:AFTER)
18 .D SCAN(DFN,SDBEG,SDEND) Q
19 W:'$G(DGQUIET) "completed."
20ENQ K ^TMP("SDSTAT",$J),^TMP("SDOE STAT",$J) Q
21 ;
22SCAN(SDFN,SDBEG,SDEND) ; -- scan range of appts to update
23 ; input: SDFN := ien of patient
24 ; SDBEG := begin date
25 ; SDEND := end date
26 ; ^TMP("SDSTAT",$J) := array of apts processed
27 ; ^TMP("SDOE STAT",$J) := array of encounters processed
28 ;
29 N SDT,SDOE,SDOEP,SDORG,SDSTB,SDSTA
30 ; -- process appts
31 S SDT=SDBEG
32 F S SDT=$O(^DPT(SDFN,"S",SDT)) Q:'SDT!(SDT>SDEND) D
33 .I $D(^TMP("SDSTAT",$J,SDT)) Q ; appt already processed
34 .S ^TMP("SDSTAT",$J,0)=^TMP("SDSTAT",$J,0)+1,^(SDT)=""
35 .D UPDATE(SDFN,SDT)
36 ;
37 ; -- process encounters
38 S SDT=SDBEG
39 F S SDT=$O(^SCE("ADFN",SDFN,SDT)) Q:'SDT!(SDT>SDEND) D
40 .S SDOE=0 F S SDOE=$O(^SCE("ADFN",SDFN,SDT,SDOE)) Q:'SDOE D
41 ..I $D(^TMP("SDOE STAT",$J,SDOE)) Q ; emcounter already processed
42 ..S ^TMP("SDOE STAT",$J,0)=^TMP("SDOE STAT",$J,0)+1,^(SDOE)=""
43 ..S SDOE0=$G(^SCE(SDOE,0)),SDORG=$P(SDOE0,U,8),SDOEP=$P(SDOE0,U,6)
44 ..I SDOEP!(SDORG=1) Q
45 ..S SDSTB=$S($P(SDOE0,U,12)=8:"I",1:""),SDSTA=$$INP^SDAM2(SDFN,SDT)
46 ..N SDATA,SDADTHDL,DFN S SDADTHDL=$$HANDLE^SDAMEVT(SDORG),DFN=SDFN
47 ..I SDORG=2 D BEFORE^SDAMEVT2(SDOE,SDADTHDL)
48 ..I SDORG=3 D BEFORE^SDAMEVT3(SDFN,SDT,9,SDADTHDL)
49 ..D OE(SDOE,SDSTB,SDSTA,SDADTHDL)
50 ..I SDORG=2 D EVT^SDAMEVT2(SDOE,7,SDADTHDL)
51 ..I SDORG=3 D EVT^SDAMEVT3(SDFN,SDT,9,SDADTHDL)
52 Q
53 ;
54UPDATE(DFN,SDT) ; -- update appt status
55 ; input: DFN := ien of patient
56 ; SDT := date of appt
57 ;
58 N SDATA,SDSTB,SDSTA,SDSTB,SDOE,SDCL
59 G UPDATEQ:'$D(^DPT(DFN,"S",SDT,0)) S SDATA=^(0)
60 S SDOE=+$P(SDATA,U,20),SDSTB=$P(SDATA,U,2),SDCL=+SDATA
61 I SDSTB=""!(SDSTB="NT")!(SDSTB="I") S SDSTA=$$STAT() I SDSTB'=SDSTA D
62 .I $$REQ^SDM1A(SDT)="CI"!(SDT'<(DT+.2359)) S $P(^DPT(DFN,"S",SDT,0),U,2)=SDSTA Q
63 .I SDT<(DT+.2359) D
64 ..N SDATA,SDADTHDL,SDOEC
65 ..S SDOE=$S(SDOE:SDOE,1:+$$GETAPT^SDVSIT2(DFN,SDT,SDCL)) Q:'SDOE
66 ..S SDADTHDL=$$HANDLE^SDAMEVT(+$P($G(^SCE(SDOE,0)),U,8))
67 ..D OEVT^SDAMEVT(SDOE,"BEFORE",SDADTHDL,.SDATA)
68 ..S $P(^DPT(DFN,"S",SDT,0),U,2)=SDSTA
69 ..D OE(SDOE,SDSTB,SDSTA,SDADTHDL)
70 ..D OEVT^SDAMEVT(SDOE,"AFTER",SDADTHDL,.SDATA)
71 ..I SDSTA="I",$G(SDOE),$P($G(^SCE(SDOE,0)),U,12)=14 D
72 ...S $P(^SCE(SDOE,0),U,12)=8
73 ...S SDOEC=$O(^SCE("APAR",SDOE,SDOE)) I SDOEC S $P(^SCE(SDOEC,0),U,12)=8
74UPDATEQ Q
75 ;
76STAT() ; -- determine status of appt
77 N C,X
78 S C=$G(^SC(+SDATA,"S",SDT,1,+$$FIND^SDAM2(DFN,SDT,+SDATA),"C"))
79 I $$INP^SDAM2(DFN,SDT)="I" S X="I" G STATQ ; inpatient
80 I SDT>(DT+.2359) S X="" G STATQ ; future
81 I $$REQ^SDM1A(.SDT)="CI",C S X="" G STATQ ; checked in
82 I $$COCMP^SDM1A(DFN,SDT),$P(C,U,3) S X="" G STATQ ; checked out
83 I '$$CHK^SDM1A(+SDATA,SDT) S X="" G STATQ ; non-count
84 S X="NT"
85STATQ Q X
86 ;
87OE(SDOE,SDSTB,SDSTA,SDHDL) ; -- update outpatient encounter if appropriate
88 N Y
89 S Y=0
90 I 'Y,SDSTB="I",SDSTA="NT" S Y=1
91 I 'Y,SDSTB="I",SDSTA="" S Y=1
92 I 'Y,SDSTB="NT",SDSTA="I" S Y=1
93 I 'Y,SDSTB="",SDSTA="I" S Y=1
94 I Y D
95 .D COMDT^SDCODEL(SDOE,0)
96 .D EN^SDCOM(SDOE,0,SDHDL)
97OEQ Q
Note: See TracBrowser for help on using the repository browser.