source: WorldVistAEHR/trunk/r/ICR_IMMUNOLOGY_CASE_REGISTRY-IMR/IMRSUDOP.m@ 1096

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

initial load of WorldVistAEHR

File size: 4.7 KB
Line 
1IMRSUDOP ;ISC-SF/JLI,HCIOFO/FT/FAI/SPS-LOCAL COUNT OF PTS, STATUS, OP VISITS, IP STAYS, ETC. ;07/23/01 07:28
2 ;;2.1;IMMUNOLOGY CASE REGISTRY;**5,13**;Feb 09, 1998
3DQ ;
4 U IO K ^TMP($J) S X1=IMRED,X2=1 D C^%DTC S IMREDP1=X
5 F IMRL=0:0 S IMRL=$O(^IMR(158,IMRL)) Q:IMRL'>0 S X=+^(IMRL,0),IMR1C=+$P(^(0),U,42) D XOR^IMRXOR S IMRDFN=X I $D(^DPT(IMRDFN,0)) S DFN=IMRDFN D NS^IMRCALL K DFN F IMR0C=IMR1C,"T" I IMR2C!(IMR0C="T") S IMR1C="C"_IMR0C D C1
6 K VADM,VA
7 D ^IMRLCNT1,^IMRLCNT2
8KILL Q
9 Q
10C1 S IMRSDV=0,IMRSDVA=1,DFN=IMRDFN D DEM^VADPT
11 S IMRDTH=$P($G(VADM(6)),"^",1)
12 I IMRDTH,IMRDTH<IMRSD Q ;quit if dead before start date of report
13 I +$$VERSION^XPDUTL("SD")>5.3 S IMRSDV=1 D ACRP G DGPT ;get data from File 409.68
14 I +$$PATCH^XPDUTL("SD*5.3*131")>0 S IMRSDV=1 D ACRP G DGPT ;get data from File 409.68
15 S VASD("F")=IMRSD,VASD("T")=IMRED D SDA^VADPT K DFN,VASD
16 F IMRDY=0:0 S IMRDY=$O(^UTILITY("VASD",$J,IMRDY)) Q:IMRDY'>0 S IMRD=+^(IMRDY,"I"),IMRCS=$P(^("I"),U,2) D C2
17 K ^UTILITY("VASD",$J)
18 S IMRSDV=1
19 F IMRD=IMRSD-.0000001:0 S IMRD=$O(^SDV("C",IMRDFN,IMRD)) Q:IMRD'>0!(IMRD'<(IMRED+1)) S IMRSDVA=$S('$D(^TMP($J,IMR1C,"PAT",IMRDFN,"S",(IMRD\1))):1,1:0) S IMRSDVI=IMRD D SDVCS^IMRUTL I $D(IMRAR(409.51)) D
20 .S J="" F S J=$O(IMRAR(409.51,J)) Q:J="" S IMRCS=$G(IMRAR(409.51,J,.01,"I")) D C2
21 .Q
22DGPT K IMRAR,IMRSDVI
23 F IMRI=0:0 S IMRI=$O(^DGPT("B",IMRDFN,IMRI)) Q:IMRI'>0 I $D(^DGPT(IMRI,0)),+^(0)=IMRDFN S IMRPTF=IMRI D PTF^IMRUTL D
24 .S IMRDD=$S(+IMRDD'>0:0,1:+IMRDD)
25 .Q:'IMRAD
26 .S IMRFLG=0
27 .I 'IMRDD D DBCHK(IMRDFN,IMRAD,.IMRDD,.IMRFLG)
28 .Q:IMRFLG
29 .I (IMRDD=0&(IMRAD'>IMRED))!((IMRDD'<IMRSD)&(IMRAD'>IMRED)) D C3
30 .Q
31 Q
32C2 ;
33 S:'IMRSDV IMRCS=+$$ARSC^IMRUTL(+IMRCS) ;get ptr value to File 40.7
34 S IMRCS=$S($D(^DIC(40.7,IMRCS,0)):$P(^(0),U,2),1:"NO SC ID")
35 S:IMRCS="" IMRCS=$P(^DIC(40.7,IMRCS,0),U)
36 I IMRCS="NO SC ID" S ^TMP($J,IMR1C,"NO SC",IMRDFN,IMRD,IMRSDV)=""
37 S ^("OP")=$S($D(^TMP($J,IMR1C,"PAT",IMRDFN,"OP")):^("OP"),1:0)+1,^(IMRCS)=$S($D(^("OP",IMRCS)):^(IMRCS),1:0)+1
38 S IMRDX=IMRD\1
39 I '$D(^TMP($J,IMR1C,"PAT",IMRDFN,"S",IMRDX,IMRCS)) S ^(IMRCS)=$S(IMRSDV:"SDV",1:""),^(IMRDX)=$S(($D(^TMP($J,IMR1C,"PAT",IMRDFN,"S",IMRDX))#2):^(IMRDX),1:0)+1
40 Q
41C3 ;
42 I '$D(IMRSUF)!('$D(IMREC)) S IMRPTF=IMRI D PTF^IMRUTL
43 I IMRSUF'="",'(IMRSUF="9AA"!(IMRSUF="A0")!(IMRSUF="9AB")!(IMRSUF="9AD")!(IMRSUF="9AC")!(IMRSUF="9AE")!(IMRSUF="9BB")!(IMRSUF="A4")!(IMRSUF="A5")!(IMRSUF="BU")!(IMRSUF="BV")!(IMRSUF="PA")) Q
44 Q:+IMREC>1 ; IGNORE CENSUS PTF ENTRIES
45 S IMRAD1=IMRAD,IMRAD=$S(IMRAD'<IMRSD:IMRAD,1:IMRSD),IMRDD=$S(IMRDD=0:IMREDP1,(IMRDD\1)'>IMRED:IMRDD,1:IMREDP1)
46 S ^("IP")=$S($D(^TMP($J,IMR1C,"PAT",IMRDFN,"IP")):^("IP"),1:0)+1,X1=IMRDD\1,X2=IMRAD\1
47 D ^%DTC S:X=0 X=1 S IMRDAYS=X,^("DAYS")=$S($D(^TMP($J,IMR1C,"PAT",IMRDFN,"IP","DAYS")):^("DAYS"),1:0)+IMRDAYS,^(IMRDAYS)=$S($D(^(IMRDAYS)):^(IMRDAYS),1:0)+1
48 S IMRD1=IMRAD\1,K=0 S IMRAD1=IMRAD1\1
49 S IMRPTF=IMRI D ICDM^IMRUTL,REORDER^IMRUTL K IMRAR
50 I $D(IMR4502) F K=IMRAD1:0 S K=$O(IMR4502(K)) Q:K'<IMRAD!(K="") S IMRAD1=K\1
51 S K=0,IMRROU="C4^IMRLCNT1"
52 F IMRJ=IMRD1:0 S IMRJ=$O(IMR4502(IMRJ)) Q:IMRJ'>0!(IMRJ'<(IMRDD\1)) D
53 .D C31,^%DTC S IMRDAYS=X
54 .S IMRBS=$P(IMR4502(IMRJ),U,1) ;treating specialty (external) File 45
55 .S IMRBSO=$$TREAT(IMRDFN) ;treating specialty (external) File 2
56 .S IMRBS=$S(IMRBS]"":IMRBS,1:IMRBSO)
57 .S:IMRBS="" IMRBS="NO ID"
58 .D @IMRROU S IMRD1=IMRJ\1
59 .Q
60 K IMRROU S X2=IMRD1,X1=IMRDD\1 D ^%DTC S:X=0 X=1 S IMRDAYS=X,IMRBS=$S($D(IMRFIRST):$P(IMRFIRST,U,1),1:0) D
61 .S IMRBSO=$$TREAT(IMRDFN)
62 .S IMRBS=$S(IMRBS]"":IMRBS,1:IMRBSO)
63 .S:IMRBS="" IMRBS="NO ID"
64 .D C4^IMRLCNT1
65 .Q
66 K IMR4502,IMRFIRST
67 Q
68C31 S X1=IMRJ\1,X2=IMRD1
69 Q
70DBCHK(DFN,IMRAD,IMRDD,IMRFLG) ; Double Check if Admission date is valid and
71 ; if there is a discharge date or not. If
72 ; Admission date is not valid set IMRFLG=1
73 ; if Discharge date exist pass it back.
74 N IMRX
75 S VAINDT=IMRAD D ADM^VADPT2 K VAINDT I 'VADMVT K VADMVT S IMRFLG=1 Q
76 S IMRX=$$GET1^DIQ(405,VADMVT,.17,"I") K VADMVT Q:'IMRX
77 S IMRDD=$$GET1^DIQ(405,IMRX,.01,"I")
78 Q
79TREAT(DFN) ; Retrieve the patient's Treatment Specialty
80 S Y=$$GET1^DIQ(2,DFN,.103,"")
81 Q Y
82ACRP ; Ambulatory Care Reporting Changes
83 ; If site has SD*5.3*131 installed, then use the ACRP APIs to get
84 ; the stop code data.
85 N QUERY
86 D OPEN^SDQ(.QUERY)
87 D INDEX^SDQ(.QUERY,"PATIENT/DATE","SET")
88 D PAT^SDQ(.QUERY,IMRDFN,"SET")
89 D DATE^SDQ(.QUERY,IMRSD,IMREDP1,"SET")
90 D SCANCB^SDQ(.QUERY,"D SCAN^IMRLCNT(Y,Y0)","SET")
91 D ACTIVE^SDQ(.QUERY,"TRUE","SET")
92 D SCAN^SDQ(.QUERY,"FORWARD")
93 D CLOSE^SDQ(.QUERY)
94 Q
95SCAN(Y,Y0) ; Scan records returned by ACRP API
96 ; data comes from the Outpatient Encounter file (409.68)
97 S IMRD=+Y0 ;get visit/admit date/time
98 S IMRCS=$P(Y0,U,3) ;dds id, pointer to File 40.7 (Clinic Stop)
99 D C2
100 Q
Note: See TracBrowser for help on using the repository browser.