SDCCRGAP ;CCRA/LB,PB - Appointment retrieval API;APR 4, 2019
;;5.3;Scheduling;**707**;APR 4, 2019;Build 57
;;Per VA directive 6402, this routine should not be modified.
Q
GETAPPT(PATIEN,APPTDT,APPTARY) ;Gets the appointment details form the database and returns it in an array.
; See parameter descriptions for details of the available nodes.
; PATIEN(I,REQ) - The patient IEN
; APPTDT(I,REQ) - the appointment date/time in vista format.
; Found in the ^DPT(<IEN>,"S",<APPTDT> node.
; APPTARY(O,REQ) - Array of appointment data.
;
; APPTARY("PATIENT IEN") - IEN
; APPTARY("APPTDT") = date/time of the appointment in VistA format
; APPTARY("APPTTYPE") - appointment type
; APPTARY("CANCEL REASON") - Cancellation reason (discrete)
; APPTARY("CANCEL REMARK") - Cancellation remark (freetext)
; APPTARY("CHECKIN DT") - date/time of the check in action
; APPTARY("CHECKIN USER") - check in user
; APPTARY("CHECKOUT DT") - date/time of the check out action
; APPTARY("CHECKOUT USER") - check out user
; APPTARY("CLINIC") = the clinic of this appointment
; APPTARY("CLINIC NAME") = Clinic name
; APPTARY("CLINIC PROVIDER",0) - number of providers on the clinic
; APPTARY("CLINIC PROVIDER",n,"IEN") - Provider IEN
; APPTARY("CLINIC PROVIDER",n,"NAME") - Name of provider
; APPTARY("CLINIC PURGED") - Flag to say the clinic has reached its
; purge days so the data is no longer available.
; APPTARY("CLINIC GROUP") - This is heavily covering our specialties.
; APPTARY("COMMENT") - Appointment comment.
; APPTARY("CONSULT") - linked consult ID
; APPTARY("COV") - The COV. Looking into what this is.
; APPTARY("DURATION") - appointment duration
; APPTARY("ENCOUNTER IEN") - Encounter ID
; APPTARY("ELIGIBILITY") - Appointment eligibility if different than primary
; APPTARY("Next Available") - If the appt was scheduled as next available
; APPTARY("PAT INDICATED DATE") - Date the start of search was performed on.
; APPTARY("STATUS") - APPT status calculated to current state
; (SCHEDULED/CHECKED IN/CHECKED OUT/CANCELLED/NO-SHOW)
; APPTARY("USER") - Scheduling user
;
N DELIM,CLNODE0,SNODE0,CLINIC,PROVARY,CLNODEC,CLNODECN
K APPTARY ;Force output only parameter
;
I $G(PATIEN)="" Q
I $G(APPTDT)="" Q
;
S DELIM="^"
S SNODE0=$$APPTNODE(PATIEN,APPTDT,0)
I $G(SNODE0)="" Q ;no appointment found
;
; Get clinic
S CLINIC=$P(SNODE0,DELIM,1)
S CLNODE0=$$CLINNODE(PATIEN,APPTDT,CLINIC,0)
S CLNODEC=$$CLINNODE(PATIEN,APPTDT,CLINIC,"C")
S CLNODECN=$$CLINNODE(PATIEN,APPTDT,CLINIC,"CONS")
;
; Get providers off of clinic
I $G(CLINIC)'="" D CLINPROV(CLINIC,.PROVARY)
;
; Build Array of patient information from the known nodes
S APPTARY("PATIENT IEN")=PATIEN ;IEN
S APPTARY("APPTDT")=APPTDT ;date/time of the appointment in VistA format
S APPTARY("APPTTYPE")=$P(SNODE0,DELIM,16) ;appointment type
S APPTARY("CLINIC")=$G(CLINIC) ;the clinic of this appointment ;
I $G(CLNODE0)="" S APPTARY("CLINIC PURGED")=1
I $D(PROVARY) M APPTARY("CLINIC PROVIDER")=PROVARY
S APPTARY("CLINIC NAME")=$$GET1^DIQ(44,$G(CLINIC),.01)
S APPTARY("CLINIC GROUP")=$$CLINGRP($G(CLINIC))
S APPTARY("CLINIC GROUP NAME")=$$GET1^DIQ(409.67,$G(APPTARY("CLINIC GROUP")),.01)
S APPTARY("CHECKIN DT")=$P($G(CLNODEC),DELIM,1)
S APPTARY("CHECKIN USER")=$P($G(CLNODEC),DELIM,2)
S APPTARY("CHECKOUT DT")=$P($G(CLNODEC),DELIM,3)
S APPTARY("CHECKOUT USER")=$P($G(CLNODEC),DELIM,4)
S APPTARY("COMMENT")=$P(CLNODE0,DELIM,4)
S APPTARY("CONSULT")=$$CLINNODE(PATIEN,APPTDT,CLINIC,"CONS") ;consult ID
S APPTARY("COV")=$P(SNODE0,DELIM,7) ;The COV if c&P/Scheduled/or walked in
S APPTARY("DURATION")=$P(CLNODE0,DELIM,2)
s APPTARY("ELIGIBILITY")=$P(CLNODE0,DELIM,10)
S APPTARY("PAT INDICATED DATE")=$$APTNODEP(PATIEN,APPTDT,1,1)
; APPT status - Computed and translated
S APPTARY("STATUS")=$$APTSTAT(PATIEN,APPTDT,0)
S APPTARY("STATUS PIECE")=$P(SNODE0,DELIM,2) ;Status from the status node
S APPTARY("USER")=$P(SNODE0,DELIM,18) ;Scheduling user
S APPTARY("CANCEL REASON")=$P(SNODE0,DELIM,15)
S APPTARY("CANCEL REMARK")=$$APTNODEP(PATIEN,APPTDT,"R",1)
S APPTARY("ENCOUNTER IEN")=$P(SNODE0,DELIM,20)
Q
APPTNODE(PATIEN,APPTDT,NODE) ;For a given patient we will return their appointment node in the ^DPT file.
; PATIEN(I,REQ) - The patient IEN
; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
; NODE(I,REQ) - node number to pull
;
I ($G(APPTDT)="")!($G(PATIEN)="")!($G(NODE)="") Q
Q $G(^DPT(PATIEN,"S",APPTDT,NODE))
APTNODEP(PATIEN,APPTDT,NODE,PIECE) ;For a given patient we will return a piece of their appointment node in the ^DPT file.
; PATIEN(I,REQ) - The patient IEN
; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
; NODE(I,REQ) - node number to pull
; PIECE(I,REQ) - piece in the node to return
; DATA(I,OPT) - data node may be passed in to bypass extracting.
N DATA
S DATA=$$APPTNODE($G(PATIEN),$G(APPTDT),$G(NODE))
Q $P($G(DATA),"^",$G(PIECE))
CLINNODE(PATIEN,APPTDT,CLINICIEN,NODE,COUNT) ;For a given patient we will find their clinic node in the ^SC file.
; May need to loop through the overbooks on that time.
; PATIEN(I,REQ) - The patient IEN
; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
; CLINICIEN(I,REQ) - clinic record IEN to search through
; NODE(I,REQ) - last node for the clinic. 0 node has appointment info. "C" node has check in/out info.
; COUNT(O,OPT) - subscript # of appointment
N RET
; Loop through the possibly multiple appointments scheduled into this clinic slot
S COUNT=$$FIND^SDAM2($G(PATIEN),$G(APPTDT),$G(CLINICIEN))
I $G(COUNT)'="" S RET=$G(^SC($G(CLINICIEN),"S",$G(APPTDT),1,COUNT,$G(NODE))) ;Get the node from the SC global
Q $G(RET)
CLINPROV(CLINIC,ARRAY) ;Sets an array filled with clinic provider data
; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
; ARRAY (O,REQ) - APPTARY("CLINIC PROVIDER",0) - number of providers on the clinic
; APPTARY("CLINIC PROVIDER",N,"IEN") - Provider IEN
; APPTARY("CLINIC PROVIDER",N,"NAME") - Name of provider
N NUM
K ARRAY
I $G(CLINIC)="" Q
S NUM=0
S ARRAY(0)=0
F S NUM=$O(^SC(CLINIC,"PR",NUM)) Q:'NUM D
. S ARRAY(NUM,"IEN")=$$PROVIEN(CLINIC,NUM) ;-Provider IEN File 200
. I ARRAY(NUM,"IEN")="" Q
. S ARRAY(NUM,"NAME")=$$GET1^DIQ(200,(ARRAY(NUM,"IEN")),.01) ;- Name of provider File 200
. S ARRAY(0)=ARRAY(0)+1
Q
PROVIEN(CLINIC,NODE) ;Returns the Nth provider ID for a Clinic
; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
; NODE (I,REQ) - The count of the node being examined
Q $P(^SC($G(CLINIC),"PR",$G(NODE),0),"^",1)
CLINGRP(CLINIC) ;Returns the ID of a Clinic's group
; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
Q $P(^SC($G(CLINIC),0),"^",31)
;---------
; DESCRIPTION:
; PARAMETERS:
;
;
;---------
APTSTAT(PATIEN,APPTDT,FULLSTAT) ;Returns current computed appointment status which
; includes checked in/out which the "S"0;2 node does not.
; PATIEN (I,REQ)- Patient ID as in DPT(PATIEN,"S",APPTDAT
; APPTDT (I,REQ) - Appointment date
; FULLSTAT (I,OPT,DEFAULT:"") - Set to 1 return full STATUS string
; OUTPUT: Appointment current Status values:
; SCHEDULED (Default)
; CHECKED IN
; CHECKED OUT
; CANCELLED
; NO-SHOW
; "" if the appointment does not exist.\
;
N RET,DPT0,CLINICID
I $G(PATIEN)="" Q ""
I $G(APPTDT)="" Q ""
;
;
S DPT0=$$APPTNODE(PATIEN,APPTDT,0)
I $G(DPT0)="" Q ""
;
;CLINIC ID IS FIRST PART OF DPT "S" 0 NODE
S CLINICID=+$G(DPT0)
I $G(CLINICID)="" Q ""
;
S RET=$$STATUS^SDAM1(PATIEN,APPTDT,CLINICID,DPT0)
I '$G(FULLSTAT) D
. S RET=$P(RET,";",3) ;PRINT STATUS- NOTE THAT THESE HAVE THE POSSIBILITY OF RETURNING MULTIPLE STATUSES
. S RET=$S(RET["CANCELLED":"CANCELLED",RET["NO-SHOW":"NO SHOW",RET["CHECKED OUT":"CHECKED OUT",RET["CHECKED IN":"CHECKED IN",1:"SCHEDULED")
Q RET
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDCCRGAP 8569 printed Nov 22, 2024@17:58:48 Page 2
SDCCRGAP ;CCRA/LB,PB - Appointment retrieval API;APR 4, 2019
+1 ;;5.3;Scheduling;**707**;APR 4, 2019;Build 57
+2 ;;Per VA directive 6402, this routine should not be modified.
+3 QUIT
GETAPPT(PATIEN,APPTDT,APPTARY) ;Gets the appointment details form the database and returns it in an array.
+1 ; See parameter descriptions for details of the available nodes.
+2 ; PATIEN(I,REQ) - The patient IEN
+3 ; APPTDT(I,REQ) - the appointment date/time in vista format.
+4 ; Found in the ^DPT(<IEN>,"S",<APPTDT> node.
+5 ; APPTARY(O,REQ) - Array of appointment data.
+6 ;
+7 ; APPTARY("PATIENT IEN") - IEN
+8 ; APPTARY("APPTDT") = date/time of the appointment in VistA format
+9 ; APPTARY("APPTTYPE") - appointment type
+10 ; APPTARY("CANCEL REASON") - Cancellation reason (discrete)
+11 ; APPTARY("CANCEL REMARK") - Cancellation remark (freetext)
+12 ; APPTARY("CHECKIN DT") - date/time of the check in action
+13 ; APPTARY("CHECKIN USER") - check in user
+14 ; APPTARY("CHECKOUT DT") - date/time of the check out action
+15 ; APPTARY("CHECKOUT USER") - check out user
+16 ; APPTARY("CLINIC") = the clinic of this appointment
+17 ; APPTARY("CLINIC NAME") = Clinic name
+18 ; APPTARY("CLINIC PROVIDER",0) - number of providers on the clinic
+19 ; APPTARY("CLINIC PROVIDER",n,"IEN") - Provider IEN
+20 ; APPTARY("CLINIC PROVIDER",n,"NAME") - Name of provider
+21 ; APPTARY("CLINIC PURGED") - Flag to say the clinic has reached its
+22 ; purge days so the data is no longer available.
+23 ; APPTARY("CLINIC GROUP") - This is heavily covering our specialties.
+24 ; APPTARY("COMMENT") - Appointment comment.
+25 ; APPTARY("CONSULT") - linked consult ID
+26 ; APPTARY("COV") - The COV. Looking into what this is.
+27 ; APPTARY("DURATION") - appointment duration
+28 ; APPTARY("ENCOUNTER IEN") - Encounter ID
+29 ; APPTARY("ELIGIBILITY") - Appointment eligibility if different than primary
+30 ; APPTARY("Next Available") - If the appt was scheduled as next available
+31 ; APPTARY("PAT INDICATED DATE") - Date the start of search was performed on.
+32 ; APPTARY("STATUS") - APPT status calculated to current state
+33 ; (SCHEDULED/CHECKED IN/CHECKED OUT/CANCELLED/NO-SHOW)
+34 ; APPTARY("USER") - Scheduling user
+35 ;
+36 NEW DELIM,CLNODE0,SNODE0,CLINIC,PROVARY,CLNODEC,CLNODECN
+37 ;Force output only parameter
KILL APPTARY
+38 ;
+39 IF $GET(PATIEN)=""
QUIT
+40 IF $GET(APPTDT)=""
QUIT
+41 ;
+42 SET DELIM="^"
+43 SET SNODE0=$$APPTNODE(PATIEN,APPTDT,0)
+44 ;no appointment found
IF $GET(SNODE0)=""
QUIT
+45 ;
+46 ; Get clinic
+47 SET CLINIC=$PIECE(SNODE0,DELIM,1)
+48 SET CLNODE0=$$CLINNODE(PATIEN,APPTDT,CLINIC,0)
+49 SET CLNODEC=$$CLINNODE(PATIEN,APPTDT,CLINIC,"C")
+50 SET CLNODECN=$$CLINNODE(PATIEN,APPTDT,CLINIC,"CONS")
+51 ;
+52 ; Get providers off of clinic
+53 IF $GET(CLINIC)'=""
DO CLINPROV(CLINIC,.PROVARY)
+54 ;
+55 ; Build Array of patient information from the known nodes
+56 ;IEN
SET APPTARY("PATIENT IEN")=PATIEN
+57 ;date/time of the appointment in VistA format
SET APPTARY("APPTDT")=APPTDT
+58 ;appointment type
SET APPTARY("APPTTYPE")=$PIECE(SNODE0,DELIM,16)
+59 ;the clinic of this appointment ;
SET APPTARY("CLINIC")=$GET(CLINIC)
+60 IF $GET(CLNODE0)=""
SET APPTARY("CLINIC PURGED")=1
+61 IF $DATA(PROVARY)
MERGE APPTARY("CLINIC PROVIDER")=PROVARY
+62 SET APPTARY("CLINIC NAME")=$$GET1^DIQ(44,$GET(CLINIC),.01)
+63 SET APPTARY("CLINIC GROUP")=$$CLINGRP($GET(CLINIC))
+64 SET APPTARY("CLINIC GROUP NAME")=$$GET1^DIQ(409.67,$GET(APPTARY("CLINIC GROUP")),.01)
+65 SET APPTARY("CHECKIN DT")=$PIECE($GET(CLNODEC),DELIM,1)
+66 SET APPTARY("CHECKIN USER")=$PIECE($GET(CLNODEC),DELIM,2)
+67 SET APPTARY("CHECKOUT DT")=$PIECE($GET(CLNODEC),DELIM,3)
+68 SET APPTARY("CHECKOUT USER")=$PIECE($GET(CLNODEC),DELIM,4)
+69 SET APPTARY("COMMENT")=$PIECE(CLNODE0,DELIM,4)
+70 ;consult ID
SET APPTARY("CONSULT")=$$CLINNODE(PATIEN,APPTDT,CLINIC,"CONS")
+71 ;The COV if c&P/Scheduled/or walked in
SET APPTARY("COV")=$PIECE(SNODE0,DELIM,7)
+72 SET APPTARY("DURATION")=$PIECE(CLNODE0,DELIM,2)
+73 SET APPTARY("ELIGIBILITY")=$PIECE(CLNODE0,DELIM,10)
+74 SET APPTARY("PAT INDICATED DATE")=$$APTNODEP(PATIEN,APPTDT,1,1)
+75 ; APPT status - Computed and translated
+76 SET APPTARY("STATUS")=$$APTSTAT(PATIEN,APPTDT,0)
+77 ;Status from the status node
SET APPTARY("STATUS PIECE")=$PIECE(SNODE0,DELIM,2)
+78 ;Scheduling user
SET APPTARY("USER")=$PIECE(SNODE0,DELIM,18)
+79 SET APPTARY("CANCEL REASON")=$PIECE(SNODE0,DELIM,15)
+80 SET APPTARY("CANCEL REMARK")=$$APTNODEP(PATIEN,APPTDT,"R",1)
+81 SET APPTARY("ENCOUNTER IEN")=$PIECE(SNODE0,DELIM,20)
+82 QUIT
APPTNODE(PATIEN,APPTDT,NODE) ;For a given patient we will return their appointment node in the ^DPT file.
+1 ; PATIEN(I,REQ) - The patient IEN
+2 ; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
+3 ; NODE(I,REQ) - node number to pull
+4 ;
+5 IF ($GET(APPTDT)="")!($GET(PATIEN)="")!($GET(NODE)="")
QUIT
+6 QUIT $GET(^DPT(PATIEN,"S",APPTDT,NODE))
APTNODEP(PATIEN,APPTDT,NODE,PIECE) ;For a given patient we will return a piece of their appointment node in the ^DPT file.
+1 ; PATIEN(I,REQ) - The patient IEN
+2 ; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
+3 ; NODE(I,REQ) - node number to pull
+4 ; PIECE(I,REQ) - piece in the node to return
+5 ; DATA(I,OPT) - data node may be passed in to bypass extracting.
+6 NEW DATA
+7 SET DATA=$$APPTNODE($GET(PATIEN),$GET(APPTDT),$GET(NODE))
+8 QUIT $PIECE($GET(DATA),"^",$GET(PIECE))
CLINNODE(PATIEN,APPTDT,CLINICIEN,NODE,COUNT) ;For a given patient we will find their clinic node in the ^SC file.
+1 ; May need to loop through the overbooks on that time.
+2 ; PATIEN(I,REQ) - The patient IEN
+3 ; APPTDT(I,REQ) - the appointment date/time in vista format. Found in the ^DPT(<IEN>,"S",<APPTDT> node.
+4 ; CLINICIEN(I,REQ) - clinic record IEN to search through
+5 ; NODE(I,REQ) - last node for the clinic. 0 node has appointment info. "C" node has check in/out info.
+6 ; COUNT(O,OPT) - subscript # of appointment
+7 NEW RET
+8 ; Loop through the possibly multiple appointments scheduled into this clinic slot
+9 SET COUNT=$$FIND^SDAM2($GET(PATIEN),$GET(APPTDT),$GET(CLINICIEN))
+10 ;Get the node from the SC global
IF $GET(COUNT)'=""
SET RET=$GET(^SC($GET(CLINICIEN),"S",$GET(APPTDT),1,COUNT,$GET(NODE)))
+11 QUIT $GET(RET)
CLINPROV(CLINIC,ARRAY) ;Sets an array filled with clinic provider data
+1 ; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
+2 ; ARRAY (O,REQ) - APPTARY("CLINIC PROVIDER",0) - number of providers on the clinic
+3 ; APPTARY("CLINIC PROVIDER",N,"IEN") - Provider IEN
+4 ; APPTARY("CLINIC PROVIDER",N,"NAME") - Name of provider
+5 NEW NUM
+6 KILL ARRAY
+7 IF $GET(CLINIC)=""
QUIT
+8 SET NUM=0
+9 SET ARRAY(0)=0
+10 FOR
SET NUM=$ORDER(^SC(CLINIC,"PR",NUM))
if 'NUM
QUIT
Begin DoDot:1
+11 ;-Provider IEN File 200
SET ARRAY(NUM,"IEN")=$$PROVIEN(CLINIC,NUM)
+12 IF ARRAY(NUM,"IEN")=""
QUIT
+13 ;- Name of provider File 200
SET ARRAY(NUM,"NAME")=$$GET1^DIQ(200,(ARRAY(NUM,"IEN")),.01)
+14 SET ARRAY(0)=ARRAY(0)+1
End DoDot:1
+15 QUIT
PROVIEN(CLINIC,NODE) ;Returns the Nth provider ID for a Clinic
+1 ; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
+2 ; NODE (I,REQ) - The count of the node being examined
+3 QUIT $PIECE(^SC($GET(CLINIC),"PR",$GET(NODE),0),"^",1)
CLINGRP(CLINIC) ;Returns the ID of a Clinic's group
+1 ; CLINIC (I,REQ) - The Clinic IEN (first piece of DPT 0 node)
+2 QUIT $PIECE(^SC($GET(CLINIC),0),"^",31)
+3 ;---------
+4 ; DESCRIPTION:
+5 ; PARAMETERS:
+6 ;
+7 ;
+8 ;---------
APTSTAT(PATIEN,APPTDT,FULLSTAT) ;Returns current computed appointment status which
+1 ; includes checked in/out which the "S"0;2 node does not.
+2 ; PATIEN (I,REQ)- Patient ID as in DPT(PATIEN,"S",APPTDAT
+3 ; APPTDT (I,REQ) - Appointment date
+4 ; FULLSTAT (I,OPT,DEFAULT:"") - Set to 1 return full STATUS string
+5 ; OUTPUT: Appointment current Status values:
+6 ; SCHEDULED (Default)
+7 ; CHECKED IN
+8 ; CHECKED OUT
+9 ; CANCELLED
+10 ; NO-SHOW
+11 ; "" if the appointment does not exist.\
+12 ;
+13 NEW RET,DPT0,CLINICID
+14 IF $GET(PATIEN)=""
QUIT ""
+15 IF $GET(APPTDT)=""
QUIT ""
+16 ;
+17 ;
+18 SET DPT0=$$APPTNODE(PATIEN,APPTDT,0)
+19 IF $GET(DPT0)=""
QUIT ""
+20 ;
+21 ;CLINIC ID IS FIRST PART OF DPT "S" 0 NODE
+22 SET CLINICID=+$GET(DPT0)
+23 IF $GET(CLINICID)=""
QUIT ""
+24 ;
+25 SET RET=$$STATUS^SDAM1(PATIEN,APPTDT,CLINICID,DPT0)
+26 IF '$GET(FULLSTAT)
Begin DoDot:1
+27 ;PRINT STATUS- NOTE THAT THESE HAVE THE POSSIBILITY OF RETURNING MULTIPLE STATUSES
SET RET=$PIECE(RET,";",3)
+28 SET RET=$SELECT(RET["CANCELLED":"CANCELLED",RET["NO-SHOW":"NO SHOW",RET["CHECKED OUT":"CHECKED OUT",RET["CHECKED IN":"CHECKED IN",1:"SCHEDULED")
End DoDot:1
+29 QUIT RET
+30 ;