PXRMMST ;SLC/PKR - Routines for dealing with MST. ;07/29/2010
;;2.0;CLINICAL REMINDERS;**4,6,17,18**;Feb 04, 2005;Build 152
;Use of DGMSTAPI supported by DBIA #2716.
;====================================================
GSYINFO(TYPE) ;Return the Clinical Reminders MST synchronization date
;and the number of updates made. The format is an up-arrow delimited
;string. The first piece is the date and the second is the number
;of updates. If TYPE is "I" then the data for the initial
;synchronization is returned. For any other value the data for the
;last daily synchronization is returned.
I $G(TYPE)="I" Q $P($G(^PXRM(800,1,"MST")),U,1,2) Q
Q $P($G(^PXRM(800,1,"MST")),U,3,4)
;
;====================================================
QUE ;Queue the MST synchronization job.
N DIR,DIROUT,DIRUT,DTOUT,DUOUT,MINDT,SDTIME,STIME,X,Y
S MINDT=$$NOW^XLFDT
W !,"Queue the Clinical Reminders MST synchronization."
S DIR("A",1)="Enter the date and time you want the job to start."
S DIR("A",2)="It must be after "_$$FMTE^XLFDT(MINDT,"5Z")
S DIR("A")="Start the task at: "
S DIR(0)="DAU"_U_MINDT_"::RSX"
D ^DIR
I $D(DIROUT)!$D(DIRUT) Q
I $D(DTOUT)!$D(DUOUT) Q
S SDTIME=Y
K DIR
S DIR(0)="YA"
S DIR("A")="Do you want to run the MST synchronization at the same time every day? "
S DIR("B")="Y"
D ^DIR
I $D(DIROUT)!$D(DIRUT) Q
I $D(DTOUT)!$D(DUOUT) Q
S STIME=$S(Y:"1."_$P(SDTIME,".",2),1:-1)
;
;Put the task into the queue.
K ZTSAVE
S ZTSAVE("STIME")=STIME
S ZTRTN="SYNCH^PXRMMST"
S ZTDESC="Clinical Reminders MST synchronization job"
S ZTDTH=SDTIME
S ZTIO=""
D ^%ZTLOAD
W !,"Task number ",ZTSK," queued."
Q
;
;====================================================
STATUS(DFN,TEST,DATE,VALUE,TEXT) ;Computed finding for checking a
;patient's MST status.
N IEN,TEMP
S TEMP=$$GETSTAT^DGMSTAPI(DFN)
S IEN=$P(TEMP,U,1)
I IEN=-1 D Q
. S TEST=0,VALUE="",DATE=$$NOW^PXRMDATE
I IEN=0 D Q
. S TEST=0
. S VALUE=$P(TEMP,U,2)
. S DATE=$P(TEMP,U,3)
. S TEXT="No MST status found"
;If we get to here then a valid entry was found.
S TEST=1
S VALUE=$P(TEMP,U,2)
S DATE=$P(TEMP,U,3)
Q
;
;====================================================
STCODE(TERM) ;Return the MST status code based on the term name.
N STCODE
S STCODE=$S(TERM="VA-MST DECLINES REPORT":"D",TERM="VA-MST NEGATIVE REPORT":"N",TERM="VA-MST POSITIVE REPORT":"Y",1:"U")
Q STCODE
;
;====================================================
SYNCH ;Synchronize the MST history file.
N INID,LTIME,NUMUPD,START,TEMP
;STIME is passed from QUE via ZTSAVE.
D UPDSTAT(.NUMUPD,.START)
;If the initial sync data has been stored then update the daily
;data.
S INID=+$P($G(^PXRM(800,1,"MST")),U,1)
I INID>0 D
. S $P(^PXRM(800,1,"MST"),U,3)=$$NOW^XLFDT
. S $P(^PXRM(800,1,"MST"),U,4)=NUMUPD
. S $P(^PXRM(800,1,"MST"),U,6)=START
E D
. S $P(^PXRM(800,1,"MST"),U,1)=$$NOW^XLFDT
. S $P(^PXRM(800,1,"MST"),U,2)=NUMUPD
. S $P(^PXRM(800,1,"MST"),U,5)=START
;
;Cleanup the task stuff.
I STIME=-1 S ZTREQ="@" Q
E D
. S TEMP=$G(^PXRM(800,1,"MST"))
. S LTIME=+$P(TEMP,U,3)
. I LTIME=0 S LTIME=+$P(TEMP,U,1)
.;Adding STIME sets the new starting time at exactly one day following
.;the previous starting time.
. S $P(ZTREQ,U,1)=$P(LTIME,".",1)+STIME
Q
;
;====================================================
SYNREP ;Provide a report of the synchronization data.
N EDTIME,EITIME,IDATE,LDATE,NIUPD,NLUPD,TEMP
S TEMP=$G(^PXRM(800,1,"MST"))
S IDATE=$$FMTE^XLFDT($P(TEMP,U,1))
I IDATE=0 S IDATE="none"
S NIUPD=$P(TEMP,U,2)
S EITIME=$$FMDIFF^XLFDT($P(TEMP,U,1),$P(TEMP,U,5),2)
S LDATE=$$FMTE^XLFDT($P(TEMP,U,3))
I LDATE=0 S LDATE="none"
S NLUPD=$P(TEMP,U,4)
S EDTIME=$$FMDIFF^XLFDT($P(TEMP,U,3),$P(TEMP,U,6),2)
W !!,"Clinical Reminders MST Synchronization Report"
W !,"---------------------------------------------"
W !,"Initial synchronization date: ",IDATE
W !,"Number of updates made: ",NIUPD
I EITIME>60 D
. S EITIME=$$FMDIFF^XLFDT($P(TEMP,U,1),$P(TEMP,U,5),3)
. W !,"Elapsed time: ",EITIME
E W !,"Elapsed time: ",EITIME," secs"
W !!,"Last daily synchronization date: ",LDATE
W !,"Number of updates made: ",NLUPD
I EDTIME>60 D
. S EDTIME=$$FMDIFF^XLFDT($P(TEMP,U,3),$P(TEMP,U,6),3)
. W !,"Elapsed time: ",EDTIME
E W !,"Elapsed time: ",EDTIME," secs"
Q
;
;====================================================
UPDATE(DFN,VISIT,SOURCE,STCODE,TYPE) ;Make an update to the MST History file.
N DATE,MSTDATE,PROV,STAT,TEMP,UPDSTAT,VPRVIEN
S UPDSTAT=-1
;If the update is because of a protocol event use NOW for the
;date/time. If it is being done as part of a synchronization use
;the date the visit was created.
S DATE=$S(TYPE="PROTOCOL":$$NOW^XLFDT,1:$P($G(^AUPNVSIT(VISIT,0)),U,2))
;If the date does not contain the time use noon.
I DATE'["." S DATE=DATE_".12"
S STAT=$$GETSTAT^DGMSTAPI(DFN)
S MSTDATE=$S($P(STAT,U,1)>0:$P(STAT,U,3),1:0)
I DATE>MSTDATE D
.;Determine the provider.
. S TEMP=$P(SOURCE,";",2)_$P(SOURCE,";",1)_",12)"
. S PROV=$P($G(@TEMP),U,4)
. I PROV="" D
..;DBIA #2316
.. S VPRVIEN=+$O(^AUPNVPRV("AD",VISIT,""))
.. I VPRVIEN>0 S PROV=$P(^AUPNVPRV(VPRVIEN,0),U,1)
. S UPDSTAT=$$NEWSTAT^DGMSTAPI(DFN,STCODE,DATE,PROV)
. I +UPDSTAT=-1 D
.. N FN,GBL,IEN,NAME,TARGET,XMSUB,VADM
.. K ^TMP("PXRMXMZ",$J)
.. S XMSUB="CLINICAL REMINDER MST UPDATE PROBLEM"
.. S ^TMP("PXRMXMZ",$J,1,0)="NEWSTAT^DGMSTAPI returned the following error:"
.. S ^TMP("PXRMXMZ",$J,2,0)=$P(UPDSTAT,U,2)
.. S ^TMP("PXRMXMZ",$J,3,0)="The following data was passed to NEWSTAT^DGMSTAPI"
.. S ^TMP("PXRMXMZ",$J,4,0)="DFN = "_DFN
.. S ^TMP("PXRMXMZ",$J,5,0)="Status code = "_STCODE
.. S ^TMP("PXRMXMZ",$J,6,0)="Date = "_DATE
.. S ^TMP("PXRMXMZ",$J,7,0)="Provider = "_PROV
.. S ^TMP("PXRMXMZ",$J,8,0)="Data source = "_SOURCE
.. S ^TMP("PXRMXMZ",$J,9,0)="This corresponds to the following:"
.. D DEM^VADPT
.. S ^TMP("PXRMXMZ",$J,10,0)="Patient = "_VADM(1)
.. S ^TMP("PXRMXMZ",$J,11,0)="SSN = "_$P(VADM(2),U,2)
.. S ^TMP("PXRMXMZ",$J,12,0)="MST Status = "_$$EXTERNAL^DILFD(29.11,3,"",STCODE)
.. S ^TMP("PXRMXMZ",$J,13,0)="Date = "_$$FMTE^XLFDT(DATE,"5Z")
.. S TEMP=$S(PROV="":"Unknown",1:TEMP=$$GET1^DIQ(200,PROV,.01,"","",""))
.. I TEMP="" S TEMP="Unknown"
.. S ^TMP("PXRMXMZ",$J,14,0)="Provider = "_TEMP
.. S GBL=$P($P(SOURCE,";",2),"(",1)
.. S TEMP=GBL_"(0)"
.. S FN=+$P(@TEMP,U,2)
.. S TEMP=GBL_"("_$P(SOURCE,";",1)_",0)"
.. S TEMP=$G(@TEMP)
.. S IEN=$P(TEMP,U,1)
.. D FIELD^DID(FN,.01,"N","POINTER","TARGET")
.. S GBL="^"_$P(TARGET("POINTER"),"(",1)
.. S TEMP=GBL_"(0)"
.. S FN=$P(@TEMP,U,1)
.. S TEMP=GBL_"("_IEN_",0)"
.. S NAME=$P(@TEMP,U,1)
.. S ^TMP("PXRMXMZ",$J,14,0)="Data type = "_FN
.. S ^TMP("PXRMXMZ",$J,15,0)="Name = "_NAME
.. D SEND^PXRMMSG("PXRMXMZ",XMSUB,"",DUZ)
Q UPDSTAT
;
;====================================================
UPDPAT(EVENT,DFN,VISIT,VFL) ;Update the MST history file for a single patient
;using term mappings. Called from DATACHG^PXRMPINF which is invoked
;by the protocol PXK VISIT DATA EVENT.
N AFTER,BEFORE,DGBL,SP,STCODE,SIEN,SOURCE
N TEMP,TERM,TERMIEN,VF
;Search all the MST terms to build patient lists.
F TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT" D
. S TERMIEN=$O(^PXRMD(811.5,"B",TERM,""))
. S VF=""
. F S VF=$O(VFL(VF)) Q:VF="" D
.. I VFL(VF)=U Q
.. S DGBL=$P(VFL(VF),U,1)
.. I '$D(^PXRMD(811.5,TERMIEN,20,"E",DGBL)) Q
.. S SIEN=""
.. F S SIEN=$O(^XTMP(EVENT,VISIT,VF,SIEN)) Q:SIEN="" D
... S AFTER=$G(^XTMP(EVENT,VISIT,VF,SIEN,0,"AFTER"))
... S BEFORE=$G(^XTMP(EVENT,VISIT,VF,SIEN,0,"BEFORE"))
... I AFTER=BEFORE Q
... S SP=$P(AFTER,U,1)
... I SP="" Q
... I '$D(^PXRMD(811.5,TERMIEN,20,"E",DGBL,SP)) Q
... S SOURCE=SIEN_";^"_$P(VFL(VF),U,2)
...;The status code depends on the term name.
... S STCODE=$$STCODE^PXRMMST(TERM)
... S TEMP=$$UPDATE^PXRMMST(DFN,VISIT,SOURCE,STCODE,"PROTOCOL")
Q
;
;====================================================
UPDSTAT(NUMUPD,START) ;Update the MST history file using term mappings.
N DAS,DATA,DFN,FILENUM,FINDPA,INDEX,ITEM,NOCC,STCODE,SOURCE
N TEMP,TERM,TERMARR,TERMIEN,UPDSTAT,VDATE,VISIT
S FINDPA=""
;Set the start time for the synchronization.
S START=$$NOW^XLFDT
S INDEX="PXRM_MST_LIST"
S NUMUPD=0
;Search all the MST terms to build patient lists. Only V file data
;is used for the update.
F TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT" D
. K TERMARR,^TMP($J,INDEX)
.;The status code depends on the term name.
. S STCODE=$$STCODE(TERM)
. S TERMIEN=$O(^PXRMD(811.5,"B",TERM,""))
. I TERMIEN="" Q
. D TERM^PXRMLDR(TERMIEN,.TERMARR)
. D EVALPL^PXRMTERL(.FINDPA,.TERMARR,INDEX)
. S DFN=0
. F S DFN=+$O(^TMP($J,INDEX,1,DFN)) Q:DFN=0 D
.. S ITEM=""
.. F S ITEM=$O(^TMP($J,INDEX,1,DFN,ITEM)) Q:ITEM="" D
... S NOCC=0
... F S NOCC=$O(^TMP($J,INDEX,1,DFN,ITEM,NOCC)) Q:NOCC="" D
.... S FILENUM=""
.... F S FILENUM=$O(^TMP($J,INDEX,1,DFN,ITEM,NOCC,FILENUM)) Q:FILENUM="" D
..... S TEMP=^TMP($J,INDEX,1,DFN,ITEM,NOCC,FILENUM)
..... S DAS=$P(TEMP,U,1)
..... K DATA
..... D GETDATA^PXRMDATA(FILENUM,DAS,.DATA)
..... S VISIT=$G(DATA("VISIT"))
..... I VISIT="" Q
..... S SOURCE=DAS_";"_^PXRMINDX(FILENUM,"GLOBAL NAME")
..... S UPDSTAT=$$UPDATE(DFN,VISIT,SOURCE,STCODE,"SYNCH")
..... I UPDSTAT'=-1 S NUMUPD=NUMUPD+1
K ^TMP($J,INDEX)
Q
;
PXRMMST ;SLC/PKR - Routines for dealing with MST. ;07/29/2010
+1 ;;2.0;CLINICAL REMINDERS;**4,6,17,18**;Feb 04, 2005;Build 152
+2 ;Use of DGMSTAPI supported by DBIA #2716.
+3 ;====================================================
GSYINFO(TYPE) ;Return the Clinical Reminders MST synchronization date
+1 ;and the number of updates made. The format is an up-arrow delimited
+2 ;string. The first piece is the date and the second is the number
+3 ;of updates. If TYPE is "I" then the data for the initial
+4 ;synchronization is returned. For any other value the data for the
+5 ;last daily synchronization is returned.
+6 IF $GET(TYPE)="I"
QUIT $PIECE($GET(^PXRM(800,1,"MST")),U,1,2)
QUIT
+7 QUIT $PIECE($GET(^PXRM(800,1,"MST")),U,3,4)
+8 ;
+9 ;====================================================
QUE ;Queue the MST synchronization job.
+1 NEW DIR,DIROUT,DIRUT,DTOUT,DUOUT,MINDT,SDTIME,STIME,X,Y
+2 SET MINDT=$$NOW^XLFDT
+3 WRITE !,"Queue the Clinical Reminders MST synchronization."
+4 SET DIR("A",1)="Enter the date and time you want the job to start."
+5 SET DIR("A",2)="It must be after "_$$FMTE^XLFDT(MINDT,"5Z")
+6 SET DIR("A")="Start the task at: "
+7 SET DIR(0)="DAU"_U_MINDT_"::RSX"
+8 DO ^DIR
+9 IF $DATA(DIROUT)!$DATA(DIRUT)
QUIT
+10 IF $DATA(DTOUT)!$DATA(DUOUT)
QUIT
+11 SET SDTIME=Y
+12 KILL DIR
+13 SET DIR(0)="YA"
+14 SET DIR("A")="Do you want to run the MST synchronization at the same time every day? "
+15 SET DIR("B")="Y"
+16 DO ^DIR
+17 IF $DATA(DIROUT)!$DATA(DIRUT)
QUIT
+18 IF $DATA(DTOUT)!$DATA(DUOUT)
QUIT
+19 SET STIME=$SELECT(Y:"1."_$PIECE(SDTIME,".",2),1:-1)
+20 ;
+21 ;Put the task into the queue.
+22 KILL ZTSAVE
+23 SET ZTSAVE("STIME")=STIME
+24 SET ZTRTN="SYNCH^PXRMMST"
+25 SET ZTDESC="Clinical Reminders MST synchronization job"
+26 SET ZTDTH=SDTIME
+27 SET ZTIO=""
+28 DO ^%ZTLOAD
+29 WRITE !,"Task number ",ZTSK," queued."
+30 QUIT
+31 ;
+32 ;====================================================
STATUS(DFN,TEST,DATE,VALUE,TEXT) ;Computed finding for checking a
+1 ;patient's MST status.
+2 NEW IEN,TEMP
+3 SET TEMP=$$GETSTAT^DGMSTAPI(DFN)
+4 SET IEN=$PIECE(TEMP,U,1)
+5 IF IEN=-1
Begin DoDot:1
+6 SET TEST=0
SET VALUE=""
SET DATE=$$NOW^PXRMDATE
End DoDot:1
QUIT
+7 IF IEN=0
Begin DoDot:1
+8 SET TEST=0
+9 SET VALUE=$PIECE(TEMP,U,2)
+10 SET DATE=$PIECE(TEMP,U,3)
+11 SET TEXT="No MST status found"
End DoDot:1
QUIT
+12 ;If we get to here then a valid entry was found.
+13 SET TEST=1
+14 SET VALUE=$PIECE(TEMP,U,2)
+15 SET DATE=$PIECE(TEMP,U,3)
+16 QUIT
+17 ;
+18 ;====================================================
STCODE(TERM) ;Return the MST status code based on the term name.
+1 NEW STCODE
+2 SET STCODE=$SELECT(TERM="VA-MST DECLINES REPORT":"D",TERM="VA-MST NEGATIVE REPORT":"N",TERM="VA-MST POSITIVE REPORT":"Y",1:"U")
+3 QUIT STCODE
+4 ;
+5 ;====================================================
SYNCH ;Synchronize the MST history file.
+1 NEW INID,LTIME,NUMUPD,START,TEMP
+2 ;STIME is passed from QUE via ZTSAVE.
+3 DO UPDSTAT(.NUMUPD,.START)
+4 ;If the initial sync data has been stored then update the daily
+5 ;data.
+6 SET INID=+$PIECE($GET(^PXRM(800,1,"MST")),U,1)
+7 IF INID>0
Begin DoDot:1
+8 SET $PIECE(^PXRM(800,1,"MST"),U,3)=$$NOW^XLFDT
+9 SET $PIECE(^PXRM(800,1,"MST"),U,4)=NUMUPD
+10 SET $PIECE(^PXRM(800,1,"MST"),U,6)=START
End DoDot:1
+11 IF '$TEST
Begin DoDot:1
+12 SET $PIECE(^PXRM(800,1,"MST"),U,1)=$$NOW^XLFDT
+13 SET $PIECE(^PXRM(800,1,"MST"),U,2)=NUMUPD
+14 SET $PIECE(^PXRM(800,1,"MST"),U,5)=START
End DoDot:1
+15 ;
+16 ;Cleanup the task stuff.
+17 IF STIME=-1
SET ZTREQ="@"
QUIT
+18 IF '$TEST
Begin DoDot:1
+19 SET TEMP=$GET(^PXRM(800,1,"MST"))
+20 SET LTIME=+$PIECE(TEMP,U,3)
+21 IF LTIME=0
SET LTIME=+$PIECE(TEMP,U,1)
+22 ;Adding STIME sets the new starting time at exactly one day following
+23 ;the previous starting time.
+24 SET $PIECE(ZTREQ,U,1)=$PIECE(LTIME,".",1)+STIME
End DoDot:1
+25 QUIT
+26 ;
+27 ;====================================================
SYNREP ;Provide a report of the synchronization data.
+1 NEW EDTIME,EITIME,IDATE,LDATE,NIUPD,NLUPD,TEMP
+2 SET TEMP=$GET(^PXRM(800,1,"MST"))
+3 SET IDATE=$$FMTE^XLFDT($PIECE(TEMP,U,1))
+4 IF IDATE=0
SET IDATE="none"
+5 SET NIUPD=$PIECE(TEMP,U,2)
+6 SET EITIME=$$FMDIFF^XLFDT($PIECE(TEMP,U,1),$PIECE(TEMP,U,5),2)
+7 SET LDATE=$$FMTE^XLFDT($PIECE(TEMP,U,3))
+8 IF LDATE=0
SET LDATE="none"
+9 SET NLUPD=$PIECE(TEMP,U,4)
+10 SET EDTIME=$$FMDIFF^XLFDT($PIECE(TEMP,U,3),$PIECE(TEMP,U,6),2)
+11 WRITE !!,"Clinical Reminders MST Synchronization Report"
+12 WRITE !,"---------------------------------------------"
+13 WRITE !,"Initial synchronization date: ",IDATE
+14 WRITE !,"Number of updates made: ",NIUPD
+15 IF EITIME>60
Begin DoDot:1
+16 SET EITIME=$$FMDIFF^XLFDT($PIECE(TEMP,U,1),$PIECE(TEMP,U,5),3)
+17 WRITE !,"Elapsed time: ",EITIME
End DoDot:1
+18 IF '$TEST
WRITE !,"Elapsed time: ",EITIME," secs"
+19 WRITE !!,"Last daily synchronization date: ",LDATE
+20 WRITE !,"Number of updates made: ",NLUPD
+21 IF EDTIME>60
Begin DoDot:1
+22 SET EDTIME=$$FMDIFF^XLFDT($PIECE(TEMP,U,3),$PIECE(TEMP,U,6),3)
+23 WRITE !,"Elapsed time: ",EDTIME
End DoDot:1
+24 IF '$TEST
WRITE !,"Elapsed time: ",EDTIME," secs"
+25 QUIT
+26 ;
+27 ;====================================================
UPDATE(DFN,VISIT,SOURCE,STCODE,TYPE) ;Make an update to the MST History file.
+1 NEW DATE,MSTDATE,PROV,STAT,TEMP,UPDSTAT,VPRVIEN
+2 SET UPDSTAT=-1
+3 ;If the update is because of a protocol event use NOW for the
+4 ;date/time. If it is being done as part of a synchronization use
+5 ;the date the visit was created.
+6 SET DATE=$SELECT(TYPE="PROTOCOL":$$NOW^XLFDT,1:$PIECE($GET(^AUPNVSIT(VISIT,0)),U,2))
+7 ;If the date does not contain the time use noon.
+8 IF DATE'["."
SET DATE=DATE_".12"
+9 SET STAT=$$GETSTAT^DGMSTAPI(DFN)
+10 SET MSTDATE=$SELECT($PIECE(STAT,U,1)>0:$PIECE(STAT,U,3),1:0)
+11 IF DATE>MSTDATE
Begin DoDot:1
+12 ;Determine the provider.
+13 SET TEMP=$PIECE(SOURCE,";",2)_$PIECE(SOURCE,";",1)_",12)"
+14 SET PROV=$PIECE($GET(@TEMP),U,4)
+15 IF PROV=""
Begin DoDot:2
+16 ;DBIA #2316
+17 SET VPRVIEN=+$ORDER(^AUPNVPRV("AD",VISIT,""))
+18 IF VPRVIEN>0
SET PROV=$PIECE(^AUPNVPRV(VPRVIEN,0),U,1)
End DoDot:2
+19 SET UPDSTAT=$$NEWSTAT^DGMSTAPI(DFN,STCODE,DATE,PROV)
+20 IF +UPDSTAT=-1
Begin DoDot:2
+21 NEW FN,GBL,IEN,NAME,TARGET,XMSUB,VADM
+22 KILL ^TMP("PXRMXMZ",$JOB)
+23 SET XMSUB="CLINICAL REMINDER MST UPDATE PROBLEM"
+24 SET ^TMP("PXRMXMZ",$JOB,1,0)="NEWSTAT^DGMSTAPI returned the following error:"
+25 SET ^TMP("PXRMXMZ",$JOB,2,0)=$PIECE(UPDSTAT,U,2)
+26 SET ^TMP("PXRMXMZ",$JOB,3,0)="The following data was passed to NEWSTAT^DGMSTAPI"
+27 SET ^TMP("PXRMXMZ",$JOB,4,0)="DFN = "_DFN
+28 SET ^TMP("PXRMXMZ",$JOB,5,0)="Status code = "_STCODE
+29 SET ^TMP("PXRMXMZ",$JOB,6,0)="Date = "_DATE
+30 SET ^TMP("PXRMXMZ",$JOB,7,0)="Provider = "_PROV
+31 SET ^TMP("PXRMXMZ",$JOB,8,0)="Data source = "_SOURCE
+32 SET ^TMP("PXRMXMZ",$JOB,9,0)="This corresponds to the following:"
+33 DO DEM^VADPT
+34 SET ^TMP("PXRMXMZ",$JOB,10,0)="Patient = "_VADM(1)
+35 SET ^TMP("PXRMXMZ",$JOB,11,0)="SSN = "_$PIECE(VADM(2),U,2)
+36 SET ^TMP("PXRMXMZ",$JOB,12,0)="MST Status = "_$$EXTERNAL^DILFD(29.11,3,"",STCODE)
+37 SET ^TMP("PXRMXMZ",$JOB,13,0)="Date = "_$$FMTE^XLFDT(DATE,"5Z")
+38 SET TEMP=$SELECT(PROV="":"Unknown",1:TEMP=$$GET1^DIQ(200,PROV,.01,"","",""))
+39 IF TEMP=""
SET TEMP="Unknown"
+40 SET ^TMP("PXRMXMZ",$JOB,14,0)="Provider = "_TEMP
+41 SET GBL=$PIECE($PIECE(SOURCE,";",2),"(",1)
+42 SET TEMP=GBL_"(0)"
+43 SET FN=+$PIECE(@TEMP,U,2)
+44 SET TEMP=GBL_"("_$PIECE(SOURCE,";",1)_",0)"
+45 SET TEMP=$GET(@TEMP)
+46 SET IEN=$PIECE(TEMP,U,1)
+47 DO FIELD^DID(FN,.01,"N","POINTER","TARGET")
+48 SET GBL="^"_$PIECE(TARGET("POINTER"),"(",1)
+49 SET TEMP=GBL_"(0)"
+50 SET FN=$PIECE(@TEMP,U,1)
+51 SET TEMP=GBL_"("_IEN_",0)"
+52 SET NAME=$PIECE(@TEMP,U,1)
+53 SET ^TMP("PXRMXMZ",$JOB,14,0)="Data type = "_FN
+54 SET ^TMP("PXRMXMZ",$JOB,15,0)="Name = "_NAME
+55 DO SEND^PXRMMSG("PXRMXMZ",XMSUB,"",DUZ)
End DoDot:2
End DoDot:1
+56 QUIT UPDSTAT
+57 ;
+58 ;====================================================
UPDPAT(EVENT,DFN,VISIT,VFL) ;Update the MST history file for a single patient
+1 ;using term mappings. Called from DATACHG^PXRMPINF which is invoked
+2 ;by the protocol PXK VISIT DATA EVENT.
+3 NEW AFTER,BEFORE,DGBL,SP,STCODE,SIEN,SOURCE
+4 NEW TEMP,TERM,TERMIEN,VF
+5 ;Search all the MST terms to build patient lists.
+6 FOR TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT"
Begin DoDot:1
+7 SET TERMIEN=$ORDER(^PXRMD(811.5,"B",TERM,""))
+8 SET VF=""
+9 FOR
SET VF=$ORDER(VFL(VF))
IF VF=""
QUIT
Begin DoDot:2
+10 IF VFL(VF)=U
QUIT
+11 SET DGBL=$PIECE(VFL(VF),U,1)
+12 IF '$DATA(^PXRMD(811.5,TERMIEN,20,"E",DGBL))
QUIT
+13 SET SIEN=""
+14 FOR
SET SIEN=$ORDER(^XTMP(EVENT,VISIT,VF,SIEN))
IF SIEN=""
QUIT
Begin DoDot:3
+15 SET AFTER=$GET(^XTMP(EVENT,VISIT,VF,SIEN,0,"AFTER"))
+16 SET BEFORE=$GET(^XTMP(EVENT,VISIT,VF,SIEN,0,"BEFORE"))
+17 IF AFTER=BEFORE
QUIT
+18 SET SP=$PIECE(AFTER,U,1)
+19 IF SP=""
QUIT
+20 IF '$DATA(^PXRMD(811.5,TERMIEN,20,"E",DGBL,SP))
QUIT
+21 SET SOURCE=SIEN_";^"_$PIECE(VFL(VF),U,2)
+22 ;The status code depends on the term name.
+23 SET STCODE=$$STCODE^PXRMMST(TERM)
+24 SET TEMP=$$UPDATE^PXRMMST(DFN,VISIT,SOURCE,STCODE,"PROTOCOL")
End DoDot:3
End DoDot:2
End DoDot:1
+25 QUIT
+26 ;
+27 ;====================================================
UPDSTAT(NUMUPD,START) ;Update the MST history file using term mappings.
+1 NEW DAS,DATA,DFN,FILENUM,FINDPA,INDEX,ITEM,NOCC,STCODE,SOURCE
+2 NEW TEMP,TERM,TERMARR,TERMIEN,UPDSTAT,VDATE,VISIT
+3 SET FINDPA=""
+4 ;Set the start time for the synchronization.
+5 SET START=$$NOW^XLFDT
+6 SET INDEX="PXRM_MST_LIST"
+7 SET NUMUPD=0
+8 ;Search all the MST terms to build patient lists. Only V file data
+9 ;is used for the update.
+10 FOR TERM="VA-MST DECLINES REPORT","VA-MST NEGATIVE REPORT","VA-MST POSITIVE REPORT"
Begin DoDot:1
+11 KILL TERMARR,^TMP($JOB,INDEX)
+12 ;The status code depends on the term name.
+13 SET STCODE=$$STCODE(TERM)
+14 SET TERMIEN=$ORDER(^PXRMD(811.5,"B",TERM,""))
+15 IF TERMIEN=""
QUIT
+16 DO TERM^PXRMLDR(TERMIEN,.TERMARR)
+17 DO EVALPL^PXRMTERL(.FINDPA,.TERMARR,INDEX)
+18 SET DFN=0
+19 FOR
SET DFN=+$ORDER(^TMP($JOB,INDEX,1,DFN))
IF DFN=0
QUIT
Begin DoDot:2
+20 SET ITEM=""
+21 FOR
SET ITEM=$ORDER(^TMP($JOB,INDEX,1,DFN,ITEM))
IF ITEM=""
QUIT
Begin DoDot:3
+22 SET NOCC=0
+23 FOR
SET NOCC=$ORDER(^TMP($JOB,INDEX,1,DFN,ITEM,NOCC))
IF NOCC=""
QUIT
Begin DoDot:4
+24 SET FILENUM=""
+25 FOR
SET FILENUM=$ORDER(^TMP($JOB,INDEX,1,DFN,ITEM,NOCC,FILENUM))
IF FILENUM=""
QUIT
Begin DoDot:5
+26 SET TEMP=^TMP($JOB,INDEX,1,DFN,ITEM,NOCC,FILENUM)
+27 SET DAS=$PIECE(TEMP,U,1)
+28 KILL DATA
+29 DO GETDATA^PXRMDATA(FILENUM,DAS,.DATA)
+30 SET VISIT=$GET(DATA("VISIT"))
+31 IF VISIT=""
QUIT
+32 SET SOURCE=DAS_";"_^PXRMINDX(FILENUM,"GLOBAL NAME")
+33 SET UPDSTAT=$$UPDATE(DFN,VISIT,SOURCE,STCODE,"SYNCH")
+34 IF UPDSTAT'=-1
SET NUMUPD=NUMUPD+1
End DoDot:5
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+35 KILL ^TMP($JOB,INDEX)
+36 QUIT
+37 ;