Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MBAARPCL

MBAARPCL.m

Go to the documentation of this file.
MBAARPCL ;OIT-PD/PB - Scheduling RPCs ;02/10/2016
 ;;1.0;Scheduling Calendar View;**1**;Feb 10, 2016;Build 85
 ;
 ;Associated ICRs:
 ;  ICR#
 ;  6045 SD(403.5
 ;  10061 VADPT
 ;  6044 SC(
 ;  10112 VASITE
 ;  6053 DPT
 ;  10103 XLFDT
 ;  6047 SDWL(409.32
 ;  1024 DIC(40.7
 ;  6046 SDWL(409.3
 ;
 ;This routine has multiple RPCs created to support the mobile Scheduling apps
RECALL(RESULTS)  ;pull a list of recalls for a facility MBAA RPC: MBAA RECALL FACILITY LIST
 ;   No input parameters
 ;   Output: RESULTS Array:
 ;       $P(1) = DFN
 ;       $P(2) = PTR TO CLINIC FILE
 ;       $P(3) = ACCESSION#
 ;       $P(4) = TEST/APP - PTR TO FILE 403.51
 ;       $P(5) = PROVIDER - PTR TO FILE 405.54
 ;       $P(6) = RECALL DATE PER PROVIDER
 ;       $P(7) = COMMENT
 ;       $P(8) = FAST/NON-FASTING (SET OF CODES: f = Fasting, n = Non- Fasting)
 ;       $P(9) = LENGTH OF APPOINTMENT
 ;       $P(10) = DATE REMINDER SENT
 ;       $P(11) = USER WHO ENTERED RECALL (PTR to file 200)
 ;       $P(12) = RECALL DATE (PER PATIENT)
 ;       $P(13) = SECOND PRINT DATE
 ;       $P(14) = PATIENT NAME (LAST,FIRST)
 ;       $P(15) = PATIENT SSN
 ;       $P(16) = CLINIC NAME
 ;
 S CNT=0 S XX=0 F  S XX=$O(^SD(403.5,XX)) Q:XX'>0  D  ;ICR#: 6045 SD(403.5
 .K DFN,LNAME,SSN,CLINIC,CIEN,NODE,ACCESS,COMMENT,USER,TESTAPP,FASTNON,PATRECDT,PROVIDER,APPTLEN,SCEPRT,RECALLDT,REMINDDT
 .;T13 Change to FM read
 .;S NODE=$G(^SD(403.5,XX,0))  ;ICR#: 6045 SD(403.5
 .;S DFN=$P(NODE,"^"),CIEN=$P(NODE,"^",2)
 .;D DEM^VADPT  ;ICR#: 10061 VADPT
 .;S LNAME=$G(VADM(1)),SSN=$P($G(VADM(2)),"^",2)
 .;I $G(CIEN)>0 S CLINIC=$P(^SC(CIEN,0),"^")  ;ICR#: 6044 SC(
 .;S ACCESS=$P(NODE,"^",3),TESTAPP=$P(NODE,"^",4),PROVIDER=$P(NODE,"^",5),RECALLDT=$P(NODE,"^",6)
 .;S COMMENT=$P(NODE,"^",7),FASTNON=$P(NODE,"^",8),APPTLEN=$P(NODE,"^",9),REMINDDT=$P(NODE,"^",10)
 .;S USER=$P(NODE,"^",11),PATRECDT=$P(NODE,"^",12),SECPRT=$P(NODE,"^",13)
 .;S RESULTS(CNT)=$G(^SD(403.5,XX,0))  ;ICR#: 6045 SD(403.5
 .N ARRAY D GETS^DIQ(403.5,$G(XX),"**","IE","ARRAY")
 .S DFN=$G(ARRAY(403.5,XX_",",.01,"I")),LNAME=$G(ARRAY(403.5,XX_",",.01,"E")),CIEN=$G(ARRAY(403.5,XX_",",4.5,"I")),CLINIC=$G(ARRAY(403.5,XX_",",4.5,"E"))
 .D DEM^VADPT S SSN=$P($G(VADM(2)),"^",2)
 .S ACCESS=$G(ARRAY(403.5,XX_",",2,"I")),TESTAPP=$G(ARRAY(403.5,XX_",",3,"I")),PROVIDER=$G(ARRAY(403.5,XX_",",4,"I")),RECALLDT=$G(ARRAY(403.5,XX_",",5,"I"))
 .S COMMENT=$G(ARRAY(403.5,XX_",",2.5,"I")),FASTNON=$G(ARRAY(403.5,XX_",",2.6,"I")),APPTLEN=$G(ARRAY(403.5,XX_",",4.7,"I"))
 .S REMINDDT=$G(ARRAY(403.5,XX_",",6,"I")),USER=$G(ARRAY(403.5,XX_",",7,"I")),PATRECDT=$G(ARRAY(403.5,XX_",",5.5,"I")),SECPRT=$G(ARRAY(403.5,XX_",",8,"I"))
 .S RESULTS(CNT)=$G(DFN)_U_$G(CIEN)_U_$G(ACCESS)_U_$G(TESTAPP)_U_$G(PROVIDER)_U_$G(RECALLDT)_U_$G(COMMENT)_U_$G(FASTNON)_U_$G(APPTLEN)_U_$G(REMINDDT)_U_$G(USER)_U_$G(PATRECDT)_U_$G(SECPRT)_U_$G(LNAME)_U_$G(SSN)_U_$G(CLINIC)
 .;S:$P(RESULTS(CNT),"^",13)="" RESULTS(CNT)=$G(RESULTS(CNT))_"^^"_$G(LNAME)_"^"_$G(SSN)_"^"_$G(CLINIC)
 .S CNT=CNT+1
 .D KVA^VADPT
 S:$G(RESULTS(0))="" RESULTS(0)="1^RECALL LIST EMPTY"
 K XDT,XX,CNT,DFN,LNAME,VA("PID"),VA("BID"),SSN,CLINIC,CIEN,NODE,ACCESS,COMMENT,USER,TESTAPP,FASTNON,PATRECDT,PROVIDER,APPTLEN,SCEPRT,RECALLDT,REMINDDT,SECPRT
 Q
RCLDFN(RESULTS,DFN) ;pull a list of recalls by patient MBAA RPC: MBAA RECALL LIST BY PATIENT
 ;   Input parameter = DFN (PTR to Patient file #2)
 ;   Output: RESULTS Array:
 ;       $P(1) = DFN
 ;       $P(2) = PTR TO CLINIC FILE
 ;       $P(3) = ACCESSION#
 ;       $P(4) = TEST/APP - PTR TO FILE 403.51
 ;       $P(5) = PROVIDER - PTR TO FILE 405.54
 ;       $P(6) = RECALL DATE PER PROVIDER
 ;       $P(7) = COMMENT
 ;       $P(8) = FAST/NON-FASTING (SET OF CODES: f = Fasting, n = Non- Fasting)
 ;       $P(9) = LENGTH OF APPOINTMENT
 ;       $P(10) = DATE REMINDER SENT
 ;       $P(11) = USER WHO ENTERED RECALL (PTR to file 200)
 ;       $P(12) = RECALL DATE (PER PATIENT)
 ;       $P(13) = SECOND PRINT DATE
 ;       $P(14) = PATIENT NAME (LAST,FIRST)
 ;       $P(15) = PATIENT SSN
 ;       $P(16) = CLINIC NAME
 ;
 K RESULTS
 I $G(DFN)="" S RESULTS(0)="1^DFN HAS TO BE SUPPLIED" Q
 S RESULTS(0)="1^RECALL LIST EMPTY"
 S CNT=0,XX=0 F  S XX=$O(^SD(403.5,"B",DFN,XX)) Q:XX'>0  D  ;ICR#: 6045 SD(403.5
 .K LNAME,SSN,CLINIC,CIEN,NODE,ACCESS,COMMENT,USER,TESTAPP,FASTNON,PATRECDT,PROVIDER,APPTLEN,SCEPRT,RECALLDT,REMINDDT
 .;T13 Change to FM read
 .;S NODE=$G(^SD(403.5,XX,0))  ;ICR#: 6045 SD(403.5
 .;S CIEN=$P(NODE,"^",2)
 .;D DEM^VADPT  ;ICR#: 10061 VADPT
 .;S LNAME=$G(VADM(1)),SSN=$P($G(VADM(2)),"^",2)
 .;I $G(CIEN)>0 S CLINIC=$P(^SC(CIEN,0),"^")  ;ICR#: 6044 SC(
 .;S ACCESS=$P(NODE,"^",3),TESTAPP=$P(NODE,"^",4),PROVIDER=$P(NODE,"^",5),RECALLDT=$P(NODE,"^",6)
 .;S COMMENT=$P(NODE,"^",7),FASTNON=$P(NODE,"^",8),APPTLEN=$P(NODE,"^",9),REMINDDT=$P(NODE,"^",10)
 .;S USER=$P(NODE,"^",11),PATRECDT=$P(NODE,"^",12),SECPRT=$P(NODE,"^",13)
 .;S RESULTS(CNT)=$G(^SD(403.5,XX,0))  ;ICR#: 6045 SD(403.5
 .N ARRAY D GETS^DIQ(403.5,$G(XX),"**","IE","ARRAY")
 .S DFN=$G(ARRAY(403.5,XX_",",.01,"I")),LNAME=$G(ARRAY(403.5,XX_",",.01,"E")),CIEN=$G(ARRAY(403.5,XX_",",4.5,"I")),CLINIC=$G(ARRAY(403.5,XX_",",4.5,"E"))
 .D DEM^VADPT S SSN=$P($G(VADM(2)),"^",2)
 .S ACCESS=$G(ARRAY(403.5,XX_",",2,"I")),TESTAPP=$G(ARRAY(403.5,XX_",",3,"I")),PROVIDER=$G(ARRAY(403.5,XX_",",4,"I")),RECALLDT=$G(ARRAY(403.5,XX_",",5,"I"))
 .S COMMENT=$G(ARRAY(403.5,XX_",",2.5,"I")),FASTNON=$G(ARRAY(403.5,XX_",",2.6,"I")),APPTLEN=$G(ARRAY(403.5,XX_",",4.7,"I"))
 .S REMINDDT=$G(ARRAY(403.5,XX_",",6,"I")),USER=$G(ARRAY(403.5,XX_",",7,"I")),PATRECDT=$G(ARRAY(403.5,XX_",",5.5,"I")),SECPRT=$G(ARRAY(403.5,XX_",",8,"I"))
 .S RESULTS(CNT)=$G(DFN)_U_$G(CIEN)_U_$G(ACCESS)_U_$G(TESTAPP)_U_$G(PROVIDER)_U_$G(RECALLDT)_U_$G(COMMENT)_U_$G(FASTNON)_U_$G(APPTLEN)_U_$G(REMINDDT)_U_$G(USER)_U_$G(PATRECDT)_U_$G(SECPRT)_U_$G(LNAME)_U_$G(SSN)_U_$G(CLINIC)
 .;S RESULTS(CNT)=$G(^SD(403.5,XX,0))
 .;S:$P(RESULTS(CNT),"^",13)="" RESULTS(CNT)=$G(RESULTS(CNT))_"^"
 .S CNT=CNT+1
 .D KVA^VADPT
 K XDT,XX,CNT
 K DFN,LNAME,SSN,CLINIC,VA("PID"),VA("BID"),CIEN,NODE,ACCESS,COMMENT,USER,TESTAPP,FASTNON,PATRECDT,PROVIDER,APPTLEN,SCEPRT,RECALLDT,REMINDDT
 Q
NEARLST(RESULTS) ;Gets the NEAR List for a Facility MBAA RPC: MBAA FACILITY NEAR LIST
 ;  No input parameters required
 ;  Output: TMP($J,"NEAR")=DFN^PATIENTNAME^SSN^ELIGIBILITY CODE INTERNAL^ELIGIBILITY CODE EXTERNAL^HOME PHONE^CELL PHONE^DATE^SITE
 ;    DFN = PATIENT ID
 ;    PATIENTNAME = PATIENT NAME
 ;    SSN = LAST FOUR OF SSN
 ;    ELIGIBILITY CODE INTERNAL = INTERNAL ELIGIBILITY CODE
 ;    ELIGIBILITY CODE EXTERNAL = EXTERNAL ELIGIBILITY CODE
 ;    HOME PHONE
 ;    CELL PHONE
 ;    DATE = APPOINTMENT DATE REQUESTED
 ;    SITE = FACILITY ID
 ;-Build temp global
 K ^TMP($J,"NEAR")
 N DFNIEN,DGSITE,PNAME,SSN,ELIG,PHONE,CELL,DFN
 S DGSITE=+$$SITE^VASITE()  ;ICR#: 10112 VASITE
 S (CNT,DFNIEN)=0 F  S DFNIEN=$O(^DPT("AEAR",1,DFNIEN)) Q:'DFNIEN  D  ;ICR#: 6053 DPT
 .I $$GET1^DIQ(2,DFNIEN,1010.159,"I") D
 .Q:$P($G(^DPT(DFNIEN,1010.16)),"^",1)'=""  ;ICR#: 6053 DPT
 .S DFN=DFNIEN D DEM^VADPT,ELIG^VADPT,ADD^VADPT  ;ICR#: 10061 VADPT
 .S CNT=CNT+1
 .;T13 Change to get cell phone using FM read
 .;S PNAME=VADM(1),SSN=+VADM(2),ELIG=VAEL(1),PHONE=VAPA(8),CELL=$P($G(^DPT(DFNIEN,.13)),"^",4)  ;ICR#: 6053 DPT
 .S PNAME=VADM(1),SSN=+VADM(2),ELIG=VAEL(1),PHONE=VAPA(8),CELL=$$GET1^DIQ(2,100841,.01,"I")  ;ICR#: 6053 DPT
 .I $G(ELIG)="" S ELIG="^"
 .S ^TMP($J,"NEAR",CNT)=DFNIEN_"^"_$G(PNAME)_"^"_$G(SSN)_"^"_$G(ELIG)_"^"_$G(PHONE)_"^"_$G(CELL)_"^"_$$GET1^DIQ(2,DFNIEN,1010.1511,"I")_"^"_DGSITE_$C(10)
 .K PNAME,DFN,SSN,ELIG,PHONE,CELL
 .D KVA^VADPT
 S RESULTS=$NA(^TMP($J,"NEAR"))
 K DFN,VADM,VAEL,VAPA,VA("BID"),VA("PID"),VACNTRY,VAERR
 Q
 ;
NEARDFN(RESULTS,DFN) ;Gets the NEAR List for a PATIENT MBAA RPC: MBAA PATIENT NEAR LIST
 ;  INPUT: Patient DFN
 ;  Output:
 ;  If the patient is on the NEAR List, returns the array:
 ;    DFN^PATIENTNAME^SSN^ELIGIBILITY CODE INTERNAL^ELIGIBILITY CODE EXTERNAL^HOME PHONE^CELL PHONE^DATE^SITE
 ;    DFN = PATIENT ID
 ;    PATIENTNAME = PATIENT NAME
 ;    SSN = LAST FOUR OF SSN
 ;    ELIGIBILITY CODE INTERNAL = INTERNAL ELIGIBILITY CODE
 ;    ELIGIBILITY CODE EXTERNAL = EXTERNAL ELIGIBILITY CODE
 ;    HOME PHONE
 ;    CELL PHONE
 ;    DATE = APPOINTMENT DATE REQUESTED
 ;    SITE = FACILITY ID
 ;   If the patient is not on the NEAR List returns "1^Patient not on the NEAR List"
 N DGSITE,SSN,ELIG,PHONE,CELL,PNAME
 I $G(DFN)="" S RESULTS(0)="1^DFN IS NOT DEFINED" Q
 S RESULTS(0)=""
 I $$GET1^DIQ(2,DFN,1010.159,"I") D
 .Q:$P($G(^DPT(DFN,1010.16)),"^",1)'=""  ;ICR#: 6053 DPT
 .S DGSITE=+$$SITE^VASITE()
 .D DEM^VADPT,ELIG^VADPT,ADD^VADPT  ;ICR#: 10061 VADPT
 .;T13 Change to get cell phone using FM read
 .;S PNAME=VADM(1),SSN=+VADM(2),ELIG=VAEL(1),PHONE=VAPA(8),CELL=$P($G(^DPT(DFN,.13)),"^",4)  ;ICR#: 6053 DPT
 .S PNAME=VADM(1),SSN=+VADM(2),ELIG=VAEL(1),PHONE=VAPA(8),CELL=$$GET1^DIQ(2,100841,.01,"I")  ;ICR#: 6053 DPT
 .I $G(ELIG)="" S ELIG="^"
 .S RESULTS(0)=DFN_"^"_$G(PNAME)_"^"_$G(SSN)_"^"_$G(ELIG)_"^"_$G(PHONE)_"^"_$G(CELL)_"^"_$$GET1^DIQ(2,DFN,1010.1511,"I")_"^"_DGSITE
 .D KVA^VADPT
 I RESULTS(0)="" S RESULTS(0)="1^Patient not on the NEAR List"
 K DFN,VADM,VAEL,VAPA,VA("BID"),VA("PID"),VACNTRY,VAERR
 Q
EWL(RESULTS,DFN) ; gets the EWL data by patient as described in the output data MBAA RPC: MBAA WAIT LIST BY DFN
 ;  Input: Patient DFN (PTR to Patient File (#2))
 ;  Outputs if successful - patient is on the EWL:
 ;  $P(1)  = DFN
 ;  $P(2)  = DSS STOP CODE
 ;  $P(3)  = LAST UPDATED (RETURNED IN FILEMAN FORMAT)
 ;  $P(4)  = PATIENT NAME
 ;  $P(5)  = PATIENT SSN
 ;  $P(6)  = CLINIC NAME
 ;  $P(7)  = ORIGINATING DATE (RETURNED IN FILEMAN FORMAT)
 ;  $P(8)  = DESIRED DATE OF APPOINTMENT
 ;  $P(9)  = DAYS ON EWL
 ;  $P(10) = DATE REMOVED FROM EWL (RETURNED IN FILEMAN FORMAT)
 ;  $P(11) = PATIENT ZIP CODE
 ;  $P(12) = SERVICE CONNECTED %
 ;  $P(13) = ENROLLEE STATUS
 ;  $P(14) = PRIORITY
 ;  $P(15) = CLINIC ID
 ;  $P(16) = IEN FROM SDWL(409.3 FOR THE ENTRY
 ;
 ;  If patient is not on the EWL, returns
 ;  RESULTS(0)="1^PATIENT NOT ON THE EWL."
 ;
 I $G(DFN)="" S RESULTS(0)="1^DFN IS NOT DEFINED" Q
 I '$D(^SDWL(409.3,"B",DFN)) S RESULTS(0)="1^PATIENT NOT ON THE EWL" Q  ;ICR#: 6046 SDWL(409.3
 S REC=0,CNT=1 F  S REC=$O(^SDWL(409.3,"B",DFN,REC)) Q:REC'>0  D  ;ICR#: 6046 SDWL(409.3
 .;T13 Change to use FM reads
 .;S NODE=$G(^SDWL(409.3,REC,0))  ;ICR#: 6046 SDWL(409.3
 .;Q:$G(NODE)=""
 .;I $P($G(NODE),"^",17)="C" S RESULTS(0)="1^PATIENT NOT ON THE EWL" Q
 .;I $P($G(NODE),"^",17)="O" S RESULTS(0)="" 
 .I $$GET1^DIQ(409.3,REC,23,"I")="C" S RESULTS(0)="1^PATIENT NOT ON THE EWL" Q
 .I $$GET1^DIQ(409.3,REC,23,"I")="O" S RESULTS(0)=""
 .N SDWL1
 .D GETS^DIQ(409.3,REC_",","1;8;10;13.1;14;22;23;27","IE","SDWL1")
 .D NOW^%DTC,DEM^VADPT,ADD^VADPT  ;ICR#: 10061 VADPT
 .S (ORIGDT,LASTUPDT)=$G(SDWL1(409.3,REC_",",1,"I")),DAYSON=$$FMDIFF^XLFDT(%,ORIGDT,1)  ;ICR#: 10103 XLFDT
 .;S (ORIGDT,LASTUPDT)=$P(NODE,"^",2),DAYSON=$$FMDIFF^XLFDT(%,ORIGDT,1)  ;ICR#: 10103 XLFDT
 .S PTNAME=$G(VADM(1))  ;,LASTNAME=$P(PTNAME,",")
 .S SSN=$P($G(VADM(2)),"^",2),ZIP=$G(VAPA(6))
 .S DESIRED=$G(SDWL1(409.3,REC_",",22,"I")),CLINIEN=$G(SDWL1(409.3,REC_",",8,"I"))
 .;S DESIRED=$P(NODE,"^",16),CLINIEN=$P(NODE,"^",9)
 .I $G(CLINIEN)'="" D
 ..S PTR=$$GET1^DIQ(409.32,CLINIEN_",",".01","I")  ;ICR#: 6047 SDWL(409.32
 ..K CLIN1 D GETS^DIQ(44,PTR_",",".01;8","IE","CLIN1") S CLINNAME=$G(CLIN1(44,PTR_",",.01,"E")),STPCODE=$G(CLIN1(44,PTR_",",8,"E"))
 .;S SC=$P($G(^SDWL(409.3,REC,"SC")),"^",1),PRIOR=$P(NODE,"^",11),ENRSTAT1=$P(NODE,"^",20)  ;ICR#: 6046 SDWL(409.3
 .S SC=$G(SDWL1(409.3,REC_",",14,"E")),PRIOR1=$G(SDWL1(409.3,REC_",",10,"E")),ENRSTAT=$G(SDWL1(409.3,REC_",",27,"E"))  ;ICR#: 6046 SDWL(409.3
 .;S DTREMOVE=$P($G(^SDWL(409.3,REC,"SDAPT")),"^",1)  ;ICR#: 6046 SDWL(409.3
 .S DTREMOVE=$G(SDWL1(409.3,REC_",",13.1,"I"))  ;ICR#: 6046 SDWL(409.3
 .;I ENRSTAT1'="" S ENRSTAT=$S(ENRSTAT1="N":"NEW",ENRSTAT1="E":"ESTABLISHED",ENRSTAT1="P":"PRIOR",ENRSTAT1="U":"UNDETERMINED",1:"UNKNOWN")
 .;I PRIOR'="" S PRIOR1=$S(PRIOR="A":"ASAP",PRIOR="F":"FUTURE",1:0)
 .S RESULTS(CNT)=DFN_U_$G(STPCODE)_U_$G(LASTUPDT)_U_$G(PTNAME)_U_$G(SSN)_U_$G(CLINNAME)_U_$G(ORIGDT)_U_$G(DESIRED)_U_$G(DAYSON)_U_$G(DTREMOVE)_U_$G(ZIP)_U_$G(SC)_U_$G(ENRSTAT)_U_$G(PRIOR1)_U_$G(CLINIEN)_U_$G(REC),CNT=CNT+1
 .D KVA^VADPT
 .K NODE,%,ORIGDT,LASTUPDT,DAYSON,PTNAME,LASTNAME,SSN
 .K DESIRED,CLINIEN,PTR,CLINNAME,STOPPTR,STPCODE,PRIOR,ENRSTAT,SC,ENRSTAT1,PRIOR1,DTREMOVE,ZIP,CLIN1,SDWL1
 K REC,CNT,REC,DFN
 Q
FACEWL(RESULTS) ; gets the EWL data for a facility as described in the output data MBAA RPC: MBAA FACILITY WAIT LIST
 ;  Outputs if successful - patient is on the EWL:
 ;  $P(1)  = DFN
 ;  $P(2)  = DSS STOP CODE
 ;  $P(3)  = LAST UPDATED (RETURNED IN FILEMAN FORMAT)
 ;  $P(4)  = PATIENT NAME
 ;  $P(5)  = PATIENT SSN
 ;  $P(6)  = CLINIC NAME
 ;  $P(7)  = ORIGINATING DATE (RETURNED IN FILEMAN FORMAT)
 ;  $P(8)  = DESIRED DATE OF APPOINTMENT
 ;  $P(9)  = DAYS ON EWL
 ;  $P(10) = DATE REMOVED FROM EWL (RETURNED IN FILEMAN FORMAT)
 ;  $P(11) = PATIENT ZIP CODE
 ;  $P(12) = SERVICE CONNECTED %
 ;  $P(13) = ENROLLEE STATUS
 ;  $P(14) = PRIORITY
 ;  $P(15) = CLINIC ID
 ;  $P(16) = IEN FROM SDWL(409.3 FOR THE ENTRY
 ;
 ;  If no patients are not on the EWL, returns
 ;  RESULTS(0)="1^EWL is empty."
 ;
 I '$D(^SDWL(409.3,"B")) S RESULTS(0)="1^EWL is empty." Q  ;ICR#: 6046 SDWL(409.3
 S REC=0,CNT=0,DFN=0 F  S DFN=$O(^SDWL(409.3,"B",DFN)) Q:DFN'>0  F  S REC=$O(^SDWL(409.3,"B",DFN,REC)) Q:REC'>0  D  ;ICR#: 6046 SDWL(409.3
 .;T13 Change to use FM reads
 .;S NODE=$G(^SDWL(409.3,REC,0))  ;ICR#: 6046 SDWL(409.3
 .;Q:$G(NODE)=""
 .;I $P($G(NODE),"^",17)="C" S RESULTS(0)="1^PATIENT NOT ON THE EWL" Q
 .;I $P($G(NODE),"^",17)="O" S RESULTS(0)="" 
 .;I $$GET1^DIQ(409.3,REC,23,"I")="C" S RESULTS(0)="1^PATIENT NOT ON THE EWL" Q
 .;I $$GET1^DIQ(409.3,REC,23,"I")="O" S RESULTS(0)=""
 .Q:$$GET1^DIQ(409.3,REC,23,"I")="C"
 .N SDWL1
 .K SEWL1 D GETS^DIQ(409.3,REC_",","1;8;10;13.1;14;22;23;27","IE","SDWL1")
 .D NOW^%DTC,DEM^VADPT,ADD^VADPT  ;ICR#: 10061 VADPT
 .S (ORIGDT,LASTUPDT)=$G(SDWL1(409.3,REC_",",1,"I")),DAYSON=$$FMDIFF^XLFDT(%,ORIGDT,1)  ;ICR#: 10103 XLFDT
 .;S (ORIGDT,LASTUPDT)=$P(NODE,"^",2),DAYSON=$$FMDIFF^XLFDT(%,ORIGDT,1)  ;ICR#: 10103 XLFDT
 .S PTNAME=$G(VADM(1))  ;,LASTNAME=$P(PTNAME,",")
 .S SSN=$P($G(VADM(2)),"^",2),ZIP=$G(VAPA(6))
 .S DESIRED=$G(SDWL1(409.3,REC_",",22,"I")),CLINIEN=$G(SDWL1(409.3,REC_",",8,"I"))
 .;S DESIRED=$P(NODE,"^",16),CLINIEN=$P(NODE,"^",9)
 .I $G(CLINIEN)'="" D
 ..S PTR=$$GET1^DIQ(409.32,CLINIEN_",",".01","I")  ;ICR#: 6047 SDWL(409.32
 ..K CLIN1 D GETS^DIQ(44,PTR_",",".01;8","IE","CLIN1") S CLINNAME=$G(CLIN1(44,PTR_",",.01,"E")),STPCODE=$G(CLIN1(44,PTR_",",8,"E"))
 .S SC=$G(SDWL1(409.3,REC_",",14,"E")),PRIOR1=$G(SDWL1(409.3,REC_",",10,"E")),ENRSTAT=$G(SDWL1(409.3,REC_",",27,"E"))  ;ICR#: 6046 SDWL(409.3
 .;S DTREMOVE=$P($G(^SDWL(409.3,REC,"SDAPT")),"^",1)  ;ICR#: 6046 SDWL(409.3
 .S DTREMOVE=$G(SDWL1(409.3,REC_",",13.1,"I"))  ;ICR#: 6046 SDWL(409.3
 .;I ENRSTAT1'="" S ENRSTAT=$S(ENRSTAT1="N":"NEW",ENRSTAT1="E":"ESTABLISHED",ENRSTAT1="P":"PRIOR",ENRSTAT1="U":"UNDETERMINED",1:"UNKNOWN")
 .;I PRIOR'="" S PRIOR1=$S(PRIOR="A":"ASAP",PRIOR="F":"FUTURE",1:0)
 .;S NODE=$G(^SDWL(409.3,REC,0))  ;ICR#: 6046 SDWL(409.3
 .;Q:$G(NODE)=""
 .;Q:$P($G(NODE),"^",17)="C"
 .;D NOW^%DTC,DEM^VADPT,ADD^VADPT  ;ICR#: 10061 VADPT
 .;S (ORIGDT,LASTUPDT)=$P(NODE,"^",2),DAYSON=$$FMDIFF^XLFDT(%,ORIGDT,1)  ;ICR#: 10103 XLFDT
 .;S PTNAME=$G(VADM(1)) ;,LASTNAME=$P(PTNAME,",")
 .;S SSN=$P($G(VADM(2)),"^",2),ZIP=$G(VAPA(6))
 .;S DESIRED=$P(NODE,"^",16),CLINIEN=$P(NODE,"^",9)
 .;I $G(CLINIEN)'="" D
 .;S SC=$P($G(^SDWL(409.3,REC,"SC")),"^",1),PRIOR=$P(NODE,"^",11),ENRSTAT1=$P(NODE,"^",20)  ;ICR#: 6046 SDWL(409.3
 .;S DTREMOVE=$P($G(^SDWL(409.3,REC,"SDAPT")),"^",1)  ;ICR#: 6046 SDWL(409.3
 .;I ENRSTAT1'="" S ENRSTAT=$S(ENRSTAT1="N":"NEW",ENRSTAT1="E":"ESTABLISHED",ENRSTAT1="P":"PRIOR",ENRSTAT1="U":"UNDETERMINED",1:"UNKNOWN")
 .;I PRIOR'="" S PRIOR1=$S(PRIOR="A":"ASAP",PRIOR="F":"FUTURE",1:0)
 .S RESULTS(CNT)=DFN_U_$G(STPCODE)_U_$G(LASTUPDT)_U_$G(PTNAME)_U_$G(SSN)_U_$G(CLINNAME)_U_$G(ORIGDT)_U_$G(DESIRED)_U_$G(DAYSON)_U_$G(DTREMOVE)_U_$G(ZIP)_U_$G(SC)_U_$G(ENRSTAT)_U_$G(PRIOR1)_U_$G(CLINIEN)_U_$G(REC),CNT=CNT+1
 .D KVA^VADPT
 .K NODE,%,ORIGDT,LASTUPDT,DAYSON,PTNAME,LASTNAME,SSN
 .K DESIRED,CLINIEN,PTR,CLINNAME,STOPPTR,STPCODE,PRIOR,ENRSTAT,SC,ENRSTAT1,PRIOR1
 K REC,CNT,REC,DFN
 Q
EDITNEAR(RESULTS,DFN,STATUS,COMM) ;Edit a patient on the NEAR List MBAA RPC: MBAA UPDATE NEAR LIST
 ;Called by the RPC ZSD EDIT NEAR
 ;Input: 
 ;  DFN         = Patient DFN
 ;  STATUS      = Set of codes:
 ;                  C = Cancelled
 ;                  E = EWL - Moved to the EWL
 ;                  F = Filled
 ;                  I = In Process/Veteran Contacted
 ;  COMM        = Comments. Required if the status is cancelled, otherwise it is optional
 ;Output: RESULTS(0)="0^Patient NEAR List entry updated." if the update was successful
 ;        RESULTS(0)="1^Patient is not on the NEAR List."
 ;        RESULTS(0)="1^DFN was not provided."
 ;        RESULTS(0)="1^Status is null. Status is a required field."
 ;        RESULTS(0)="1^Could not update the record."
 ;        RESULTS(0)="1^Patient record is locked, try again later."
 S RESULTS(0)=""
 I $G(DFN)="" S RESULTS(0)="1^DFN was not provided." Q
 I $G(STATUS)="" S RESULTS(0)="1^Status is null. Status is a required field." Q
 I $D(^DPT(DFN,1010.16)) D  ;ICR#: 6053 DPT
 .I $P(^DPT(DFN,1010.16),U,1)'="" S ERR=1  ;ICR#: 6053 DPT
 I $G(ERR)=1 S RESULTS(0)="1^Patient is not on the NEAR List." Q
 I '$$GET1^DIQ(2,DFN,1010.159,"I") S RESULTS(0)="1^Patient is not on the NEAR List." Q
 D NOW^%DTC
 L +^DPT(DFN):10 I '$TEST S ERR=1,RESULTS(0)="1^Patient record is locked, try again later." Q  ;ICR#: 6053 DPT
 S DA=DFN,DIE="^DPT(",DR="1010.161///"_$G(STATUS)_";1010.163///"_$G(COMM) D ^DIE
 L -^DPT(DFN)  ;ICR#: 6053 DPT
 K DA,DIE,DR
 ;I $P($G(^DPT(DFN,1010.16)),"^")='$G(STATUS) S ERR=1
 ;I $P($G(^DPT(DFN,1010.16)),"^",2)'=% S ERR=1
 I $P($G(^DPT(DFN,1010.16)),"^")=$G(STATUS) S RESULTS(0)="0^Patient removed from NEAR List."  ;ICR#: 6053 DPT
 ;I $G(ERR)=1 S RESULTS(0)="1^Could not update the record." Q
 S RESULTS(0)="0^Patient NEAR List entry updated."
 Q