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

SDECDATA.m

Go to the documentation of this file.
  1. SDECDATA ;ALB/WTC - VISTA SCHEDULING GUI ; 01 May 2019 10:52 AM
  1. ;;5.3;Scheduling;**723,731**;;Build 7
  1. ;;Per VHA Directive 2004-038, this routine should not be modified
  1. Q
  1. ;
  1. ; ICR
  1. ; ---
  1. ; 7030 - #2 Appointment data
  1. ; 10035 - #2 Patient demographics
  1. ;
  1. REPORT ;
  1. ;
  1. ; Run report only
  1. ;
  1. N AUTO,REPORT,POP,IO,%ZIS ;
  1. S REPORT="YES",AUTO="NO" ;
  1. S %ZIS="Q" D ^%ZIS Q:POP ; Added code to output to printer. wtc 9/12/2019
  1. D APPT1 Q ;
  1. ;
  1. AUTO ;
  1. ;
  1. ; Run correction code non-interactively.
  1. ;
  1. N AUTO,REPORT S REPORT="NO",AUTO="YES" D APPT1 Q ;
  1. ;
  1. APPT ;
  1. ;
  1. ; Scan appointment file (#409.84) for entries without resources. Identify correct resource using appointment list in patient file (#2).
  1. ;
  1. N AUTO,REPORT S REPORT="NO",AUTO="NO" ;
  1. ;
  1. APPT1 ;
  1. ;
  1. N DA,APPTDATA,CNT,STARTTIME,DFN,CANCELLED,APPTMADE,MADEBY,PTDATA,FAILED,CLINICSFND,CLINIC,DA1,RESOURCE,MATCHED,RESPONSE,STOP,FIXED,LOCDATA,D2,%DT,PTR44,Y ;
  1. ;
  1. ; DA = Appointment (#409.84) pointer
  1. ; APPTDATA = Zero node of appointment file entry (#409.84)
  1. ; CNT = Number of appointments with missing resources found
  1. ; STARTTIME = Appointment start time
  1. ; DFN = Patient (#2) pointer
  1. ; CANCELLED = Appointment cancelled flag (from #409.84)
  1. ; APPTMADE = Date appointment was made (from #409.84)
  1. ; MADEBY = DUZ of person making appointment (from #409.84)
  1. ; PTDATA = Appointment data record from patient file (#2)
  1. ; FAILED = Total number of appointment records that could not be matched
  1. ; CLINICFND = Array indexed by clinic name of appointment records matched with patient appointments
  1. ; CLINIC = Clinic name (.01 field of file #44)
  1. ; DA1 = Appointment (#409.84) pointer
  1. ; RESOURCE = Resource (#409.831) pointer
  1. ; MATCHED = 1 if a second appointment for same patient at same time in the same clinic is found, 0 otherwise
  1. ; RESPONSE = User response
  1. ; STOP = 1 if user enters ^ to stop processing or time out occurs
  1. ; FIXED = Count of number of appointment records updated
  1. ; LOCDATA = Appointment data record from the location file (#44)
  1. ; D2 = Subscript in appointment multiple in location file (#44)
  1. ; PTR44 = Hospital location (pointer to #44)
  1. ;
  1. U 0 W !!,"Appointments without resources checker",! ;
  1. ;
  1. S CNT=0,FAILED=0,STOP=0,FIXED=0 ;
  1. ;
  1. ; Scan is in date order starting with the user indicated date.
  1. ;
  1. U 0 W !,"Select starting date to check",! ;
  1. S %DT="AX" D ^%DT Q:Y<0 S STARTTIME=$P(Y,".",1) W ! ;
  1. ;
  1. ; If report is queued, set up variables and call Task Manager then quit
  1. ;
  1. I REPORT="YES",$D(IO("Q")) D Q ;
  1. . S ZTRTN="APPT2^SDECDATA",ZTDESC="Appointments missing resources starting from "_$$FMTE^XLFDT(STARTTIME) ;
  1. . S ZTSAVE("*")="" ;
  1. . D ^%ZTLOAD W $S($D(ZTSK):"...Task queued",1:"...Task cancelled"),! ;
  1. ;
  1. APPT2 ; Entry point for queued report printing
  1. ;
  1. ; Scan appointment file in date order.
  1. ;
  1. F S STARTTIME=$O(^SDEC(409.84,"B",STARTTIME)) Q:'STARTTIME Q:STOP S DA=0 F S DA=$O(^SDEC(409.84,"B",STARTTIME,DA)) Q:'DA S APPTDATA=^SDEC(409.84,DA,0) I $P(APPTDATA,U,7)="" S CNT=CNT+1 D Q:STOP ;
  1. . ;
  1. . S DFN=$P(APPTDATA,U,5),CANCELLED=$S($P(APPTDATA,U,12)="":0,1:1),APPTMADE=$P(APPTDATA,U,9),MADEBY=$P(APPTDATA,U,8) ;
  1. . U:REPORT="YES" IO W !,CNT,". ",$$FMTE^XLFDT(STARTTIME)," (",DA,") ",$P(^DPT(DFN,0),U,1) ; ICR 10035
  1. . ;
  1. . ; Find appointment in patient file.
  1. . ;
  1. . I '$D(^DPT(DFN,"S",STARTTIME,0)) W " *** No matching appointment in Patient file.",! S FAILED=FAILED+1 Q ;
  1. . S PTDATA=^DPT(DFN,"S",STARTTIME,0),PTR44=$P(PTDATA,U,1),CLINIC=$P(^SC(PTR44,0),U,1) W " ",CLINIC,! ; ICR 7030
  1. . S CLINICSFND(CLINIC)=$G(CLINICSFND(CLINIC))+1 ;
  1. . ;
  1. . ; Find appointment in location file.
  1. . ;
  1. . S D2=0,LOCDATA="" F S D2=$O(^SC(PTR44,"S",STARTTIME,1,D2)) Q:'D2 I $P(^(D2,0),U,1)=DFN D Q:LOCDATA'="" ;
  1. .. S LOCDATA=^SC(PTR44,"S",STARTTIME,1,D2,0) ;
  1. .. I $P(LOCDATA,U,6)'=$P(PTDATA,U,18) S LOCDATA="" Q ; Appointment made by do not match. Continue looking.
  1. .. I $P(LOCDATA,U,7)'=$P(PTDATA,U,19) S LOCDATA="" Q ; Date appointment made do not match. Continue looking.
  1. .. I $P(PTDATA,U,2)="C"!($P(PTDATA,U,2)="PC"),$P(LOCDATA,U,9)="C" Q ; Both appointments are cancelled. Matching appointment found.
  1. .. I $P(PTDATA,U,2)'="C",$P(PTDATA,U,2)'="PC",$P(LOCDATA,U,9)'="C" Q ; Both appointments are not cancelled. Matching appointment found.
  1. .. S LOCDATA="" ; Not a match. Continue looking.
  1. . ;
  1. . W !,"Source",?15,"Status",?30,"Date Made",?45,"Made by",! ;
  1. . W "-----------",?15,"---------",?30,"------------",?45,"-----------------------------",! ;
  1. . W "Patient",?15,$S($P(PTDATA,U,2)="C"!($P(PTDATA,U,2)="PC"):"Cancelled",1:"Active"),?30,$$FMTE^XLFDT($P(PTDATA,U,19)),?45,$$GET1^DIQ(200,$P(PTDATA,U,18)_",",.01),! ;
  1. . I LOCDATA="" W "Location",?15,"NOT IN FILE",! ;
  1. . E W "Location",?15,$S($P(LOCDATA,U,9)="C":"Cancelled",1:"Active"),?30,$$FMTE^XLFDT($P(LOCDATA,U,7)),?45,$$GET1^DIQ(200,$P(LOCDATA,U,6)_",",.01),! ;
  1. . W "Appointment",?15,$S(CANCELLED:"Cancelled",1:"Active"),?30,$$FMTE^XLFDT(APPTMADE),?45,$$GET1^DIQ(200,MADEBY_",",.01),! ;
  1. . ;
  1. . ; Stop if patient appointment is active but no matching appointment in Location file.
  1. . ;
  1. . I $P(PTDATA,U,2)'="C",$P(PTDATA,U,2)'="PC",LOCDATA="" W !,"Active appointment in Patient file not in Location file." S FAILED=FAILED+1 Q ;
  1. . ;
  1. . ; Determine if another appointment file entry is for the same time
  1. . ;
  1. . S DA1=0,MATCHED=0 F S DA1=$O(^SDEC(409.84,"CPAT",DFN,DA1)) Q:'DA1 I DA1'=DA D Q:MATCHED ;
  1. .. ;
  1. .. Q:$P(^SDEC(409.84,DA1,0),U,1)'=STARTTIME W !,"*** Another appointment exists for the patient at the same time.",! S FAILED=FAILED+1,MATCHED=1 ;
  1. .. ;
  1. . Q:MATCHED ;
  1. . ;
  1. . ; If patient appointment and location appointment is cancelled but appointment file entry is NOT cancelled, fix the appointment file entry. 731 wtc 7/25/2019
  1. . ;
  1. . ;I $P(PTDATA,U,2)="C"!($P(PTDATA,U,2)="PC"),$P(LOCDATA,U,9)="C",'CANCELLED S FAILED=FAILED+1 Q ;
  1. . ;
  1. . ; Do not match appointments if not made by same person on same day.
  1. . ; Do not match appointments if patient and location file do not agree or patient file is active but location file does not exist.
  1. . ;
  1. . I $P(PTDATA,U,2)'="C",$P(PTDATA,U,2)'="PC",LOCDATA=""!($P(LOCDATA,U,9)="C") S FAILED=FAILED+1 Q ;
  1. . ;
  1. . ; Do not fail matching due to appointment made by and date appointment made. 731 wtc 8/6/2019
  1. . ;
  1. . ;I $P(PTDATA,U,19)'=$P(APPTMADE,".",1) S FAILED=FAILED+1 Q ;
  1. . ;I $P(PTDATA,U,18)'=MADEBY S FAILED=FAILED+1 Q ;
  1. . ;
  1. . ; OK to correct if patient file is active but appointment file is cancelled.
  1. . ;
  1. . ;I $P(PTDATA,U,2)'="C",$P(PTDATA,U,2)'="PC",CANCELLED S FAILED=FAILED+1 Q ;
  1. . ;
  1. . ; Stop if report only
  1. . ;
  1. . I REPORT="YES" Q ;
  1. . ;
  1. . ; Check resource file for entry matching the clinic name. If one does not exist, notify user but do not process a change for the appointment.
  1. . ;
  1. . S RESOURCE=$O(^SDEC(409.831,"B",CLINIC,0)) ;
  1. . I 'RESOURCE W !,"No resource exists with the name '",CLINIC,"'.",!,"Create the required resource before updating this appointment.",! Q ;
  1. . I $P($G(^SDEC(409.831,RESOURCE,0)),U,4)'=PTR44 W !,"Resource not associated with ",CLINIC,". Correct this before updating this appointment.",! Q ;
  1. . ;
  1. . ; If automatics option selected, update the appointment.
  1. . ;
  1. . ; Added 2 parameters to UPDAPPT call to allow matching if patient file appointment is cancelled but appointment file entry is not. 731 wtc 7/26/2019
  1. . ;
  1. . I AUTO="YES" D UPDAPPT(DA,RESOURCE,$P(PTDATA,U,2),CANCELLED) W "...updated",! S FIXED=FIXED+1 Q ;
  1. . ;
  1. . ; For manual processing, ask user if he/she wants to update Appointment file with resource of same name as clinic.
  1. . ;
  1. . W !,"Make '",CLINIC,"' the resource for this appointment?" R " NO// ",RESPONSE:$S($G(DTIME):DTIME,1:180) I '$T!(RESPONSE="^") S STOP=1 Q ;
  1. . ;
  1. . ; Added 2 parameters to UPDAPPT call to allow matching if patient file appointment is cancelled but appointment file entry is not. 731 wtc 7/26/2019
  1. . ;
  1. . I RESPONSE="YES"!(RESPONSE="Y")!(RESPONSE="yes")!(RESPONSE="y") D UPDAPPT(DA,RESOURCE,$P(PTDATA,U,2),CANCELLED) W "...updated",! S FIXED=FIXED+1 Q ;
  1. . ;
  1. . W "... skipped",! Q ;
  1. ;
  1. I 'CNT Q:REPORT="NO" D ^%ZISC K ZTDESC,ZTRTN,ZTSAVE,ZTSK Q ; No bad entries found. Do not output statistics.
  1. ;
  1. ; Output statistics. Show total found, number fixed and number that could not be fixed.
  1. ;
  1. W !,"TOTAL FOUND: ",CNT,!,"FIXES MADE: ",FIXED,!,"FAILED TO MATCH: ",FAILED,!,"MATCHING PERCENTAGE: ",$J(CNT-FAILED/CNT*100,4,1),"%",! ;
  1. W !,"MISSING CLINICS MATCHED TO: " ;
  1. S CLINIC="" F S CLINIC=$O(CLINICSFND(CLINIC)) Q:CLINIC="" W ?30,CLINIC,?62,$J(CLINICSFND(CLINIC),$L(CNT))," = ",$J(CLINICSFND(CLINIC)/CNT*100,4,1),"%",! ;
  1. ;
  1. I REPORT="YES" D ^%ZISC K ZTDESC,ZTRTN,ZTSAVE,ZTSK ;
  1. Q ;
  1. ;
  1. UPDAPPT(APPT,RESOURCE,PTCANFLG,APPTCAN) ; Added last 2 parameters - 731 wtc 7/25/2019
  1. ;
  1. ; APPT = Appointment (pointer to #409.84) [REQUIRED]
  1. ; RESOURCE = Resource (pointer to #409.831) [REQUIRED]
  1. ; PTCANFLG = Patient appointment status (see field #1 in the appointment multiple in the patient file) [REQUIRED]
  1. ; APPTCAN = Appointment cancelled (1) or active (2). [REQUIRED]
  1. ;
  1. Q:$G(APPT)="" Q:$G(RESOURCE)="" Q:$G(APPTCAN)="" ;
  1. ;
  1. N DIE,DA,DR ;
  1. ;
  1. ; Assign resource to appointment file entry
  1. ;
  1. S DIE=409.84,DA=APPT,DR=".07///"_RESOURCE ;
  1. ;
  1. ; If patient appointment cancelled but appointment entry not cancelled, cancel the appointment entry. 731 wtc 7/26/2019
  1. ;
  1. I PTCANFLG="C"!(PTCANFLG="PC"),'APPTCAN D ;
  1. . ;
  1. . ; Get cancellation data from patient appointment and file in appointment file. WTC 9/10/2019
  1. . ;
  1. . N DATA,DFN,DTTM ;
  1. . S DATA=^SDEC(409.84,APPT,0),DFN=$P(DATA,U,5),DTTM=$P(DATA,U,1) ;
  1. . S DATA=^DPT(DFN,"S",DTTM,0) ;
  1. . S DR=DR_";.12///"_$S($P(DATA,U,14):"^S X="_$P(DATA,U,14),1:"NOW")_";.121///^S X="_$S($P(DATA,U,12):$P(DATA,U,12),1:DUZ) ;
  1. . S DR=DR_";.122///^S X="_$S($P(DATA,U,15):$P(DATA,U,15),1:11)_";.17///^S X="_$C(34)_PTCANFLG_$C(34) ;
  1. ;
  1. ; If patient appointment is active but appointment entry is cancelled, activate the appointment entry. 731 wtc 729/2019
  1. ;
  1. I PTCANFLG'="C",PTCANFLG'="PC",APPTCAN S DR=DR_";.12///@;.121///@;.122///@;.17///@" ;
  1. ;
  1. D ^DIE ;
  1. Q ;
  1. ;
  1. PTAPTINQ ;
  1. ;
  1. ; Display appointments for a patient and date range
  1. ;
  1. N DIC,Y,DFN,START,END,%DT ;
  1. ;
  1. S DIC(0)="AEQM",DIC=2 D ^DIC Q:Y<0 S DFN=+Y ;
  1. ;
  1. K %DT(0) S %DT="AEP",%DT("A")="Start date: " D ^%DT Q:Y<0 S START=Y ;
  1. S %DT="AEP",%DT("A")="End date: ",%DT(0)=START D ^%DT Q:Y<0 S END=Y+1 ;
  1. ;
  1. W !,"Patient: ",$$GET1^DIQ(2,DFN_",",.01)," (",DFN,")",! ;
  1. W "Appt Date/Time",?20,"Location",?50,"Status",!! ;
  1. S STARTTIME=START F S STARTTIME=$O(^DPT(DFN,"S",STARTTIME)) Q:'STARTTIME Q:STARTTIME>END S X=^(STARTTIME,0) D ; ICR 7030
  1. . ;
  1. . W $$FMTE^XLFDT(STARTTIME),?20,$$GET1^DIQ(44,$P(X,U,1)_",",.01),?50,$$SETOFCODES(2.98,3,$P(X,U,2)),! ;
  1. ;
  1. Q ;
  1. ;
  1. SETOFCODES(FILE,FIELD,VALUE) ;
  1. ;
  1. N DD,VALUES,RETURN,I ;
  1. ;
  1. S DD=^DD(FILE,FIELD,0),VALUES=$P(DD,U,3),RETURN="" ;
  1. F I=1:1 Q:$P(VALUES,";",I,99)="" I $P($P(VALUES,";",I),":",1)=VALUE S RETURN=$P($P(VALUES,";",I),":",2) Q ;
  1. Q RETURN ;
  1. ;
  1. MISMATCH ;
  1. ;
  1. ; Find encounters whose status does not match with the appointment status.
  1. ;
  1. N DFN,D1,ENCOUNTER,APPTDATA,ENCDATA,X,Y,START,NAME,COUNT ;
  1. ;
  1. K %DT S %DT="AEP",%DT("A")="Start date: " D ^%DT Q:Y<0 S START=Y W !! ;
  1. ;
  1. S NAME="" F S NAME=$O(^DPT("B",NAME)) Q:NAME="" S DFN=0 F S DFN=$O(^DPT("B",NAME,DFN)) Q:'DFN S D1=START-1 F S D1=$O(^DPT(DFN,"S",D1)) Q:'D1 S APPTDATA=^(D1,0),ENCOUNTER=$P(APPTDATA,U,20) I ENCOUNTER'="" D ; ICR 7030
  1. . ;
  1. . ; Compare status
  1. . ;
  1. . S X=$P(APPTDATA,U,2),Y=$$GET1^DIQ(409.68,ENCOUNTER_",",.12,"I") ;
  1. . I X="",Y=1!(Y=2) Q ; Checked in or checked out
  1. . I X="",Y=12 Q ; Non-count
  1. . I X="",Y=14 Q ; Action required
  1. . I X="N",Y=4 Q ; No show
  1. . I X="C",Y=5 Q ; Cancelled by clinic
  1. . I X="NA",Y=6 Q ; No show and auto-rebook
  1. . I X="CA",Y=7 Q ; Cancelled by clinic and auto re-book
  1. . I X="I",Y=8 Q ; Inpatient
  1. . I X="PC",Y=9 Q ; Cancelled by patient
  1. . I X="PCA",Y=10 Q ; Cancelled by patient and auto re-book
  1. . I X="NT",Y=3 Q ; No action taken
  1. . ;W $$GET1^DIQ(2,DFN_",",.01),?30,$$FMTE^XLFDT(D1),?50,"APPT: ",$$SETOFCODES(2.98,3,X),! ;
  1. . W NAME,?30,$$FMTE^XLFDT(D1),?50,"APPT: " W:X'="" $$SETOFCODES(2.98,3,X) W ! ;
  1. . W ?50," ENC: " W:Y'="" $$GET1^DIQ(409.63,Y_",",.01) W !! ;
  1. . I X="" S X="NULL" ;
  1. . I Y="" S Y="NULL" ;
  1. . S COUNT(X,Y)=$G(COUNT(X,Y))+1 ;
  1. ;
  1. TOTALS ;
  1. W !!,"APPOINTMENT STATUS",?25,"ENCOUNTER STATUS",?50,"COUNT",! ;
  1. W "------------------",?25,"----------------",?50,"-----",! ;
  1. S X="" F S X=$O(COUNT(X)) Q:X="" W !,$S(X="NULL":X,1:$$SETOFCODES(2.98,3,X)) S Y=0 F S Y=$O(COUNT(X,Y)) Q:'Y W ?25,$$GET1^DIQ(409.63,Y_",",.01),?50,COUNT(X,Y),! ;
  1. Q ;
  1. ;