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

ORACCES2.m

Go to the documentation of this file.
ORACCES2 ;SLC/JNM - User Read/Write Access to CPRS ; Jan 05, 2024@12:47
 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**588,608**;Dec 17, 1997;Build 15;
 ; Reference to ^XTV(8989.5,"AC" in ICR #2686
 Q
 ;
ACCESS(RESULTS,USER,GETNOTES,NOTES) ;
 ; NOTES only populated if GETNOTES>0
 ; GETNOTES=1 Adds just the missing dependencies
 ; GETNOTES=2 Adds the entire description
 N CNT,CNT2,IEN,IENARR,NODE,ORERR,ORVALUE,TAB,VALUE,X,SORT,COUNT,PARAM,LASTPARAM,SHOW
 N ORPARAM,ORTABS,CPRS,WRITE,TEMPLATE,DG,TABS,OTHER,ORDERS,ERROR,NCNT,MAXGROUPS,SHOWEXCLUDE
 N ORDERSTAB,ALLERGIESTAB,NOTESTAB,DELAYEDORDERSTAB,IMMUNIZATIONSTAB,ENCOUNTERSTAB
 D GETPARAMS^ORACCESS
 S CPRS="cprsAccess",WRITE="writeAccess",TEMPLATE="templateAccess",DG="displayGroups"
 S SORT="SORT",MAXGROUPS=0
 S ORDERSTAB=$$TABIDX^ORACCESS(TABS,"O"),ALLERGIESTAB=$$TABIDX^ORACCESS(OTHER,"A")
 S NOTESTAB=$$TABIDX^ORACCESS(TABS,"N"),DELAYEDORDERSTAB=$$TABIDX^ORACCESS(OTHER,"D")
 S IMMUNIZATIONSTAB=$$TABIDX^ORACCESS(OTHER,"I"),ENCOUNTERSTAB=$$TABIDX^ORACCESS(OTHER,"E")
 S GETNOTES=+$G(GETNOTES) K NOTES
 S RESULTS(CPRS,"errorMessage")=$$GET^XPAR("ALL",ORPARAM(ERROR))
 ;get tabs values
 S TAB=0 F  S TAB=$O(ORTABS(TAB))  Q:'TAB  D
 .S VALUE=$$GET^XPAR("ALL",ORPARAM(ORTABS(TAB,1)),ORTABS(TAB,2))
 .I VALUE="" S VALUE=0
 .S RESULTS(CPRS,ORTABS(TAB,3),WRITE)=VALUE
 .I ORTABS(TAB,5)=1 S RESULTS(CPRS,ORTABS(TAB,3),TEMPLATE)=VALUE
 .I GETNOTES=2,TAB'=ORDERSTAB,TAB'=DELAYEDORDERSTAB D
 ..S NOTES(SORT,ORTABS(TAB,1)_$$TABDESC^ORACCESS(TAB,1))=VALUE
 ;get Order Display Groups Write Access
 I RESULTS(CPRS,ORTABS(ORDERSTAB,3),WRITE)=1 D
 .S (CNT,CNT2)=0
 .F X="PKG","SYS","DIV","USR" D
 ..K ORVALUE,ORERR
 ..D GETLST^XPAR(.ORVALUE,X,ORPARAM(ORDERS),"I",.ORERR)
 ..S IEN=0 F  S IEN=$O(ORVALUE(IEN)) Q:IEN'>0  D
 ...S VALUE=ORVALUE(IEN)
 ...S NODE=$G(^ORD(100.98,IEN,0)) I NODE="" Q
 ...I X="PKG" D  Q
 ....S CNT=CNT+1,CNT2=CNT
 ....S IENARR(IEN)=VALUE_U_CNT
 ....D ADDGROUPRESULTS
 ...I $D(IENARR(IEN)),+IENARR(IEN)=VALUE Q
 ...I $D(IENARR(IEN)) S $P(IENARR(IEN),U,1)=VALUE,CNT=$P(IENARR(IEN),U,2)
 ...E  S CNT2=CNT2+1,CNT=CNT2,IENARR(IEN)=VALUE_U_CNT
 ...D ADDGROUPRESULTS
 .; Add any missing groups
 .S VALUE=1,IEN=0 F  S IEN=$O(^ORD(100.98,IEN)) Q:'IEN  D
 ..S NODE=$G(^ORD(100.98,IEN,0)),MAXGROUPS=MAXGROUPS+1 I '$D(IENARR(IEN)) D
 ...S CNT2=CNT2+1,CNT=CNT2,IENARR(IEN)=VALUE_U_CNT
 ...D ADDGROUPRESULTS
 .I GETNOTES=2 D
 ..F X=1:1:CNT2 D
 ...S NOTES(SORT,3_RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,X,"name"))=RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,X,WRITE)
 ;
 I RESULTS(CPRS,ORTABS(ALLERGIESTAB,3),WRITE)=1 D
 .N MSG
 .I RESULTS(CPRS,ORTABS(NOTESTAB,3),WRITE)=0 S MSG=ORTABS(NOTESTAB,4)_" tab"
 .I RESULTS(CPRS,ORTABS(ORDERSTAB,3),WRITE)=0 D  I 1
 ..I $D(MSG) S MSG=MSG_" and "
 ..S MSG=$G(MSG)_ORTABS(ORDERSTAB,4)_" tab"
 .E  D
 ..S IEN=$O(^ORD(100.98,"B","ALLERGIES",0))
 ..I IEN,$D(IENARR(IEN)),$P(IENARR(IEN),U)=0 D
 ...I $D(MSG) S MSG=MSG_" and "
 ...S MSG=$G(MSG)_"ALLERGIES display group"
 .I $D(MSG) D
 ..S RESULTS(CPRS,ORTABS(ALLERGIESTAB,3),WRITE)=0
 ..I GETNOTES>0 S NOTES(SORT,4_ORTABS(ALLERGIESTAB,4)_" requires "_MSG_" access")=1
 ..I GETNOTES=2 S NOTES(SORT,ORTABS(ALLERGIESTAB,1)_$$TABDESC^ORACCESS(ALLERGIESTAB,1))=0
 ;
 I RESULTS(CPRS,ORTABS(DELAYEDORDERSTAB,3),WRITE)=1,RESULTS(CPRS,ORTABS(ORDERSTAB,3),WRITE)=0 D
 .S RESULTS(CPRS,ORTABS(DELAYEDORDERSTAB,3),WRITE)=0
 .I GETNOTES>0 S NOTES(SORT,4_ORTABS(DELAYEDORDERSTAB,4)_" requires "_ORTABS(ORDERSTAB,4)_" tab access")=1
 .;I GETNOTES=2 S NOTES(SORT,ORTABS(DELAYEDORDERSTAB,1)_$$TABDESC^ORACCESS(DELAYEDORDERSTAB,1))=0
 ;
 I RESULTS(CPRS,ORTABS(IMMUNIZATIONSTAB,3),WRITE)=1 D
 .N MSG
 .I RESULTS(CPRS,ORTABS(NOTESTAB,3),WRITE)=0 S MSG=ORTABS(NOTESTAB,4)_" tab"
 .I RESULTS(CPRS,ORTABS(ENCOUNTERSTAB,3),WRITE)=0 D
 ..I $D(MSG) S MSG=MSG_" and "
 ..S MSG=$G(MSG)_ORTABS(ENCOUNTERSTAB,4)
 .I $D(MSG) D
 ..S RESULTS(CPRS,ORTABS(IMMUNIZATIONSTAB,3),WRITE)=0
 ..I GETNOTES>0 S NOTES(SORT,4_ORTABS(IMMUNIZATIONSTAB,4)_" requires "_MSG_" access")=1
 ..I GETNOTES=2 S NOTES(SORT,ORTABS(IMMUNIZATIONSTAB,1)_$$TABDESC^ORACCESS(IMMUNIZATIONSTAB,1))=0
 ;
 I GETNOTES>0 D
 .N MSG S SHOWEXCLUDE=0
 .I GETNOTES=2,RESULTS(CPRS,ORTABS(ORDERSTAB,3),WRITE)=1 D
 ..S MSG=ORTABS(ORDERSTAB,1)_$$TABDESC^ORACCESS(ORDERSTAB,1)_", delayed orders "
 ..I RESULTS(CPRS,ORTABS(DELAYEDORDERSTAB,3),WRITE)=0 S MSG=MSG_"not "
 ..S MSG=MSG_"allowed",NOTES(SORT,MSG)=1
 .S (NCNT,LASTPARAM)=0 F PARAM=1:1:4 S COUNT(PARAM)=0
 .S NODE="" F  S NODE=$O(NOTES(SORT,NODE)) Q:NODE=""  D
 ..S PARAM=+$E(NODE,1,1) I +NOTES(SORT,NODE) S COUNT(PARAM)=COUNT(PARAM)+1
 .S NODE="" F  S NODE=$O(NOTES(SORT,NODE)) Q:NODE=""  D
 ..S PARAM=+$E(NODE,1,1)
 ..I PARAM'=LASTPARAM D
 ...N IDX,MSGOUT S MSG=""
 ...S LASTPARAM=PARAM
 ...I NCNT>0 S NCNT=NCNT+1,NOTES(NCNT)=""
 ...I COUNT(PARAM)=0 D  I 1
 ....I PARAM<3 D
 .....N MSGSORT,CNT,MAX S (IDX,CNT,MAX)=0
 .....F  S IDX=$O(ORTABS(IDX)) Q:'IDX  I IDX'=DELAYEDORDERSTAB,ORTABS(IDX,1)=PARAM S MAX=MAX+1
 .....S IDX=0 F  S IDX=$O(ORTABS(IDX)) Q:'IDX  I IDX'=DELAYEDORDERSTAB,ORTABS(IDX,1)=PARAM D
 ......S MSGSORT($$TABDESC^ORACCESS(IDX,$S(ORTABS(IDX,5)=2:1,1:0)))=""
 .....S IDX="" F  S IDX=$O(MSGSORT(IDX)) Q:IDX=""  D
 ......S CNT=CNT+1 I MSG'="" S MSG=MSG_$S(CNT<MAX:", ",1:" or ")
 ......S MSG=MSG_IDX
 .....I PARAM=1 S MSG=MSG_" tabs"
 ....I PARAM=3 S MSG="any display groups"
 ....S MSG="No write access for "_MSG_"."
 ....D WRAP^ORUTL(MSG,"MSGOUT",1,0,3,0,78)
 ....S IDX=0 F  S IDX=$O(MSGOUT(IDX)) Q:'IDX  D
 .....S NCNT=NCNT+1,NOTES(NCNT)=MSGOUT(IDX)
 ...E  D  ; COUNT(PARAM)>0
 ....S NCNT=NCNT+1
 ....I PARAM=1 S NOTES(NCNT)="Write access allowed for the following tab"_$S(COUNT(PARAM)>1:"s",1:"")_":"
 ....I PARAM=2 S NOTES(NCNT)="Write access allowed for the following additional functionality:"
 ....I PARAM=3 D
 .....S SHOWEXCLUDE=(COUNT(PARAM)<MAXGROUPS)&(COUNT(PARAM)>(MAXGROUPS/2))
 .....I COUNT(PARAM)<MAXGROUPS D
 ......I SHOWEXCLUDE S NOTES(NCNT)="Ordering write access allowed for all display groups EXCEPT:"
 ......E  S NOTES(NCNT)="Ordering write access allowed for the following display group"_$S(COUNT(PARAM)>1:"s",1:"")_":"
 .....E  S NOTES(NCNT)="Ordering write access allowed for all display groups."
 ....I PARAM=4 S NOTES(NCNT)="Missing write access dependenc"_$S(COUNT(PARAM)=1:"y",1:"ies")_":"
 ..S SHOW=(NOTES(SORT,NODE)>0) I PARAM=3,SHOWEXCLUDE S SHOW='SHOW
 ..I SHOW,(PARAM'=3)!(COUNT(PARAM)<MAXGROUPS) D
 ...S NCNT=NCNT+1,NOTES(NCNT)="   "_$E(NODE,2,999)
 .K NOTES(SORT)
 Q
 ;
ADDGROUPRESULTS ; 
 S RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,CNT,"ien")=IEN
 S RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,CNT,"name")=$P(NODE,U)
 S RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,CNT,"shortName")=$P(NODE,U,3)
 S RESULTS(CPRS,ORTABS(ORDERSTAB,3),DG,CNT,WRITE)=VALUE
 Q
 ;
VALUEMSG(ENT,INST,X,GETALL,MESSAGE,NAME) ;
 I +$G(NODEPENDENCIES) Q
 S GETALL=+$G(GETALL)
 I $G(ENT)="" Q
 I 'GETALL,$G(X)'="YES" Q
 I $P($G(DIR(0)),U,3)'="" Q
 N CODE
 S CODE=$P($G(INST),U)
 I 'GETALL,"^A^D^I^"'[(U_CODE_U) Q
 N ORPARAM,ORPIEN,ORTABS,TABS,OTHER,ORDERS,ERROR,IEN,MCNT
 N ORDERSTAB,ALLERGIESTAB,NOTESTAB,DELAYEDORDERSTAB,IMMUNIZATIONSTAB,ENCOUNTERSTAB
 D GETPARAMS^ORACCESS(1)
 S MCNT=0
 S ORDERSTAB=$$TABIDX^ORACCESS(TABS,"O"),ALLERGIESTAB=$$TABIDX^ORACCESS(OTHER,"A")
 S NOTESTAB=$$TABIDX^ORACCESS(TABS,"N"),DELAYEDORDERSTAB=$$TABIDX^ORACCESS(OTHER,"D")
 S IMMUNIZATIONSTAB=$$TABIDX^ORACCESS(OTHER,"I"),ENCOUNTERSTAB=$$TABIDX^ORACCESS(OTHER,"E")
 I GETALL S CODE=$S(+$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(ALLERGIESTAB,1)),ENT,ORTABS(ALLERGIESTAB,2))):"A",1:"")
 I CODE="A" D
 .N MSG
 .I +$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(NOTESTAB,1)),ENT,ORTABS(NOTESTAB,2)))=0 D
 ..S MSG=ORTABS(NOTESTAB,4)_" tab"
 .I +$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(ORDERSTAB,1)),ENT,ORTABS(ORDERSTAB,2)))=0 D  I 1
 ..I $D(MSG) S MSG=MSG_" and "
 ..S MSG=$G(MSG)_ORTABS(ORDERSTAB,4)_" tab"
 .E  D
 ..S IEN=$O(^ORD(100.98,"B","ALLERGIES",0))
 ..I IEN,+$G(^XTV(8989.5,"AC",ORPIEN(ORDERS),ENT,IEN))=0 D
 ...I $D(MSG) S MSG=MSG_" and "
 ...S MSG=$G(MSG)_"ALLERGIES display group"
 .I $D(MSG) D
 ..S MCNT=MCNT+1,MESSAGE(MCNT)="  "_ORTABS(ALLERGIESTAB,4)_" also requires "_MSG_" access."
 I GETALL S CODE=$S(+$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(DELAYEDORDERSTAB,1)),ENT,ORTABS(DELAYEDORDERSTAB,2))):"D",1:"")
 I CODE="D" D
 .I +$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(ORDERSTAB,1)),ENT,ORTABS(ORDERSTAB,2)))=0 D
 ..S MCNT=MCNT+1,MESSAGE(MCNT)="  "_ORTABS(DELAYEDORDERSTAB,4)_" also requires "_ORTABS(ORDERSTAB,4)_" tab access."
 I GETALL S CODE=$S(+$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(IMMUNIZATIONSTAB,1)),ENT,ORTABS(IMMUNIZATIONSTAB,2))):"I",1:"")
 I CODE="I" D
 .N MSG
 .I +$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(NOTESTAB,1)),ENT,ORTABS(NOTESTAB,2)))=0 D
 ..S MSG=ORTABS(NOTESTAB,4)_" tab"
 .I +$G(^XTV(8989.5,"AC",ORPIEN(ORTABS(ENCOUNTERSTAB,1)),ENT,ORTABS(ENCOUNTERSTAB,2)))=0 D
 ..I $D(MSG) S MSG=MSG_" and "
 ..S MSG=$G(MSG)_ORTABS(ENCOUNTERSTAB,4)
 .I $D(MSG) D
 ..S MCNT=MCNT+1,MESSAGE(MCNT)="  "_ORTABS(IMMUNIZATIONSTAB,4)_" also requires "_MSG_" access."
 I MCNT>0 D
 .I GETALL D
 ..S MESSAGE(0.5)="Missing write access dependenc"_$S(MCNT=1:"y",1:"ies")_"* for "_$G(NAME)
 ..S MESSAGE(999)="* Dependencies may be resolved at a different level."
 .I 'GETALL S IEN=0 F  S IEN=$O(MESSAGE(IEN)) Q:'IEN  W !,MESSAGE(IEN)
 Q
 ;
DLGOIINFO(ORY,LIST,INFO) ; Return orderable item info tied to each order dialog in the list
 ; INFO=1 Get LAB SECTION
 I '+$G(INFO) Q
 N IDX,DLG,OI,OIIDX,SUBIDX,CODE,LINE
 S OIIDX=$O(^ORD(101.41,"B","OR GTX ORDERABLE ITEM",0)) I 'OIIDX Q
 S (LINE,IDX)=0 F  S IDX=$O(LIST(IDX)) Q:'IDX  D
 . S (OI,SUBIDX)=0 F  S SUBIDX=$O(^ORD(101.41,LIST(IDX),6,SUBIDX)) Q:'SUBIDX  D  Q:OI
 . . I $P($G(^ORD(101.41,LIST(IDX),6,SUBIDX,0)),U,2)=OIIDX D  Q
 . . . S OI=$P($G(^ORD(101.41,LIST(IDX),6,SUBIDX,1)),U,1)
 . I OI D
 . . S CODE=""
 . . I INFO=1 S CODE=$P($G(^ORD(101.43,OI,"LR")),U,6) I CODE="" S CODE="CH"
 . . I CODE'="" S LINE=LINE+1,ORY(LINE)=LIST(IDX)_U_CODE
 Q
 ;
LABSBYXREF(ORY,DGSNAME) ; Return all LAB SECTION codes used by the specified XREF
 S ORY=U
 N XREF S XREF="S."_DGSNAME
 I "^S.LAB^S.AP^"'[(U_$G(XREF)_U) Q
 N DG,I,CODE,NAME,TEMP,LST,ILST,LIST,OUTPUT,ISAP,QUIT,APDLGIEN,X,CURTM
 S CURTM=$$NOW^XLFDT,ISAP=(XREF="S.AP")
 S NAME="" F  S NAME=$O(^ORD(101.43,XREF,NAME)) Q:NAME=""  D
 . S I=0 F  S I=$O(^ORD(101.43,XREF,NAME,I)) Q:'I  D
 . . S X=$G(^ORD(101.43,XREF,NAME,I))
 . . I +$P(X,U,3),$P(X,U,3)<CURTM Q
 . . I $P(X,U,5) Q
 . . I ISAP D  Q:QUIT
 . . . S QUIT=1
 . . . I '$$OK4CPRS^ORWLRAP1(I) Q
 . . . S APDLGIEN=+$O(^ORD(101.45,"C",I,0)) I 'APDLGIEN Q
 . . . I +$P($G(^ORD(101.45,APDLGIEN,0)),U,6) Q
 . . . S QUIT=0
 . . S CODE=$P($G(^ORD(101.43,I,"LR")),U,6)
 . . I CODE="" S CODE="CH"
 . . I '$D(TEMP(CODE)) S TEMP(CODE)=""
 S ILST=0
 I XREF="S.LAB" D SHORT^ORWDLR32 ; Also get any codes used by quick orders
 I $D(LST) D
 . S I=0 F  S I=$O(LST(I)) Q:'I  S LST(I)=$E($P(LST(I),U,1),3,999)
 . D DLGOIINFO(.LIST,.LST,1)
 . S I=0 F  S I=$O(LIST(I)) Q:'I  D
 . . S CODE=$P(LIST(I),U,2) I CODE'="" S TEMP(CODE)=""
 S I="" F  S I=$O(TEMP(I)) Q:I=""  S ORY=ORY_I_U
 Q
 ;
DIETINFO(ORY) ; Return Diet Order Dialog info used to write access
 N CNT,DIET,IEN,DG,TYPE,NAME
 S CNT=0
 D ADD2ORY("DIETETICS")
 S DIET=$O(^ORD(100.98,"B","DIETETICS",0)) Q:'DIET
 S IEN=0 F  S IEN=$O(^ORD(100.98,DIET,1,IEN)) Q:'IEN  D
 . S DG=$P($G(^ORD(100.98,DIET,1,IEN,0)),U) Q:'+DG
 . S TYPE="" D FINDTYP^ORWDFH(.TYPE,DG) I $G(TYPE)="" Q
 . S NAME=$P($G(^ORD(100.98,DG,0)),U,3) Q:NAME="D CON"
 . D ADD2ORY(DG_U_TYPE_U_$P($G(^ORD(100.98,DG,0)),U,3))
 Q
 ;
ADD2ORY(TEXT) ;
 S CNT=CNT+1,ORY(CNT)=TEXT
 Q