BEHOPGAP ;IHS/MSC/MGH - PATIENT GOALS APIs;05-Dec-2011 13:44;DU
;;1.1;BEH COMPONENTS;**058001**;MAY 14, 2009;Build 2
;
;
ADDGOAL(RETVAL,DFN,GDAT) ;PEP -- add Patient Goal
;This API is called to add a new entry to the PATIENT GOALS file
;Input:
; - DFN = Patient DFN
; - GDAT = array of field data
; Details:
; DATA(0)=?GOAL?^ GOAL SET STATUS^WHERE SET^GOAL NUMBER^PROVIDER^START DATE^FOLLOWUP DATE^ USER
; DATA(1)=?TYPE?^ GOAL TYPE^GOAL TYPE^GOAL TYPE ETC ēGOAL TYPES ARE FROM A SEPARATE FILE
; DATA(2)=?NAME?^GOAL NAME (FREE TEXT)
; DATA(3)=?REASON?^GOAL REASON(FREE TEXT)
; note: field .11 is always stuffed with A (Active) on an add so no need to pass in that field value
; note: field .02 is always stuffed with the value of DFN
; note: fields .03 and .05 are stuffed with DT and $$NOW
; note: fields .04 and .12 area stuffed with DUZ
;
; - RETVAL = string that returns value of call success/failure
;
;RETURN VALUE - RETVAL=ien of patient goal entry created OR 0^error message
;
;
S RETVAL=""
N GARRAY,I,J,DATA,FAC
S I="" F S I=$O(GDAT(I)) Q:I="" D
.I $P($G(GDAT(I)),U,1)="GOAL" D
..S DATA=$G(GDAT(I))
..S GARRAY(".01",1)=$P(DATA,U,2) ;goal set status
..I $P(DATA,U,3)="" S GARRAY(".06",1)=+$G(DUZ(2))
..E S GARRAY(".06",1)=$P(DATA,U,3) ;facility, DUZ(2) used if not sent
..S GARRAY(".07",1)=$P(DATA,U,4) ;goal number
..S GARRAY(".08",1)=$P(DATA,U,5) ;provider documenting, DUZ used if not sent
..S GARRAY(".09",1)=$P(DATA,U,6) ;goal start date ,date only
..S GARRAY(".1",1)=$P(DATA,U,7) ;goal followup date ,date only
..S GARRAY(".12",1)=$P(DATA,U,8) ;user last updated, DUZ used if not sent
.I $P($G(GDAT(I)),U,1)="TYPE" D
..S J=2 F S TYPE=$P($G(GDAT(I)),U,J) Q:TYPE="" D
...S GARRAY("1000",J-1)=TYPE ;goal type can be multiple
...S J=J+1
.I $P($G(GDAT(I)),U,1)="NAME" D ;goal name
..S GARRAY("1101",1)=$P($G(GDAT(I)),U,2)
.I $P($G(GDAT(I)),U,1)="REASON" D ;goal reason
..S GARRAY("1201",1)=$P($G(GDAT(I)),U,2)
D ADDGOAL^APCDGAPI(DFN,.GARRAY,.RETVAL)
I +RETVAL=0 D
.I $P(RETVAL,U,1)'=0 S RETVAL=0_U_RETVAL
Q
DELGOAL(RETVAL,GIEN,PRV,DDTE,DREA,DOTHER) ;PEP - called to delete a goal
;marks the goal status as "deleted", does not physically delete the goal
;INPUT -
; GIEN=goal IEN
; PRV= Provider who deleted goal uses DUZ if not passed
; DDTE=Date deleted, uses NOW If nothing passed
; DREA=Reason deleted (set of codes)
; DOTHER=Text if reason chosen is other
;
;OUTPUT - return value is 1 if delete successful or 0^error message if not successful
I '$G(GIEN) S RETVAL="0^invalid ien" Q
N APCDGIEN
S APCDGIEN=GIEN
I (DREA="O"!(DREA="OTHER"))&(DOTHER="") S RETVAL="0^Other delete reason needs a comment" Q
D DELGOAL^APCDGAPI(APCDGIEN,PRV,DDTE,DREA,DOTHER,.RETVAL)
Q
EDITGOAL(RETVAL,GIEN,FUD,STAT,REVD,REVT) ;PEP- edit a goal entry
;only the following fields can be edited per requirements: F/U DATE (.09), STATUS (.11)
;you can also add a review date and review/follow up text, to edit a review comment use EDITREV API
;INPUT :
; GIEN=ien of goal
; FUD= new followup date
; STAT= new status
; REVD= review date (optional)
; REVT= review comment (optional)
; if adding a review both review date and comment are required, if both are not passed they
; are ignored
;OUTPUT : 1 if edit successful, 0^error message if not successful
;
S RETVAL=""
I '$G(GIEN) S RETVAL="0^invalid ien" Q
S REVD=$G(REVD)
S REVT=$G(REVT)
D EDITGOAL^APCDGAPI(GIEN,FUD,STAT,REVD,REVT,.RETVAL)
I RETVAL="" S RETVAL=1
Q
;
NEXTGN(RET,DFN,FAC) ;PEP - return next available goal number for patient P, facility F
S RET=$$NEXTGN^APCDGAPI(DFN,FAC)
Q
;
GETGOAL(RET,DFN) ;PEP Return a list of a patient's goals
; (goal no,0)=IEN(1)^GSET(2)^CREATED(3)^BY(4)^LASTMODIFIED(5)^FACILITY(6)
; ^PROVIDER(7)^STARTDT(8)^FOLLOWUPDT(9)^STATUS(10)^GOAL NUMBER (11)
; (goal no,10)=TYPE1^TYPE2^TYPE3...
; (goal no,11)=GOALNAME
; (goal no,12)=GOALREASON
; (goal no,13,n)=REVIEW DATE(1)^NOTE(2)
N GRIEN,FILE,FIELDS,IEN,ARRAY,ERRARRY,GNAME,GTYP,CNT,SFAC,REV,REVDT,REVTXT,CNT,TIEN
N GSET,GOALNO,GDATE,GBY,GMOD,GFAC,GPROV,GSTART,GFUP,GSTAT,GTYPE,GREASON,GSTATE
S FILE=9000093
S RET=$$TMPGBL,GRIEN=""
F S GRIEN=$O(^AUPNGOAL("AC",DFN,GRIEN)) Q:'GRIEN D
.S IEN=GRIEN_","
.;Get all the data that is needed for the zero nodes
.D GETS^DIQ(FILE,GRIEN,"*","IE","ARRAY","ERRARRY")
.S GSET=$G(ARRAY(FILE,IEN,.01,"E"))
.S GDATE=$G(ARRAY(FILE,IEN,.03,"I"))
.S GBY=$G(ARRAY(FILE,IEN,.04,"E"))
.S GMOD=$G(ARRAY(FILE,IEN,.05,"I"))
.S GFAC=$G(ARRAY(FILE,IEN,.06,"E"))
.S GOALNO=$G(ARRAY(FILE,IEN,.07,"E"))
.S GPROV=$G(ARRAY(FILE,IEN,.08,"E"))
.S GSTART=$G(ARRAY(FILE,IEN,.09,"I"))
.S GFUP=$G(ARRAY(FILE,IEN,.1,"I"))
.S GSTAT=$G(ARRAY(FILE,IEN,.11,"I"))
.S GSTATE=$G(ARRAY(FILE,IEN,.11,"E"))
.I GSTAT'="" S GSTAT=GSTAT_";"_GSTATE
.Q:GSTAT="D"
.;Get the text needed for the 11 and 12 nodes
.S GNAME=$G(ARRAY(FILE,IEN,1101,"E"))
.S GREASON=$G(ARRAY(FILE,IEN,1201,"E"))
.S @RET@(GOALNO,0)=GRIEN_U_GSET_U_GDATE_U_GBY_U_GMOD_U_GFAC_U_GPROV_U_GSTART_U_GFUP_U_GSTAT_U_GOALNO
.;Get the data from the goal type multiple (goals may have more than 1 type)
.S GTYPE=""
.S TIEN=0 F S TIEN=$O(^AUPNGOAL(GRIEN,10,TIEN)) Q:'+TIEN D
..S GTYP=$G(^AUPNGOAL(GRIEN,10,TIEN,0))
..I GTYPE="" S GTYPE=$P($G(^APCDTPGT(GTYP,0)),U,1)
..E S GTYPE=GTYPE_U_$P($G(^APCDTPGT(GTYP,0)),U,1)
.S @RET@(GOALNO,10)=GTYPE
.S @RET@(GOALNO,11)=GNAME
.S @RET@(GOALNO,12)=GREASON
.S CNT=0,REV=0 F S REV=$O(^AUPNGOAL(GRIEN,13,REV)) Q:'+REV D
..S REVDT=$P($G(^AUPNGOAL(GRIEN,13,REV,0)),U,1)
..S REVTXT=$P($G(^AUPNGOAL(GRIEN,13,REV,0)),U,2)
..S CNT=CNT+1
..S @RET@(GOALNO,13,CNT)="REVIEW"_U_REVDT_U_REVTXT
Q
GETSTEP(RET,GIEN) ;Get the step data
;Input GIEN=goal IEN
;Ouptut global array of steps for a particular goal
;format equals
;zero node=Goal ien [1] ^ facility [2] ^ step ien [3] ^ Step number [4] ^ Created by [5] ^ created date [6] ^
;Step type [7] ^ step start dt [8] ^ step followup date [9] ^ user last modififed [10] ^ last modified date [11]
;^ step status [12] ^ provider [13]
;one node= Step text
N FILE,SFAC,CNT
S FILE=9000093,CNT=0
S RET=$$TMPGBL
S SFAC=0 F S SFAC=$O(^AUPNGOAL(GIEN,21,SFAC)) Q:'+SFAC D
.S FAC=$P($G(^AUPNGOAL(GIEN,21,SFAC,0)),U,1)
.S FNAME=$P($G(^DIC(4,FAC,0)),U,1)
.D STEPS(GIEN,SFAC,FAC,FNAME)
Q
STEPS(GOAL,SFAC,FAC,FNAME) ;Get the step data for each goal
N SIEN,LKP,GFLDS,FILE1,GDATA,GERR,STATUS
N STEPNO,SBY,SWHEN,STYPE,SSTART,SFUP,SUPD,SMOD,SSTATUS,SPROV,STEXT
S SIEN=0 F S SIEN=$O(^AUPNGOAL(GOAL,21,SFAC,11,SIEN)) Q:'+SIEN D
.S LKP=SIEN_","_SFAC_","_GOAL_",",FILE1=9000093.211101
.S STEPNO=$$GET1^DIQ(FILE1,LKP,".01")
.S SBY=$$GET1^DIQ(FILE1,LKP,".02")
.S SWHEN=$$GET1^DIQ(FILE1,LKP,".03","I")
.S STYPE=$$GET1^DIQ(FILE1,LKP,".04")
.S SSTART=$$GET1^DIQ(FILE1,LKP,".05","I")
.S SFUP=$$GET1^DIQ(FILE1,LKP,".06","I")
.S SUPD=$$GET1^DIQ(FILE1,LKP,".07")
.S SMOD=$$GET1^DIQ(FILE1,LKP,".08","I")
.S SSTATUS=$$GET1^DIQ(FILE1,LKP,".09")
.Q:SSTATUS="DELETED"
.S STATUS=$$GET1^DIQ(FILE1,LKP,".09","I")
.S SPROV=$$GET1^DIQ(FILE1,LKP,".1")
.S @RET@(SIEN,0)=GIEN_U_FAC_";"_FNAME_U_SIEN_U_STEPNO_U_SBY_U_SWHEN_U_STYPE_U_SSTART_U_SFUP_U_SUPD_U_SMOD_U_STATUS_";"_SSTATUS_U_SPROV
.S STEXT=$$GET1^DIQ(FILE1,LKP,1101)
.S @RET@(SIEN,1)=STEXT
Q
ADDREV(RETVAL,GIEN,REVD,REVT) ;PEP - ADD A REVIEW TO A GOAL 9000093.13
;INPUT:
;GIEN= ien of goal
;REVD= review date
;REVT= review text
;OUTPUT: ien of review entry in multiple or 0^error text
;
I '$G(GIEN) S RETVAL="0^invalid ien" Q
D ADDREV^APCDGAP2(GIEN,REVD,REVT,.RETVAL)
Q
;
ADDSTEP(RETVAL,GIEN,SDAT) ;PEP - add a step to a goal
;Add a Step to an existing goal
; SDAT - array of steps to be added if adding steps
; SDAT(n)=facility^step number^step type^step start date^step f/u date^provider^step text
; one entry in array for each step being added
; step number is optional, if not passed the next available step number will be used
; values can be internal or external
; user created / user last update fields auto stuffed with DUZ
; date created / date last updated fields auto stuffed with DT and NOW^XLFDT
;
; Example:
; SDAT(1)="5217^1^NUTRITION^3101029^3101231^1239^EAT LESS THAN 1200 CAAPCDTESTES PER DAY
; SDAT(2)="5217^2^PHYSICAL ACTIVITY^3101029^3101231^1239^WALK 60 MINUTES PER DAY
N I,J,SDAT2
S I="" F S I=$O(SDAT(I)) Q:I="" D
.S J=I+1
.S SDAT2(J)=SDAT(I)
D ADDSTEP^APCDGAP2(GIEN,.SDAT2,.RETVAL)
S RETVAL=RETVAL(1)
Q
DELSTEP(RET,GIEN,LIEN,SIEN,PRV,SDTE,SREA,SOTHER) ;PEP - DELETE A STEP
;delete a step
; INP =
; GIEN=Goal IEN
; LINE=Location
; SIEN=Step IEN
; PRV= Who deleted (defaults to DUZ if not sent)
; SDTE= When deleted (defaults to NOW If not sent)
; SREA= Reason deleted (set of codes)
; SOTHER=Text if reason is other
; OUTPUT = 1 if delete successful or 0^error message
S RET=""
I '$G(GIEN) S RET="0^invalid goal ien" Q
S SOTHER=$G(SOTHER)
S X=SDTE D ^%DT S SDTE=Y
I (SREA="O"!(SREA="OTHER"))&(SOTHER="") S RET="0^Text must be sent with OTHER reason" Q
D DELSTEP^APCDGAP2(GIEN,LIEN,SIEN,PRV,SDTE,SREA,SOTHER,.RET)
Q
EDITSTEP(RETVAL,GIEN,LIEN,SIEN,FUD,STAT) ;PEP - edit a step entry
;edit a step entry
;per requirements only the followup date and status can be edited
;INPUT:
; GIEN=goal ien
; LIEN=location ien
; SIEN=Step ien
; FUD= new f/u date
; STAT=status
;OUTPUT: 1 if edit successful, 0^error message if not successful
I '$G(GIEN) S RETVAL="0^invalid ien" Q
D EDITSTEP^APCDGAP2(GIEN,LIEN,SIEN,FUD,STAT,.RETVAL)
Q
NEXTSN(RET,GIEN,FAC) ;PEP - return next step number for this goal, facility
S RET=$$NEXTSN^APCDGAP2(GIEN,FAC)
Q
TMPGBL() ;EP
K ^TMP("BEHOGOAL",$J) Q $NA(^($J))
BEHOPGAP ;IHS/MSC/MGH - PATIENT GOALS APIs;05-Dec-2011 13:44;DU
+1 ;;1.1;BEH COMPONENTS;**058001**;MAY 14, 2009;Build 2
+2 ;
+3 ;
ADDGOAL(RETVAL,DFN,GDAT) ;PEP -- add Patient Goal
+1 ;This API is called to add a new entry to the PATIENT GOALS file
+2 ;Input:
+3 ; - DFN = Patient DFN
+4 ; - GDAT = array of field data
+5 ; Details:
+6 ; DATA(0)=?GOAL?^ GOAL SET STATUS^WHERE SET^GOAL NUMBER^PROVIDER^START DATE^FOLLOWUP DATE^ USER
+7 ; DATA(1)=?TYPE?^ GOAL TYPE^GOAL TYPE^GOAL TYPE ETC ƧGOAL TYPES ARE FROM A SEPARATE FILE
+8 ; DATA(2)=?NAME?^GOAL NAME (FREE TEXT)
+9 ; DATA(3)=?REASON?^GOAL REASON(FREE TEXT)
+10 ; note: field .11 is always stuffed with A (Active) on an add so no need to pass in that field value
+11 ; note: field .02 is always stuffed with the value of DFN
+12 ; note: fields .03 and .05 are stuffed with DT and $$NOW
+13 ; note: fields .04 and .12 area stuffed with DUZ
+14 ;
+15 ; - RETVAL = string that returns value of call success/failure
+16 ;
+17 ;RETURN VALUE - RETVAL=ien of patient goal entry created OR 0^error message
+18 ;
+19 ;
+20 SET RETVAL=""
+21 NEW GARRAY,I,J,DATA,FAC
+22 SET I=""
FOR
SET I=$ORDER(GDAT(I))
IF I=""
QUIT
Begin DoDot:1
+23 IF $PIECE($GET(GDAT(I)),U,1)="GOAL"
Begin DoDot:2
+24 SET DATA=$GET(GDAT(I))
+25 ;goal set status
SET GARRAY(".01",1)=$PIECE(DATA,U,2)
+26 IF $PIECE(DATA,U,3)=""
SET GARRAY(".06",1)=+$GET(DUZ(2))
+27 ;facility, DUZ(2) used if not sent
IF '$TEST
SET GARRAY(".06",1)=$PIECE(DATA,U,3)
+28 ;goal number
SET GARRAY(".07",1)=$PIECE(DATA,U,4)
+29 ;provider documenting, DUZ used if not sent
SET GARRAY(".08",1)=$PIECE(DATA,U,5)
+30 ;goal start date ,date only
SET GARRAY(".09",1)=$PIECE(DATA,U,6)
+31 ;goal followup date ,date only
SET GARRAY(".1",1)=$PIECE(DATA,U,7)
+32 ;user last updated, DUZ used if not sent
SET GARRAY(".12",1)=$PIECE(DATA,U,8)
End DoDot:2
+33 IF $PIECE($GET(GDAT(I)),U,1)="TYPE"
Begin DoDot:2
+34 SET J=2
FOR
SET TYPE=$PIECE($GET(GDAT(I)),U,J)
IF TYPE=""
QUIT
Begin DoDot:3
+35 ;goal type can be multiple
SET GARRAY("1000",J-1)=TYPE
+36 SET J=J+1
End DoDot:3
End DoDot:2
+37 ;goal name
IF $PIECE($GET(GDAT(I)),U,1)="NAME"
Begin DoDot:2
+38 SET GARRAY("1101",1)=$PIECE($GET(GDAT(I)),U,2)
End DoDot:2
+39 ;goal reason
IF $PIECE($GET(GDAT(I)),U,1)="REASON"
Begin DoDot:2
+40 SET GARRAY("1201",1)=$PIECE($GET(GDAT(I)),U,2)
End DoDot:2
End DoDot:1
+41 DO ADDGOAL^APCDGAPI(DFN,.GARRAY,.RETVAL)
+42 IF +RETVAL=0
Begin DoDot:1
+43 IF $PIECE(RETVAL,U,1)'=0
SET RETVAL=0_U_RETVAL
End DoDot:1
+44 QUIT
DELGOAL(RETVAL,GIEN,PRV,DDTE,DREA,DOTHER) ;PEP - called to delete a goal
+1 ;marks the goal status as "deleted", does not physically delete the goal
+2 ;INPUT -
+3 ; GIEN=goal IEN
+4 ; PRV= Provider who deleted goal uses DUZ if not passed
+5 ; DDTE=Date deleted, uses NOW If nothing passed
+6 ; DREA=Reason deleted (set of codes)
+7 ; DOTHER=Text if reason chosen is other
+8 ;
+9 ;OUTPUT - return value is 1 if delete successful or 0^error message if not successful
+10 IF '$GET(GIEN)
SET RETVAL="0^invalid ien"
QUIT
+11 NEW APCDGIEN
+12 SET APCDGIEN=GIEN
+13 IF (DREA="O"!(DREA="OTHER"))&(DOTHER="")
SET RETVAL="0^Other delete reason needs a comment"
QUIT
+14 DO DELGOAL^APCDGAPI(APCDGIEN,PRV,DDTE,DREA,DOTHER,.RETVAL)
+15 QUIT
EDITGOAL(RETVAL,GIEN,FUD,STAT,REVD,REVT) ;PEP- edit a goal entry
+1 ;only the following fields can be edited per requirements: F/U DATE (.09), STATUS (.11)
+2 ;you can also add a review date and review/follow up text, to edit a review comment use EDITREV API
+3 ;INPUT :
+4 ; GIEN=ien of goal
+5 ; FUD= new followup date
+6 ; STAT= new status
+7 ; REVD= review date (optional)
+8 ; REVT= review comment (optional)
+9 ; if adding a review both review date and comment are required, if both are not passed they
+10 ; are ignored
+11 ;OUTPUT : 1 if edit successful, 0^error message if not successful
+12 ;
+13 SET RETVAL=""
+14 IF '$GET(GIEN)
SET RETVAL="0^invalid ien"
QUIT
+15 SET REVD=$GET(REVD)
+16 SET REVT=$GET(REVT)
+17 DO EDITGOAL^APCDGAPI(GIEN,FUD,STAT,REVD,REVT,.RETVAL)
+18 IF RETVAL=""
SET RETVAL=1
+19 QUIT
+20 ;
NEXTGN(RET,DFN,FAC) ;PEP - return next available goal number for patient P, facility F
+1 SET RET=$$NEXTGN^APCDGAPI(DFN,FAC)
+2 QUIT
+3 ;
GETGOAL(RET,DFN) ;PEP Return a list of a patient's goals
+1 ; (goal no,0)=IEN(1)^GSET(2)^CREATED(3)^BY(4)^LASTMODIFIED(5)^FACILITY(6)
+2 ; ^PROVIDER(7)^STARTDT(8)^FOLLOWUPDT(9)^STATUS(10)^GOAL NUMBER (11)
+3 ; (goal no,10)=TYPE1^TYPE2^TYPE3...
+4 ; (goal no,11)=GOALNAME
+5 ; (goal no,12)=GOALREASON
+6 ; (goal no,13,n)=REVIEW DATE(1)^NOTE(2)
+7 NEW GRIEN,FILE,FIELDS,IEN,ARRAY,ERRARRY,GNAME,GTYP,CNT,SFAC,REV,REVDT,REVTXT,CNT,TIEN
+8 NEW GSET,GOALNO,GDATE,GBY,GMOD,GFAC,GPROV,GSTART,GFUP,GSTAT,GTYPE,GREASON,GSTATE
+9 SET FILE=9000093
+10 SET RET=$$TMPGBL
SET GRIEN=""
+11 FOR
SET GRIEN=$ORDER(^AUPNGOAL("AC",DFN,GRIEN))
IF 'GRIEN
QUIT
Begin DoDot:1
+12 SET IEN=GRIEN_","
+13 ;Get all the data that is needed for the zero nodes
+14 DO GETS^DIQ(FILE,GRIEN,"*","IE","ARRAY","ERRARRY")
+15 SET GSET=$GET(ARRAY(FILE,IEN,.01,"E"))
+16 SET GDATE=$GET(ARRAY(FILE,IEN,.03,"I"))
+17 SET GBY=$GET(ARRAY(FILE,IEN,.04,"E"))
+18 SET GMOD=$GET(ARRAY(FILE,IEN,.05,"I"))
+19 SET GFAC=$GET(ARRAY(FILE,IEN,.06,"E"))
+20 SET GOALNO=$GET(ARRAY(FILE,IEN,.07,"E"))
+21 SET GPROV=$GET(ARRAY(FILE,IEN,.08,"E"))
+22 SET GSTART=$GET(ARRAY(FILE,IEN,.09,"I"))
+23 SET GFUP=$GET(ARRAY(FILE,IEN,.1,"I"))
+24 SET GSTAT=$GET(ARRAY(FILE,IEN,.11,"I"))
+25 SET GSTATE=$GET(ARRAY(FILE,IEN,.11,"E"))
+26 IF GSTAT'=""
SET GSTAT=GSTAT_";"_GSTATE
+27 IF GSTAT="D"
QUIT
+28 ;Get the text needed for the 11 and 12 nodes
+29 SET GNAME=$GET(ARRAY(FILE,IEN,1101,"E"))
+30 SET GREASON=$GET(ARRAY(FILE,IEN,1201,"E"))
+31 SET @RET@(GOALNO,0)=GRIEN_U_GSET_U_GDATE_U_GBY_U_GMOD_U_GFAC_U_GPROV_U_GSTART_U_GFUP_U_GSTAT_U_GOALNO
+32 ;Get the data from the goal type multiple (goals may have more than 1 type)
+33 SET GTYPE=""
+34 SET TIEN=0
FOR
SET TIEN=$ORDER(^AUPNGOAL(GRIEN,10,TIEN))
IF '+TIEN
QUIT
Begin DoDot:2
+35 SET GTYP=$GET(^AUPNGOAL(GRIEN,10,TIEN,0))
+36 IF GTYPE=""
SET GTYPE=$PIECE($GET(^APCDTPGT(GTYP,0)),U,1)
+37 IF '$TEST
SET GTYPE=GTYPE_U_$PIECE($GET(^APCDTPGT(GTYP,0)),U,1)
End DoDot:2
+38 SET @RET@(GOALNO,10)=GTYPE
+39 SET @RET@(GOALNO,11)=GNAME
+40 SET @RET@(GOALNO,12)=GREASON
+41 SET CNT=0
SET REV=0
FOR
SET REV=$ORDER(^AUPNGOAL(GRIEN,13,REV))
IF '+REV
QUIT
Begin DoDot:2
+42 SET REVDT=$PIECE($GET(^AUPNGOAL(GRIEN,13,REV,0)),U,1)
+43 SET REVTXT=$PIECE($GET(^AUPNGOAL(GRIEN,13,REV,0)),U,2)
+44 SET CNT=CNT+1
+45 SET @RET@(GOALNO,13,CNT)="REVIEW"_U_REVDT_U_REVTXT
End DoDot:2
End DoDot:1
+46 QUIT
GETSTEP(RET,GIEN) ;Get the step data
+1 ;Input GIEN=goal IEN
+2 ;Ouptut global array of steps for a particular goal
+3 ;format equals
+4 ;zero node=Goal ien [1] ^ facility [2] ^ step ien [3] ^ Step number [4] ^ Created by [5] ^ created date [6] ^
+5 ;Step type [7] ^ step start dt [8] ^ step followup date [9] ^ user last modififed [10] ^ last modified date [11]
+6 ;^ step status [12] ^ provider [13]
+7 ;one node= Step text
+8 NEW FILE,SFAC,CNT
+9 SET FILE=9000093
SET CNT=0
+10 SET RET=$$TMPGBL
+11 SET SFAC=0
FOR
SET SFAC=$ORDER(^AUPNGOAL(GIEN,21,SFAC))
IF '+SFAC
QUIT
Begin DoDot:1
+12 SET FAC=$PIECE($GET(^AUPNGOAL(GIEN,21,SFAC,0)),U,1)
+13 SET FNAME=$PIECE($GET(^DIC(4,FAC,0)),U,1)
+14 DO STEPS(GIEN,SFAC,FAC,FNAME)
End DoDot:1
+15 QUIT
STEPS(GOAL,SFAC,FAC,FNAME) ;Get the step data for each goal
+1 NEW SIEN,LKP,GFLDS,FILE1,GDATA,GERR,STATUS
+2 NEW STEPNO,SBY,SWHEN,STYPE,SSTART,SFUP,SUPD,SMOD,SSTATUS,SPROV,STEXT
+3 SET SIEN=0
FOR
SET SIEN=$ORDER(^AUPNGOAL(GOAL,21,SFAC,11,SIEN))
IF '+SIEN
QUIT
Begin DoDot:1
+4 SET LKP=SIEN_","_SFAC_","_GOAL_","
SET FILE1=9000093.211101
+5 SET STEPNO=$$GET1^DIQ(FILE1,LKP,".01")
+6 SET SBY=$$GET1^DIQ(FILE1,LKP,".02")
+7 SET SWHEN=$$GET1^DIQ(FILE1,LKP,".03","I")
+8 SET STYPE=$$GET1^DIQ(FILE1,LKP,".04")
+9 SET SSTART=$$GET1^DIQ(FILE1,LKP,".05","I")
+10 SET SFUP=$$GET1^DIQ(FILE1,LKP,".06","I")
+11 SET SUPD=$$GET1^DIQ(FILE1,LKP,".07")
+12 SET SMOD=$$GET1^DIQ(FILE1,LKP,".08","I")
+13 SET SSTATUS=$$GET1^DIQ(FILE1,LKP,".09")
+14 IF SSTATUS="DELETED"
QUIT
+15 SET STATUS=$$GET1^DIQ(FILE1,LKP,".09","I")
+16 SET SPROV=$$GET1^DIQ(FILE1,LKP,".1")
+17 SET @RET@(SIEN,0)=GIEN_U_FAC_";"_FNAME_U_SIEN_U_STEPNO_U_SBY_U_SWHEN_U_STYPE_U_SSTART_U_SFUP_U_SUPD_U_SMOD_U_STATUS_";"_SSTATUS_U_SPROV
+18 SET STEXT=$$GET1^DIQ(FILE1,LKP,1101)
+19 SET @RET@(SIEN,1)=STEXT
End DoDot:1
+20 QUIT
ADDREV(RETVAL,GIEN,REVD,REVT) ;PEP - ADD A REVIEW TO A GOAL 9000093.13
+1 ;INPUT:
+2 ;GIEN= ien of goal
+3 ;REVD= review date
+4 ;REVT= review text
+5 ;OUTPUT: ien of review entry in multiple or 0^error text
+6 ;
+7 IF '$GET(GIEN)
SET RETVAL="0^invalid ien"
QUIT
+8 DO ADDREV^APCDGAP2(GIEN,REVD,REVT,.RETVAL)
+9 QUIT
+10 ;
ADDSTEP(RETVAL,GIEN,SDAT) ;PEP - add a step to a goal
+1 ;Add a Step to an existing goal
+2 ; SDAT - array of steps to be added if adding steps
+3 ; SDAT(n)=facility^step number^step type^step start date^step f/u date^provider^step text
+4 ; one entry in array for each step being added
+5 ; step number is optional, if not passed the next available step number will be used
+6 ; values can be internal or external
+7 ; user created / user last update fields auto stuffed with DUZ
+8 ; date created / date last updated fields auto stuffed with DT and NOW^XLFDT
+9 ;
+10 ; Example:
+11 ; SDAT(1)="5217^1^NUTRITION^3101029^3101231^1239^EAT LESS THAN 1200 CAAPCDTESTES PER DAY
+12 ; SDAT(2)="5217^2^PHYSICAL ACTIVITY^3101029^3101231^1239^WALK 60 MINUTES PER DAY
+13 NEW I,J,SDAT2
+14 SET I=""
FOR
SET I=$ORDER(SDAT(I))
IF I=""
QUIT
Begin DoDot:1
+15 SET J=I+1
+16 SET SDAT2(J)=SDAT(I)
End DoDot:1
+17 DO ADDSTEP^APCDGAP2(GIEN,.SDAT2,.RETVAL)
+18 SET RETVAL=RETVAL(1)
+19 QUIT
DELSTEP(RET,GIEN,LIEN,SIEN,PRV,SDTE,SREA,SOTHER) ;PEP - DELETE A STEP
+1 ;delete a step
+2 ; INP =
+3 ; GIEN=Goal IEN
+4 ; LINE=Location
+5 ; SIEN=Step IEN
+6 ; PRV= Who deleted (defaults to DUZ if not sent)
+7 ; SDTE= When deleted (defaults to NOW If not sent)
+8 ; SREA= Reason deleted (set of codes)
+9 ; SOTHER=Text if reason is other
+10 ; OUTPUT = 1 if delete successful or 0^error message
+11 SET RET=""
+12 IF '$GET(GIEN)
SET RET="0^invalid goal ien"
QUIT
+13 SET SOTHER=$GET(SOTHER)
+14 SET X=SDTE
DO ^%DT
SET SDTE=Y
+15 IF (SREA="O"!(SREA="OTHER"))&(SOTHER="")
SET RET="0^Text must be sent with OTHER reason"
QUIT
+16 DO DELSTEP^APCDGAP2(GIEN,LIEN,SIEN,PRV,SDTE,SREA,SOTHER,.RET)
+17 QUIT
EDITSTEP(RETVAL,GIEN,LIEN,SIEN,FUD,STAT) ;PEP - edit a step entry
+1 ;edit a step entry
+2 ;per requirements only the followup date and status can be edited
+3 ;INPUT:
+4 ; GIEN=goal ien
+5 ; LIEN=location ien
+6 ; SIEN=Step ien
+7 ; FUD= new f/u date
+8 ; STAT=status
+9 ;OUTPUT: 1 if edit successful, 0^error message if not successful
+10 IF '$GET(GIEN)
SET RETVAL="0^invalid ien"
QUIT
+11 DO EDITSTEP^APCDGAP2(GIEN,LIEN,SIEN,FUD,STAT,.RETVAL)
+12 QUIT
NEXTSN(RET,GIEN,FAC) ;PEP - return next step number for this goal, facility
+1 SET RET=$$NEXTSN^APCDGAP2(GIEN,FAC)
+2 QUIT
TMPGBL() ;EP
+1 KILL ^TMP("BEHOGOAL",$JOB)
QUIT $NAME(^($JOB))