| 1 | PXRMMST ; SLC/PKR - Routines for dealing with MST. ;03/29/2007 | 
|---|
| 2 | ;;2.0;CLINICAL REMINDERS;**4,6**;Feb 04, 2005;Build 123 | 
|---|
| 3 | ;Use of DGMSTAPI supported by DBIA #2716. | 
|---|
| 4 | ;==================================================== | 
|---|
| 5 | GSYINFO(TYPE) ;Return the Clinical Reminders MST synchronization date | 
|---|
| 6 | ;and the number of updates made. The format is an up-arrow delimited | 
|---|
| 7 | ;string. The first piece is the date and the second is the number | 
|---|
| 8 | ;of updates. If TYPE is "I" then the data for the initial | 
|---|
| 9 | ;synchronization is returned. For any other value the data for the | 
|---|
| 10 | ;last daily synchronization is returned. | 
|---|
| 11 | I $G(TYPE)="I" Q $P($G(^PXRM(800,1,"MST")),U,1,2) Q | 
|---|
| 12 | Q $P($G(^PXRM(800,1,"MST")),U,3,4) | 
|---|
| 13 | ; | 
|---|
| 14 | ;==================================================== | 
|---|
| 15 | QUE ;Queue the MST synchronization job. | 
|---|
| 16 | N DIR,DIROUT,DIRUT,DTOUT,DUOUT,MINDT,SDTIME,STIME,X,Y | 
|---|
| 17 | S MINDT=$$NOW^XLFDT | 
|---|
| 18 | W !,"Queue the Clinical Reminders MST synchronization." | 
|---|
| 19 | S DIR("A",1)="Enter the date and time you want the job to start." | 
|---|
| 20 | S DIR("A",2)="It must be after "_$$FMTE^XLFDT(MINDT,"5Z") | 
|---|
| 21 | S DIR("A")="Start the task at: " | 
|---|
| 22 | S DIR(0)="DAU"_U_MINDT_"::RSX" | 
|---|
| 23 | D ^DIR | 
|---|
| 24 | I $D(DIROUT)!$D(DIRUT) Q | 
|---|
| 25 | I $D(DTOUT)!$D(DUOUT) Q | 
|---|
| 26 | S SDTIME=Y | 
|---|
| 27 | K DIR | 
|---|
| 28 | S DIR(0)="YA" | 
|---|
| 29 | S DIR("A")="Do you want to run the MST synchronization at the same time every day? " | 
|---|
| 30 | S DIR("B")="Y" | 
|---|
| 31 | D ^DIR | 
|---|
| 32 | I $D(DIROUT)!$D(DIRUT) Q | 
|---|
| 33 | I $D(DTOUT)!$D(DUOUT) Q | 
|---|
| 34 | S STIME=$S(Y:"1."_$P(SDTIME,".",2),1:-1) | 
|---|
| 35 | ; | 
|---|
| 36 | ;Put the task into the queue. | 
|---|
| 37 | K ZTSAVE | 
|---|
| 38 | S ZTSAVE("STIME")=STIME | 
|---|
| 39 | S ZTRTN="SYNCH^PXRMMST" | 
|---|
| 40 | S ZTDESC="Clinical Reminders MST synchronization job" | 
|---|
| 41 | S ZTDTH=SDTIME | 
|---|
| 42 | S ZTIO="" | 
|---|
| 43 | D ^%ZTLOAD | 
|---|
| 44 | W !,"Task number ",ZTSK," queued." | 
|---|
| 45 | Q | 
|---|
| 46 | ; | 
|---|
| 47 | ;==================================================== | 
|---|
| 48 | STATUS(DFN,TEST,DATE,VALUE,TEXT) ;Computed finding for checking a | 
|---|
| 49 | ;patient's MST status. | 
|---|
| 50 | N IEN,TEMP | 
|---|
| 51 | S TEMP=$$GETSTAT^DGMSTAPI(DFN) | 
|---|
| 52 | S IEN=$P(TEMP,U,1) | 
|---|
| 53 | I IEN=-1 D  Q | 
|---|
| 54 | . S TEST=0,VALUE="",DATE=$$NOW^PXRMDATE | 
|---|
| 55 | I IEN=0 D  Q | 
|---|
| 56 | . S TEST=0 | 
|---|
| 57 | . S VALUE=$P(TEMP,U,2) | 
|---|
| 58 | . S DATE=$P(TEMP,U,3) | 
|---|
| 59 | . S TEXT="No MST status found" | 
|---|
| 60 | ;If we get to here then a valid entry was found. | 
|---|
| 61 | S TEST=1 | 
|---|
| 62 | S VALUE=$P(TEMP,U,2) | 
|---|
| 63 | S DATE=$P(TEMP,U,3) | 
|---|
| 64 | Q | 
|---|
| 65 | ; | 
|---|
| 66 | ;==================================================== | 
|---|
| 67 | STCODE(TERM) ;Return the MST status code based on the term name. | 
|---|
| 68 | N STCODE | 
|---|
| 69 | S STCODE=$S(TERM="VA-MST DECLINES REPORT":"D",TERM="VA-MST NEGATIVE REPORT":"N",TERM="VA-MST POSITIVE REPORT":"Y",1:"U") | 
|---|
| 70 | Q STCODE | 
|---|
| 71 | ; | 
|---|
| 72 | ;==================================================== | 
|---|
| 73 | SYNCH ;Synchronize the MST history file. | 
|---|
| 74 | N INID,LTIME,NUMUPD,START,TEMP | 
|---|
| 75 | ;STIME is passed from QUE via ZTSAVE. | 
|---|
| 76 | D UPDSTAT(.NUMUPD,.START) | 
|---|
| 77 | ;If the initial sync data has been stored then update the daily | 
|---|
| 78 | ;data. | 
|---|
| 79 | S INID=+$P($G(^PXRM(800,1,"MST")),U,1) | 
|---|
| 80 | I INID>0 D | 
|---|
| 81 | . S $P(^PXRM(800,1,"MST"),U,3)=$$NOW^XLFDT | 
|---|
| 82 | . S $P(^PXRM(800,1,"MST"),U,4)=NUMUPD | 
|---|
| 83 | . S $P(^PXRM(800,1,"MST"),U,6)=START | 
|---|
| 84 | E  D | 
|---|
| 85 | . S $P(^PXRM(800,1,"MST"),U,1)=$$NOW^XLFDT | 
|---|
| 86 | . S $P(^PXRM(800,1,"MST"),U,2)=NUMUPD | 
|---|
| 87 | . S $P(^PXRM(800,1,"MST"),U,5)=START | 
|---|
| 88 | ; | 
|---|
| 89 | ;Cleanup the task stuff. | 
|---|
| 90 | I STIME=-1 S ZTREQ="@" Q | 
|---|
| 91 | E  D | 
|---|
| 92 | . S TEMP=$G(^PXRM(800,1,"MST")) | 
|---|
| 93 | . S LTIME=+$P(TEMP,U,3) | 
|---|
| 94 | . I LTIME=0 S LTIME=+$P(TEMP,U,1) | 
|---|
| 95 | .;Adding STIME sets the new starting time at exactly one day following | 
|---|
| 96 | .;the previous starting time. | 
|---|
| 97 | . S $P(ZTREQ,U,1)=$P(LTIME,".",1)+STIME | 
|---|
| 98 | Q | 
|---|
| 99 | ; | 
|---|
| 100 | ;==================================================== | 
|---|
| 101 | SYNREP ;Provide a report of the synchronization data. | 
|---|
| 102 | N EDTIME,EITIME,IDATE,LDATE,NIUPD,NLUPD,TEMP | 
|---|
| 103 | S TEMP=$G(^PXRM(800,1,"MST")) | 
|---|
| 104 | S IDATE=$$FMTE^XLFDT($P(TEMP,U,1)) | 
|---|
| 105 | I IDATE=0 S IDATE="none" | 
|---|
| 106 | S NIUPD=$P(TEMP,U,2) | 
|---|
| 107 | S EITIME=$$FMDIFF^XLFDT($P(TEMP,U,1),$P(TEMP,U,5),2) | 
|---|
| 108 | S LDATE=$$FMTE^XLFDT($P(TEMP,U,3)) | 
|---|
| 109 | I LDATE=0 S LDATE="none" | 
|---|
| 110 | S NLUPD=$P(TEMP,U,4) | 
|---|
| 111 | S EDTIME=$$FMDIFF^XLFDT($P(TEMP,U,3),$P(TEMP,U,6),2) | 
|---|
| 112 | W !!,"Clinical Reminders MST Synchronization Report" | 
|---|
| 113 | W !,"---------------------------------------------" | 
|---|
| 114 | W !,"Initial synchronization date: ",IDATE | 
|---|
| 115 | W !,"Number of updates made: ",NIUPD | 
|---|
| 116 | I EITIME>60 D | 
|---|
| 117 | . S EITIME=$$FMDIFF^XLFDT($P(TEMP,U,1),$P(TEMP,U,5),3) | 
|---|
| 118 | . W !,"Elapsed time: ",EITIME | 
|---|
| 119 | E  W !,"Elapsed time: ",EITIME," secs" | 
|---|
| 120 | W !!,"Last daily synchronization date: ",LDATE | 
|---|
| 121 | W !,"Number of updates made: ",NLUPD | 
|---|
| 122 | I EDTIME>60 D | 
|---|
| 123 | . S EDTIME=$$FMDIFF^XLFDT($P(TEMP,U,3),$P(TEMP,U,6),3) | 
|---|
| 124 | . W !,"Elapsed time: ",EDTIME | 
|---|
| 125 | E  W !,"Elapsed time: ",EDTIME," secs" | 
|---|
| 126 | Q | 
|---|
| 127 | ; | 
|---|
| 128 | ;==================================================== | 
|---|
| 129 | UPDATE(DFN,VISIT,SOURCE,STCODE,TYPE) ;Make an update to the MST History file. | 
|---|
| 130 | N DATE,MSTDATE,PROV,STAT,TEMP,UPDSTAT,VPRVIEN | 
|---|
| 131 | S UPDSTAT=-1 | 
|---|
| 132 | ;If the update is because of a protocol event use NOW for the | 
|---|
| 133 | ;date/time. If it is being done as part of a synchronization use | 
|---|
| 134 | ;the date the visit was created. | 
|---|
| 135 | S DATE=$S(TYPE="PROTOCOL":$$NOW^XLFDT,1:$P($G(^AUPNVSIT(VISIT,0)),U,2)) | 
|---|
| 136 | ;If the date does not contain the time use noon. | 
|---|
| 137 | I DATE'["." S DATE=DATE_".12" | 
|---|
| 138 | S STAT=$$GETSTAT^DGMSTAPI(DFN) | 
|---|
| 139 | S MSTDATE=$S($P(STAT,U,1)>0:$P(STAT,U,3),1:0) | 
|---|
| 140 | I DATE>MSTDATE D | 
|---|
| 141 | .;Determine the provider. | 
|---|
| 142 | . S TEMP=$P(SOURCE,";",2)_$P(SOURCE,";",1)_",12)" | 
|---|
| 143 | . S PROV=$P($G(@TEMP),U,4) | 
|---|
| 144 | . I PROV="" D | 
|---|
| 145 | ..;DBIA #2316 | 
|---|
| 146 | .. S VPRVIEN=+$O(^AUPNVPRV("AD",VISIT,"")) | 
|---|
| 147 | .. I VPRVIEN>0 S PROV=$P(^AUPNVPRV(VPRVIEN,0),U,1) | 
|---|
| 148 | . S UPDSTAT=$$NEWSTAT^DGMSTAPI(DFN,STCODE,DATE,PROV) | 
|---|
| 149 | . I +UPDSTAT=-1 D | 
|---|
| 150 | .. N FN,GBL,IEN,NAME,TARGET,XMSUB,VADM | 
|---|
| 151 | .. K ^TMP("PXRMXMZ",$J) | 
|---|
| 152 | .. S XMSUB="CLINICAL REMINDER MST UPDATE PROBLEM" | 
|---|
| 153 | .. S ^TMP("PXRMXMZ",$J,1,0)="NEWSTAT^DGMSTAPI returned the following error:" | 
|---|
| 154 | .. S ^TMP("PXRMXMZ",$J,2,0)=$P(UPDSTAT,U,2) | 
|---|
| 155 | .. S ^TMP("PXRMXMZ",$J,3,0)="The following data was passed to NEWSTAT^DGMSTAPI" | 
|---|
| 156 | .. S ^TMP("PXRMXMZ",$J,4,0)="DFN = "_DFN | 
|---|
| 157 | .. S ^TMP("PXRMXMZ",$J,5,0)="Status code = "_STCODE | 
|---|
| 158 | .. S ^TMP("PXRMXMZ",$J,6,0)="Date = "_DATE | 
|---|
| 159 | .. S ^TMP("PXRMXMZ",$J,7,0)="Provider = "_PROV | 
|---|
| 160 | .. S ^TMP("PXRMXMZ",$J,8,0)="Data source = "_SOURCE | 
|---|
| 161 | .. S ^TMP("PXRMXMZ",$J,9,0)="This corresponds to the following:" | 
|---|
| 162 | .. D DEM^VADPT | 
|---|
| 163 | .. S ^TMP("PXRMXMZ",$J,10,0)="Patient = "_VADM(1) | 
|---|
| 164 | .. S ^TMP("PXRMXMZ",$J,11,0)="SSN = "_$P(VADM(2),U,2) | 
|---|
| 165 | .. S ^TMP("PXRMXMZ",$J,12,0)="MST Status = "_$$EXTERNAL^DILFD(29.11,3,"",STCODE) | 
|---|
| 166 | .. S ^TMP("PXRMXMZ",$J,13,0)="Date = "_$$FMTE^XLFDT(DATE,"5Z") | 
|---|
| 167 | .. S TEMP=$S(PROV="":"Unknown",1:TEMP=$$GET1^DIQ(200,PROV,.01,"","","")) | 
|---|
| 168 | .. I TEMP="" S TEMP="Unknown" | 
|---|
| 169 | .. S ^TMP("PXRMXMZ",$J,14,0)="Provider = "_TEMP | 
|---|
| 170 | .. S GBL=$P($P(SOURCE,";",2),"(",1) | 
|---|
| 171 | .. S TEMP=GBL_"(0)" | 
|---|
| 172 | .. S FN=+$P(@TEMP,U,2) | 
|---|
| 173 | .. S TEMP=GBL_"("_$P(SOURCE,";",1)_",0)" | 
|---|
| 174 | .. S TEMP=$G(@TEMP) | 
|---|
| 175 | .. S IEN=$P(TEMP,U,1) | 
|---|
| 176 | .. D FIELD^DID(FN,.01,"N","POINTER","TARGET") | 
|---|
| 177 | .. S GBL="^"_$P(TARGET("POINTER"),"(",1) | 
|---|
| 178 | .. S TEMP=GBL_"(0)" | 
|---|
| 179 | .. S FN=$P(@TEMP,U,1) | 
|---|
| 180 | .. S TEMP=GBL_"("_IEN_",0)" | 
|---|
| 181 | .. S NAME=$P(@TEMP,U,1) | 
|---|
| 182 | .. S ^TMP("PXRMXMZ",$J,14,0)="Data type = "_FN | 
|---|
| 183 | .. S ^TMP("PXRMXMZ",$J,15,0)="Name = "_NAME | 
|---|
| 184 | .. D SEND^PXRMMSG(XMSUB) | 
|---|
| 185 | Q UPDSTAT | 
|---|
| 186 | ; | 
|---|
| 187 | ;==================================================== | 
|---|
| 188 | UPDPAT(DFN,VISIT,VFL) ;Update the MST history file for a single patient | 
|---|
| 189 | ;using term mappings. Called from DATACHG^PXRMPINF which is invoked | 
|---|
| 190 | ;by the protocol PXK VISIT DATA EVENT. | 
|---|
| 191 | N AFTER,BEFORE,DGBL,SP,STCODE,SIEN,SOURCE | 
|---|
| 192 | N TEMP,TERM,TERMIEN,VF | 
|---|
| 193 | ;Search all the MST terms to build patient lists. | 
|---|
| 194 | F TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT" D | 
|---|
| 195 | . S TERMIEN=$O(^PXRMD(811.5,"B",TERM,"")) | 
|---|
| 196 | . S VF="" | 
|---|
| 197 | . F  S VF=$O(VFL(VF)) Q:VF=""  D | 
|---|
| 198 | .. I VFL(VF)=U Q | 
|---|
| 199 | .. S DGBL=$P(VFL(VF),U,1) | 
|---|
| 200 | .. I '$D(^PXRMD(811.5,TERMIEN,20,"E",DGBL)) Q | 
|---|
| 201 | .. S SIEN="" | 
|---|
| 202 | .. F  S SIEN=$O(^TMP("PXKCO",$J,VISIT,VF,SIEN)) Q:SIEN=""  D | 
|---|
| 203 | ... S AFTER=$G(^TMP("PXKCO",$J,VISIT,VF,SIEN,0,"AFTER")) | 
|---|
| 204 | ... S BEFORE=$G(^TMP("PXKCO",$J,VISIT,VF,SIEN,0,"BEFORE")) | 
|---|
| 205 | ... I AFTER=BEFORE Q | 
|---|
| 206 | ... S SP=$P(AFTER,U,1) | 
|---|
| 207 | ... I SP="" Q | 
|---|
| 208 | ... I '$D(^PXRMD(811.5,TERMIEN,20,"E",DGBL,SP)) Q | 
|---|
| 209 | ... S SOURCE=SIEN_";^"_$P(VFL(VF),U,2) | 
|---|
| 210 | ...;The status code depends on the term name. | 
|---|
| 211 | ... S STCODE=$$STCODE(TERM) | 
|---|
| 212 | ... S TEMP=$$UPDATE(DFN,VISIT,SOURCE,STCODE,"PROTOCOL") | 
|---|
| 213 | Q | 
|---|
| 214 | ; | 
|---|
| 215 | ;==================================================== | 
|---|
| 216 | UPDSTAT(NUMUPD,START) ;Update the MST history file using term mappings. | 
|---|
| 217 | N DAS,DATA,DFN,FILENUM,FINDPA,INDEX,ITEM,NOCC,STCODE,SOURCE | 
|---|
| 218 | N TEMP,TERM,TERMARR,TERMIEN,UPDSTAT,VDATE,VISIT | 
|---|
| 219 | S FINDPA="" | 
|---|
| 220 | ;Set the start time for the synchronization. | 
|---|
| 221 | S START=$$NOW^XLFDT | 
|---|
| 222 | S INDEX="PXRM_MST_LIST" | 
|---|
| 223 | S NUMUPD=0 | 
|---|
| 224 | ;Search all the MST terms to build patient lists. Only V file data | 
|---|
| 225 | ;is used for the update. | 
|---|
| 226 | F TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT" D | 
|---|
| 227 | . K TERMARR,^TMP($J,INDEX) | 
|---|
| 228 | .;The status code depends on the term name. | 
|---|
| 229 | . S STCODE=$$STCODE(TERM) | 
|---|
| 230 | . S TERMIEN=$O(^PXRMD(811.5,"B",TERM,"")) | 
|---|
| 231 | . I TERMIEN="" Q | 
|---|
| 232 | . D TERM^PXRMLDR(TERMIEN,.TERMARR) | 
|---|
| 233 | . D EVALPL^PXRMTERL(.FINDPA,.TERMARR,INDEX) | 
|---|
| 234 | . S DFN=0 | 
|---|
| 235 | . F  S DFN=+$O(^TMP($J,INDEX,1,DFN)) Q:DFN=0  D | 
|---|
| 236 | .. S ITEM="" | 
|---|
| 237 | .. F  S ITEM=$O(^TMP($J,INDEX,1,DFN,ITEM)) Q:ITEM=""  D | 
|---|
| 238 | ... S NOCC=0 | 
|---|
| 239 | ... F  S NOCC=$O(^TMP($J,INDEX,1,DFN,ITEM,NOCC)) Q:NOCC=""  D | 
|---|
| 240 | .... S FILENUM="" | 
|---|
| 241 | .... F  S FILENUM=$O(^TMP($J,INDEX,1,DFN,ITEM,NOCC,FILENUM)) Q:FILENUM=""  D | 
|---|
| 242 | ..... S TEMP=^TMP($J,INDEX,1,DFN,ITEM,NOCC,FILENUM) | 
|---|
| 243 | ..... S DAS=$P(TEMP,U,1) | 
|---|
| 244 | ..... K DATA | 
|---|
| 245 | ..... D GETDATA^PXRMDATA(FILENUM,DAS,.DATA) | 
|---|
| 246 | ..... S VISIT=$G(DATA("VISIT")) | 
|---|
| 247 | ..... I VISIT="" Q | 
|---|
| 248 | ..... S SOURCE=DAS_";"_^PXRMINDX(FILENUM,"GLOBAL NAME") | 
|---|
| 249 | ..... S UPDSTAT=$$UPDATE(DFN,VISIT,SOURCE,STCODE,"SYNCH") | 
|---|
| 250 | ..... I UPDSTAT'=-1 S NUMUPD=NUMUPD+1 | 
|---|
| 251 | K ^TMP($J,INDEX) | 
|---|
| 252 | Q | 
|---|
| 253 | ; | 
|---|