HLEMP ;ALB/CJM-HL7 - APIs for Monitor Events Log Profiles ;07/10/2003
;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13,1995
;
FDEFAULT(DUZ) ;
;Description: Given a DUZ, returns the default profile, or "" on failure
;
Q:'$G(DUZ) 0
Q $O(^HLEV(776.5,"AC",DUZ,0))
;
Q $S(Y=-1:0,1:+Y)
;
GET(IEN,PROFILE) ;
;Description - given the ien, it returns an array containing the profile
;Input:
; IEN - ien of the profile
;Output:
; function returns 0 on failure, 1 on success
; PROFILE( **pass by reference**
; "ALL APPS" - 1 if all sending applications should be included, 0 otherwise
; "ALL SITES" - 1 if all sites should be included, 0 otherwise
; "ALL STATUSES" 1 if all review statuses should be included, 0 otherwise
; "ALL TYPES" - 1 if all event types should be included, 0 otherwise
; "APPS",<HL7 APPLICATION PARAMETER>) -list of sending applications to include - NOT the iens, but the names of the HL7 Application Parameter
; "DUZ" - the duz of the profile's owner
; "DEFAULT" - 1 if this is the default profile, 0 if it isn't
; "IEN" - ien of the profile
; "NAME" - name of the profile
; "SITES",<institution ien>) - list of institution numbers to include
; "START" - starting date/time for selecting events for display, in FM format
; "STATUSES",<review status code>) - list of review status codes to include
; "TYPES",<HL7 MONITOR EVENT TYPE>) - list of event type iens
; "URGENT" - 1 means urgent only, 0 means disregard urgency
;
;
Q:'$G(IEN) 0
N NODE,SITE,TYPE,APP,STATUS,APPNAME,I
K PROFILE S PROFILE=IEN
S NODE=$G(^HLEV(776.5,IEN,0))
Q:'$L(NODE) 0
S PROFILE("IEN")=IEN
S PROFILE("DUZ")=+NODE
S PROFILE("NAME")=$P(NODE,"^",2)
S PROFILE("DEFAULT")=$P(NODE,"^",3)
S PROFILE("ALL SITES")=$P(NODE,"^",4)
S PROFILE("ALL TYPES")=$P(NODE,"^",5)
S PROFILE("ALL APPS")=$P(NODE,"^",6)
S PROFILE("ALL STATUSES")=$P(NODE,"^",7)
S START=+$P(NODE,"^",8) D
.N NOW
.S NOW=$$NOW^XLFDT
.S PROFILE("START")=0
.I START=1 S PROFILE("START")=$$FMADD^XLFDT(NOW,,-1) Q
.I START=2 S PROFILE("START")=$$FMADD^XLFDT(NOW,,-2) Q
.I START=3 S PROFILE("START")=$$FMADD^XLFDT(NOW,,-6) Q
.I START=4 S PROFILE("START")=+NOW Q
.I START=5 S PROFILE("START")=$$FMADD^XLFDT(NOW,-1) Q
.I START=6 S PROFILE("START")=$$FMADD^XLFDT(+NOW,-1) Q
.I START=7 S PROFILE("START")=$$FMADD^XLFDT(NOW,-2) Q
.I START=8 S PROFILE("START")=$$FMADD^XLFDT(NOW,-3) Q
.I START=9 S PROFILE("START")=$$FMADD^XLFDT(NOW,-7) Q
S PROFILE("URGENT")=$P(NODE,"^",9)
S SITE=0
F I="APPS","SITES","TYPES","STATUSES" S PROFILE(I)=""
F S SITE=$O(^HLEV(776.5,IEN,1,SITE)) Q:'SITE S PROFILE("SITES",+$G(^HLEV(776.5,IEN,1,SITE,0)))=""
S TYPE=0
F S TYPE=$O(^HLEV(776.5,IEN,2,TYPE)) Q:'TYPE S PROFILE("TYPES",+$G(^HLEV(776.5,IEN,2,TYPE,0)))=""
S APP=0
F S APP=$O(^HLEV(776.5,IEN,3,APP)) Q:'APP S PROFILE("APPS",$$APPNAME^HLEMU(+$G(^HLEV(776.5,IEN,3,APP,0))))=""
S STATUS=0
F S STATUS=$O(^HLEV(776.5,IEN,4,STATUS)) Q:'STATUS S APPNAME=$$APPNAME^HLEMU(+$G(^HLEV(776.5,IEN,4,STATUS,0))) I $L(APPNAME) S PROFILE("APPS",APPNAME)=""
Q 1
;
CREATE(DUZ,NAME,ERROR) ;
;Given the DUZ and a name, creates a new profile of that name.
;Output-
; function value - returns the new profile ien on success, 0 on failure
; ERROR **optional, pass by reference** an array of errors
;
Q:'$G(DUZ) 0
Q:'$L(NAME) 0
;
N DATA
S DATA(.01)=DUZ
S DATA(.02)=NAME
Q $$ADD^HLEMU(776.5,,.DATA,.ERROR)
;
EDIT(PROFILE) ;
;Given the ien of a profile, allows a user to edit it.
;Input: PROFILE - ien of a profile
;Output: function returns 1 on success, 0 on failure, or on indication that the user did not complete the edit
;
Q:'$G(PROFILE) 0
Q:'$G(^HLEV(776.5,PROFILE,0)) 0
K DA,DIE,DR
S DA=PROFILE
S DIE=776.5
S DR=".02:.09"
S DIE("NO^")="OUTOK"
D ^DIE
I '$D(Y),'$D(DTOUT),$$GET(PROFILE,.PROFILE) D
.S DR=""
.S DIE("NO^")="OUTOK"
.I 'PROFILE("ALL SITES") S DR="1;"
.I 'PROFILE("ALL TYPES") S DR=DR_"2;"
.I 'PROFILE("ALL APPS") S DR=DR_"3;"
.I 'PROFILE("ALL STATUSES") S DR=DR_4
.D ^DIE
Q $S($D(Y)!$D(DTOUT):0,1:1)
;
DELETE(PROFILE) ;
;Given the ien, deletes the profile
Q $$DELETE^HLEMU(776.5,.PROFILE)
HLEMP ;ALB/CJM-HL7 - APIs for Monitor Events Log Profiles ;07/10/2003
+1 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13,1995
+2 ;
FDEFAULT(DUZ) ;
+1 ;Description: Given a DUZ, returns the default profile, or "" on failure
+2 ;
+3 IF '$GET(DUZ)
QUIT 0
+4 QUIT $ORDER(^HLEV(776.5,"AC",DUZ,0))
+5 ;
+6 QUIT $SELECT(Y=-1:0,1:+Y)
+7 ;
GET(IEN,PROFILE) ;
+1 ;Description - given the ien, it returns an array containing the profile
+2 ;Input:
+3 ; IEN - ien of the profile
+4 ;Output:
+5 ; function returns 0 on failure, 1 on success
+6 ; PROFILE( **pass by reference**
+7 ; "ALL APPS" - 1 if all sending applications should be included, 0 otherwise
+8 ; "ALL SITES" - 1 if all sites should be included, 0 otherwise
+9 ; "ALL STATUSES" 1 if all review statuses should be included, 0 otherwise
+10 ; "ALL TYPES" - 1 if all event types should be included, 0 otherwise
+11 ; "APPS",<HL7 APPLICATION PARAMETER>) -list of sending applications to include - NOT the iens, but the names of the HL7 Application Parameter
+12 ; "DUZ" - the duz of the profile's owner
+13 ; "DEFAULT" - 1 if this is the default profile, 0 if it isn't
+14 ; "IEN" - ien of the profile
+15 ; "NAME" - name of the profile
+16 ; "SITES",<institution ien>) - list of institution numbers to include
+17 ; "START" - starting date/time for selecting events for display, in FM format
+18 ; "STATUSES",<review status code>) - list of review status codes to include
+19 ; "TYPES",<HL7 MONITOR EVENT TYPE>) - list of event type iens
+20 ; "URGENT" - 1 means urgent only, 0 means disregard urgency
+21 ;
+22 ;
+23 IF '$GET(IEN)
QUIT 0
+24 NEW NODE,SITE,TYPE,APP,STATUS,APPNAME,I
+25 KILL PROFILE
SET PROFILE=IEN
+26 SET NODE=$GET(^HLEV(776.5,IEN,0))
+27 IF '$LENGTH(NODE)
QUIT 0
+28 SET PROFILE("IEN")=IEN
+29 SET PROFILE("DUZ")=+NODE
+30 SET PROFILE("NAME")=$PIECE(NODE,"^",2)
+31 SET PROFILE("DEFAULT")=$PIECE(NODE,"^",3)
+32 SET PROFILE("ALL SITES")=$PIECE(NODE,"^",4)
+33 SET PROFILE("ALL TYPES")=$PIECE(NODE,"^",5)
+34 SET PROFILE("ALL APPS")=$PIECE(NODE,"^",6)
+35 SET PROFILE("ALL STATUSES")=$PIECE(NODE,"^",7)
+36 SET START=+$PIECE(NODE,"^",8)
Begin DoDot:1
+37 NEW NOW
+38 SET NOW=$$NOW^XLFDT
+39 SET PROFILE("START")=0
+40 IF START=1
SET PROFILE("START")=$$FMADD^XLFDT(NOW,,-1)
QUIT
+41 IF START=2
SET PROFILE("START")=$$FMADD^XLFDT(NOW,,-2)
QUIT
+42 IF START=3
SET PROFILE("START")=$$FMADD^XLFDT(NOW,,-6)
QUIT
+43 IF START=4
SET PROFILE("START")=+NOW
QUIT
+44 IF START=5
SET PROFILE("START")=$$FMADD^XLFDT(NOW,-1)
QUIT
+45 IF START=6
SET PROFILE("START")=$$FMADD^XLFDT(+NOW,-1)
QUIT
+46 IF START=7
SET PROFILE("START")=$$FMADD^XLFDT(NOW,-2)
QUIT
+47 IF START=8
SET PROFILE("START")=$$FMADD^XLFDT(NOW,-3)
QUIT
+48 IF START=9
SET PROFILE("START")=$$FMADD^XLFDT(NOW,-7)
QUIT
End DoDot:1
+49 SET PROFILE("URGENT")=$PIECE(NODE,"^",9)
+50 SET SITE=0
+51 FOR I="APPS","SITES","TYPES","STATUSES"
SET PROFILE(I)=""
+52 FOR
SET SITE=$ORDER(^HLEV(776.5,IEN,1,SITE))
IF 'SITE
QUIT
SET PROFILE("SITES",+$GET(^HLEV(776.5,IEN,1,SITE,0)))=""
+53 SET TYPE=0
+54 FOR
SET TYPE=$ORDER(^HLEV(776.5,IEN,2,TYPE))
IF 'TYPE
QUIT
SET PROFILE("TYPES",+$GET(^HLEV(776.5,IEN,2,TYPE,0)))=""
+55 SET APP=0
+56 FOR
SET APP=$ORDER(^HLEV(776.5,IEN,3,APP))
IF 'APP
QUIT
SET PROFILE("APPS",$$APPNAME^HLEMU(+$GET(^HLEV(776.5,IEN,3,APP,0))))=""
+57 SET STATUS=0
+58 FOR
SET STATUS=$ORDER(^HLEV(776.5,IEN,4,STATUS))
IF 'STATUS
QUIT
SET APPNAME=$$APPNAME^HLEMU(+$GET(^HLEV(776.5,IEN,4,STATUS,0)))
IF $LENGTH(APPNAME)
SET PROFILE("APPS",APPNAME)=""
+59 QUIT 1
+60 ;
CREATE(DUZ,NAME,ERROR) ;
+1 ;Given the DUZ and a name, creates a new profile of that name.
+2 ;Output-
+3 ; function value - returns the new profile ien on success, 0 on failure
+4 ; ERROR **optional, pass by reference** an array of errors
+5 ;
+6 IF '$GET(DUZ)
QUIT 0
+7 IF '$LENGTH(NAME)
QUIT 0
+8 ;
+9 NEW DATA
+10 SET DATA(.01)=DUZ
+11 SET DATA(.02)=NAME
+12 QUIT $$ADD^HLEMU(776.5,,.DATA,.ERROR)
+13 ;
EDIT(PROFILE) ;
+1 ;Given the ien of a profile, allows a user to edit it.
+2 ;Input: PROFILE - ien of a profile
+3 ;Output: function returns 1 on success, 0 on failure, or on indication that the user did not complete the edit
+4 ;
+5 IF '$GET(PROFILE)
QUIT 0
+6 IF '$GET(^HLEV(776.5,PROFILE,0))
QUIT 0
+7 KILL DA,DIE,DR
+8 SET DA=PROFILE
+9 SET DIE=776.5
+10 SET DR=".02:.09"
+11 SET DIE("NO^")="OUTOK"
+12 DO ^DIE
+13 IF '$DATA(Y)
IF '$DATA(DTOUT)
IF $$GET(PROFILE,.PROFILE)
Begin DoDot:1
+14 SET DR=""
+15 SET DIE("NO^")="OUTOK"
+16 IF 'PROFILE("ALL SITES")
SET DR="1;"
+17 IF 'PROFILE("ALL TYPES")
SET DR=DR_"2;"
+18 IF 'PROFILE("ALL APPS")
SET DR=DR_"3;"
+19 IF 'PROFILE("ALL STATUSES")
SET DR=DR_4
+20 DO ^DIE
End DoDot:1
+21 QUIT $SELECT($DATA(Y)!$DATA(DTOUT):0,1:1)
+22 ;
DELETE(PROFILE) ;
+1 ;Given the ien, deletes the profile
+2 QUIT $$DELETE^HLEMU(776.5,.PROFILE)