source: WorldVistAEHR/trunk/r/ENROLLMENT_APPLICATION_SYSTEM-EAS/EASXDR1.m@ 949

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

initial load of WorldVistAEHR

File size: 9.2 KB
Line 
1EASXDR1 ;ALB/BRM/PHH - CHECK RELATIONS DURING XDR PATIENT MERGE; ; 5/30/03 12:29pm
2 ;;1.0;ENROLLMENT APPLICATION SYSTEM;**10,26**;Mar 15, 2001
3 ;
4CHKRELAT(DFNFR,DFNTO,SILENT) ;can the relations on these 2 records be merged?
5 ;
6 ;INPUT:
7 ; DFNFR : the patient file ien of the merge from record
8 ; DFNTO : the patient file ien of the merge to record
9 ; SILENT: (optional) used to prevent screen writes and user
10 ; interaction during the merge process
11 ;
12 ; Note: DFNFR and DFNTO can both be the same if this process is
13 ; to clean-up patient relation file entries within the same
14 ; patient
15 ;
16 Q:'$G(DFNFR) "0^From DFN not passed"
17 Q:'$G(DFNTO) "0^To DFN not passed"
18 Q:'$D(^DGPR(408.12,"B",DFNFR)) "0^This patient did not have any relation entries that needed to be merged."
19 Q:'$D(^DGPR(408.12,"B",DFNTO)) "0^This patient did not have any relation entries that needed to be merged."
20 N ARYNAM2,REL,RELAT,NOMRGMSG,REASON,ARYNAM,X,ERR,NAMFIL
21 N ERROR,DIC,FRDATA,MRGFRIEN,MRGTOIEN,MSG,NAME,RELPNTR
22 N ACTOK,RELATE,EFFDT,SUBIEN,UPDMSG,MRGARY,MRGROOT,OK,IEN12TO
23 N ACTIVFR,ACTIVTO,SUBIENFR,SUBIENTO,ERRNUM,NAMIEN,IEN12FR
24 S MRGROOT="^TMP($J,""EASXDR1"",""B"")"
25 K ^TMP($J,"EASXDR1"),^TMP($J,"EASXDR")
26 S ^XTMP("EASXDR1",0)=$$FMADD^XLFDT($$NOW^XLFDT(),45)_U_$$NOW^XLFDT()_U_"EASXDR1 - DUPLICATE PATIENT RELATION MERGE"
27 ; find 408.12 entries for FROM and TO records
28 F X="IEN12FR","IEN12TO" D
29 .S REL="DFN"_$E(X,6,7),@X=""
30 .S ARYNAM="^TMP($J,""EASXDR1"","""_$E(X,6,7)_""")"
31 .S ARYNAM2="^TMP($J,""EASXDR1"",""B"","""_$E(X,6,7)_""")"
32 .F S @X=$O(^DGPR(408.12,"B",@REL,@X)) Q:'@X D
33 ..I '$D(^DGPR(408.12,@X)) S @ARYNAM@(@X)=(@REL)_"^NO 408.12 RECORD" Q
34 ..M @ARYNAM@((@X))=^DGPR(408.12,@X)
35 ..S RELPNTR=$P($G(@ARYNAM@(@X,0)),"^",3)
36 ..S NAMIEN=$P(RELPNTR,";")_",",NAMFIL=$P(RELPNTR,";",2)
37 ..I NAMFIL="DPT(" S NAMFIL=2
38 ..E S NAMFIL=$TR($P(NAMFIL,"(",2),",")
39 ..K NAME
40 ..I NAMIEN,NAMFIL S NAME=$$GET1^DIQ(NAMFIL,NAMIEN,.01)
41 ..S @ARYNAM@(@X,"NAME")=$G(NAME)
42 ..S RELAT=$P($G(^DGPR(408.12,@X,0)),"^",2)
43 ..S @ARYNAM2@(RELAT,@X)=""
44 ; merge duplicate records (if they exist)
45 S RELATE="",OK=0,ERRNUM=0
46 F S RELATE=$O(@MRGROOT@("TO",RELATE)) Q:'RELATE D
47 .S MRGTOIEN=""
48 .F S MRGTOIEN=$O(@MRGROOT@("TO",RELATE,MRGTOIEN)) Q:'MRGTOIEN D LOOP
49 Q +$G(OK)
50LOOP ;
51 M ^TMP($J,"EASXDR","MRGTO",MRGTOIEN)=^DGPR(408.12,MRGTOIEN)
52 S MRGFRIEN=""
53 F S MRGFRIEN=$O(@MRGROOT@("FR",RELATE,MRGFRIEN)) Q:'MRGFRIEN D
54 .Q:MRGFRIEN=MRGTOIEN ;do not update if FROM and TO iens are the same
55 .K ERROR
56 .I RELATE'=1 D Q:$D(ERROR)
57 ..I '$$MRGOTHR(MRGFRIEN,MRGTOIEN) S ERROR(MRGFRIEN)="DEPENDENT NAMES DO NOT MATCH" K @MRGROOT@("FR",RELATE,MRGTOIEN) Q
58 ..I '$$SSNMATCH(MRGFRIEN,MRGTOIEN) D Q:$D(ERROR)
59 ...Q:$P($G(^DGPR(408.12,MRGFRIEN,0)),"^",2)'=$P($G(^DGPR(408.12,MRGTOIEN,0)),"^",2)
60 ...S ERROR(MRGFRIEN)="DEPENDENT SSNS DO NOT MATCH"
61 ...D:'$G(SILENT) FAILED(MRGFRIEN,MRGTOIEN,$G(ERROR(MRGFRIEN)))
62 ...K @MRGROOT@("FR",RELATE,MRGTOIEN)
63 .M ^TMP($J,"EASXDR","MRGFR",MRGFRIEN)=^DGPR(408.12,MRGFRIEN)
64 .S EFFDT=""
65 .F S EFFDT=$O(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E","B",EFFDT)) Q:'EFFDT D
66 ..I $D(^DGPR(408.12,MRGTOIEN,"E","B",EFFDT)) D Q
67 ...S ACTOK=$$CHKACT()
68 ..S SUBIEN=+$O(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E","B",EFFDT,""))
69 ..Q:('SUBIEN)!('$D(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E",SUBIEN)))
70 ..S FRDATA=$G(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E",SUBIEN,0))
71 ..S UPDMSG=$$UPDATE(MRGTOIEN,FRDATA,MRGFRIEN)
72 ..I 'UPDMSG D Q
73 ...S ERROR(MRGFRIEN,SUBIEN)=$P(UPDMSG,"^",2),ERRNUM=ERRNUM+1
74 ...Q:$P(UPDMSG,"^",2)="The entry does not exist."
75 ...S ^XTMP("EASXDR1","DATA",DFNFR,"ERROR - NOT MERGED",MRGFRIEN,SUBIEN)=$P(UPDMSG,"^",2)
76 .I '$D(ERROR),$$REMOVE(MRGFRIEN,MRGTOIEN) D ;
77 ..S OK=OK+1
78 ..D:'$G(SILENT) SUCCESS(MRGFRIEN,MRGTOIEN)
79 ..K @MRGROOT@("FR",RELATE,MRGFRIEN)
80 ..K @MRGROOT@("TO",RELATE,MRGFRIEN)
81 ..I $D(@MRGROOT@("TO",RELATE,MRGFRIEN)) K @MRGROOT@("TO",RELATE,MRGFRIEN)
82 ..K ^TMP($J,"EASXDR")
83 ..M ^TMP($J,"EASXDR","MRGFR",MRGFRIEN)=^DGPR(408.12,MRGFRIEN)
84 ..M ^TMP($J,"EASXDR","MRGTO",MRGTOIEN)=^DGPR(408.12,MRGTOIEN)
85 Q
86CHKACT() ; ensure both records contain the same active flag for eff. date
87 N OK
88 S OK=1
89 S SUBIENFR=+$O(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E","B",EFFDT,""))
90 S SUBIENTO=+$O(^TMP($J,"EASXDR","MRGTO",MRGTOIEN,"E","B",EFFDT,""))
91 S ACTIVFR=$P($G(^TMP($J,"EASXDR","MRGFR",MRGFRIEN,"E",SUBIENFR,0)),"^",2)
92 S ACTIVTO=$P($G(^TMP($J,"EASXDR","MRGTO",MRGTOIEN,"E",SUBIENTO,0)),"^",2)
93 I ACTIVFR'=ACTIVTO D Q OK
94 .S OK=0
95 .S ERROR(MRGFRIEN,SUBIENFR)="'Active' flag does not match for effective date: "_$$FMTE^XLFDT(EFFDT),ERRNUM=ERRNUM+1
96 .S ^XTMP("EASXDR1","DATA",DFNFR,408.12,"ERROR - NOT MERGED",MRGFRIEN,SUBIENFR)=ERROR(MRGFRIEN,SUBIENFR)
97 .D:'$G(SILENT) FAILED(MRGFRIEN,MRGTOIEN,$G(ERROR(MRGFRIEN,SUBIENFR)))
98 .I '$D(ERROR) S OK=1
99 Q OK
100UPDATE(MRGTOIEN,FRDATA,MRGFRIEN) ;
101 Q:('MRGTOIEN)!(FRDATA="") "0^RECORD NOT UPDATED - BAD INPUT DATA"
102 N DIERR,IENS,FDA,MSGROOT,IENROOT,NAMEFR,NAMETO
103 S IENS="+1,"_MRGTOIEN_","
104 S FDA(408.1275,IENS,.01)=$P(FRDATA,"^")
105 S FDA(408.1275,IENS,.02)=$P(FRDATA,"^",2)
106 S FDA(408.1275,IENS,.03)=$P(FRDATA,"^",3)
107 S FDA(408.1275,IENS,.04)=$P(FRDATA,"^",4)
108 S NAMEFR=$G(^TMP($J,"EASXDR1","FR",MRGFRIEN,"NAME"))
109 I NAMEFR="" S NAMEFR=$$GET1^DIQ(408.12,MRGFRIEN_",",.03,"E")
110 S NAMETO=$G(^TMP($J,"EASXDR1","TO",MRGTOIEN,"NAME"))
111 I NAMETO="" S NAMEFR=$$GET1^DIQ(408.12,MRGTOIEN_",",.03,"E")
112 D UPDATE^DIE("","FDA","IENROOT","MSGROOT")
113 I '$D(DIERR) D Q "1^UPDATED "_$G(IENROOT)
114 .K @MRGROOT@("FR",RELATE,MRGFRIEN)
115 .K @MRGROOT@("TO",RELATE,MRGFRIEN)
116 .I $D(@MRGROOT@("TO",RELATE,MRGFRIEN)) K @MRGROOT@("TO",RELATE,MRGFRIEN)
117 .K ^TMP($J,"EASXDR")
118 .M ^TMP($J,"EASXDR","MRGFR",MRGFRIEN)=^DGPR(408.12,MRGFRIEN)
119 .M ^TMP($J,"EASXDR","MRGTO",MRGTOIEN)=^DGPR(408.12,MRGTOIEN)
120 Q "0^"_$G(MSGROOT("DIERR",1,"TEXT",1))
121DEL(ROOT,IEN) ;delete entries
122 Q:'IEN "1^INVALID INPUT PARAMETER"
123 N DA,DIK,MSG,X,Y,FILE
124 S FILE=$TR($P(ROOT,"(",2),",")
125 S MSG="1^DELETE ERROR "_ROOT_IEN ;default to error condition
126 M ^XTMP("EASXDR1","DATA",DFNFR,FILE,IEN)=@(ROOT_IEN_")")
127 S DA=IEN,DIK=ROOT D ^DIK,IX^DIK S MSG="0^RECORD DELETED"
128 Q MSG
129MRGOTHR(MRGFRIEN,MRGTOIEN) ;
130 Q:('MRGFRIEN)!('MRGTOIEN) 0
131 N NAMEFR,NAMETO
132 S NAMEFR=$G(^TMP($J,"EASXDR1","FR",MRGFRIEN,"NAME"))
133 S NAMETO=$G(^TMP($J,"EASXDR1","TO",MRGTOIEN,"NAME"))
134 I NAMEFR=NAMETO Q 1 ;ok to proceed with dependent merge
135 Q 0 ;different dependent - do not merge entries.
136SUCCESS(MRGFRIEN,MRGTOIEN) ;display message when merge is successful
137 Q:('$D(MRGFRIEN))!('$D(MRGTOIEN))
138 S NAMEFR=$G(^TMP($J,"EASXDR1","FR",MRGFRIEN,"NAME"))
139 I NAMEFR="" S NAMEFR=$$GET1^DIQ(408.12,MRGFRIEN_",",.03,"E")
140 S NAMETO=$G(^TMP($J,"EASXDR1","TO",MRGTOIEN,"NAME"))
141 I NAMETO="" S NAMEFR=$$GET1^DIQ(408.12,MRGTOIEN_",",.03,"E")
142 W !!?2,MRGFRIEN," ",NAMEFR," was merged into ",MRGTOIEN," ",NAMETO
143 Q
144FAILED(MRGFRIEN,MRGTOIEN,MSG) ;display message when merge fails
145 Q:('$D(MRGFRIEN))!('$D(MRGTOIEN))!('$D(MSG))
146 N EFFDT1
147 S NAMEFR=$G(^TMP($J,"EASXDR1","FR",+MRGFRIEN,"NAME"))
148 I NAMEFR="" S NAMEFR=$$GET1^DIQ(408.12,MRGFRIEN_",",.03,"E")
149 S NAMETO=$G(^TMP($J,"EASXDR1","TO",+MRGTOIEN,"NAME"))
150 I NAMETO="" S NAMEFR=$$GET1^DIQ(408.12,MRGTOIEN_",",.03,"E")
151 W !!?2,MRGFRIEN," ",NAMEFR," could not be merged into ",MRGTOIEN," ",NAMETO,"."
152 W !?2,"Reason: ",$G(MSG)
153 S EFFDT1=$G(EFFDT)
154 I MSG["'Active' flag does not match" D
155 .D CHGACT^EASXDR(MRGFRIEN,MRGTOIEN,$G(EFFDT))
156 .S EFFDT=EFFDT1
157 .K ^TMP($J,"EASXDR1","FR",RELATE,MRGTOIEN)
158 Q
159REMOVE(MRGFRIEN,MRGTOIEN) ;delete and/or repoint "old" entries
160 Q:('MRGFRIEN) "0^RECORD NOT DELETED - BAD INPUT DATA"
161 I '$D(MRGTOIEN) N MRGTOIEN S MRGTOIEN="***DELETE***"
162 I '$D(DFNFR) N DFNFR S DFNFR="DELETE" ;from DFN is not present
163 N VARPNT,MSG22,MSG21,ERROR,IEN40821,IEN40822,IEN40812,IEN40813
164 N MSG12,MSG13,VARPNT2
165 S IEN40812=MRGFRIEN
166 S IEN40821=""
167 S ^XTMP("EASXDR1","DATA",DFNFR,408.12,MRGFRIEN)=$S(MRGTOIEN:"RECORD MERGED INTO 408.12 IEN # "_MRGTOIEN,1:"RECORD DELETED")
168 F S IEN40821=$O(^DGMT(408.21,"C",IEN40812,IEN40821)) Q:'IEN40821!($G(ERROR)) D
169 .S IEN40822=""
170 .F S IEN40822=$O(^DGMT(408.22,"AIND",IEN40821,IEN40822)) Q:'IEN40822!($G(ERROR)) D
171 ..S MSG22=$$DEL("^DGMT(408.22,",IEN40822)
172 ..I MSG22 S ERROR="1^"_IEN40822_"^"_$P(MSG22,"^",2)_"^408.22 DELETE" Q
173 ..I DFNFR="DELETE" S ^XTMP("EASXDR1","DATA",DFNFR,408.12,MRGFRIEN,"SEE 408.22",IEN40822)=""
174 .Q:$G(ERROR)
175 .S MSG21=$$DEL("^DGMT(408.21,",IEN40821)
176 .I MSG21 S ERROR="1^"_IEN40821_"^"_$P(MSG21,"^",2)_"^408.21 DELETE" Q
177 .I DFNFR="DELETE" S ^XTMP("EASXDR1","DATA",DFNFR,408.12,MRGFRIEN,"SEE 408.21",IEN40821)=""
178 Q:$G(ERROR) "0^"_$P(ERROR,"^",2,4)
179 S VARPNT=$P($G(^DGPR(408.12,IEN40812,0)),"^",3)
180 S IEN40813="" S:VARPNT["DGPR" IEN40813=$P(VARPNT,";")
181 S MSG12=$$DEL("^DGPR(408.12,",IEN40812)
182 I MSG12 Q "0^"_IEN40812_"^"_$P(MSG12,"^",2)_"^408.12 DELETE"
183 Q:'IEN40813 "1^"_MRGFRIEN_" DELETED"
184 S VARPNT2=""
185 ;ensure that the new record is not pointing to the same relation
186 S:MRGTOIEN VARPNT2=$P($G(^DGPR(408.12,MRGTOIEN,0)),"^",3)
187 Q:VARPNT=VARPNT2 "1^"_MRGFRIEN_" DELETED"
188 S MSG13=$$DEL("^DGPR(408.13,",IEN40813)
189 I DFNFR="DELETE" S ^XTMP("EASXDR1","DATA",DFNFR,408.12,MRGFRIEN,"SEE 408.13",IEN40813)=""
190 Q:MSG13 "0^"_$P(MSG13,"^",2)
191 Q "1^"_MRGFRIEN_" DELETED"
192SSNMATCH(FRIEN,TOIEN) ;
193 N SSNFR,SSNTO
194 D FINDSSN^EASXDR(FRIEN,.SSNFR),FINDSSN^EASXDR(TOIEN,.SSNTO)
195 Q:SSNFR=SSNTO 1 ;SSNs match
196 Q:(SSNFR="UNKNOWN")!(SSNFR="") 1 ;use SSN of the 'merge to' record
197 Q 0
Note: See TracBrowser for help on using the repository browser.