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

PSSJORDF.m

Go to the documentation of this file.
  1. PSSJORDF ;BIR/MV - RETURN MED ROUTES(MR) AND INSTRUCTIONS(INS) ;May 25, 2021@07:40:03
  1. ;;1.0;PHARMACY DATA MANAGEMENT;**5,13,34,38,69,113,94,140,142,159,187**;9/30/97;Build 27
  1. ;;
  1. ; Reference to ^PS(50.7 is supported by DBIA 2180.
  1. ; Reference to ^PS(51.2 is supported by DBIA 2178.
  1. ; Reference to ^PS(50.606 is supported by DBIA 2174.
  1. ;
  1. ;* PSJORD is the Orderable Item IEN pass to Pharmacy by OE/RR.
  1. ;* 1. If the dosage form is valid, this routine will return:
  1. ;* If the orderable item has a default med route in the DEFAULT MED ROUTE field #.06 in
  1. ;* file #50.7 set it as the default; and then get the other med routes from the POSSIBLE MED ROUTES
  1. ;* field #11 if the USE DOSAGE FORM MED ROUTE LIST field #10 is set to "NO".
  1. ;* If the orderable item has a default med route in the DEFAULT MED ROUTE field #.06 in file #50.7
  1. ;* set it as the default; and then get the other med routes from the Dosage Form med routes if the
  1. ;* USE DOSAGE FORM MED ROUTE LIST field #10 is set to "YES".
  1. ;* Otherwise, use existing functionality.
  1. ; 2. If the dose form is null, this routine will return all med routes
  1. ;* that exist in the medication routes file.
  1. ;
  1. ;* 3. ^TMP format:
  1. ;* ^TMP("PSJMR",$J,#)=MED ROUTE^MED ROUTE ABREVATION^IEN^OUTPATIENT
  1. ;* EXPANSION^IV FLAG^DEFAULT FLAG
  1. ;* ^TMP("PSJNOUN",$J,D0)=NOUN^VERB^PREPOSITION
  1. ;* ^TMP("PSJSCH",$J)=DEFAULT SCHEDULE NAME
  1. ;
  1. START(PSJORD,PSJOPAC) ;
  1. N MR,MRNODE,PSJDFNO,X,MCT,Z,PSJOISC
  1. I '+PSJORD D MEDROUTE Q
  1. S PSJDFNO=+$P($G(^PS(50.7,+PSJORD,0)),U,2)
  1. S PSJOISC=$P($G(^PS(50.7,+PSJORD,0)),"^",8)
  1. I $G(PSJOPAC)="O"!($G(PSJOPAC)="X") D:$G(PSJOISC)'="" EN^PSSOUTSC(.PSJOISC) S:$G(PSJOISC)'="" ^TMP("PSJSCH",$J)=$G(PSJOISC) G SCPASS
  1. I $G(PSJOISC)'="" D EN^PSSGSGUI(.PSJOISC,"I") S:$G(PSJOISC)'="" ^TMP("PSJSCH",$J)=$G(PSJOISC)
  1. SCPASS ;
  1. I $G(^PS(50.606,PSJDFNO,0))="" D NOD Q:$D(^TMP("PSJMR",$J,1)) D MEDROUTE Q
  1. K ^TMP("PSJMR",$J),^TMP("PSJNOUN",$J)
  1. D DF,IND ;*187
  1. Q
  1. ;
  1. DF ;* Loop thru DF node to find all available med routes, nouns, and instructions.
  1. N VERB,MR,X,PM,II
  1. S (MR,X)=0,MCT=1
  1. S VERB=$P($G(^PS(50.606,PSJDFNO,"MISC")),U),MR=+$P($G(^PS(50.7,+PSJORD,0)),"^",6)
  1. I MR,$D(^PS(51.2,MR,0)),$P($G(^(0)),"^",4)=1 S ^TMP("PSJMR",$J,1)=$P(^PS(51.2,MR,0),"^")_U_$P(^(0),"^",3)_U_MR_U_$P(^(0),"^",2)_U_$S($P(^(0),"^",6):1,1:0)_"^D",MCT=MCT+1
  1. ; Populate possible med routes
  1. I $P($G(^PS(50.7,+PSJORD,0)),"^",13)'="Y" D S:$O(^TMP("PSJMR",$J,""),-1)=1 $P(^TMP("PSJMR",$J,1),U,6)="D" Q
  1. . S II=0 F S II=$O(^PS(50.7,+PSJORD,3,II)) Q:'II S PM=$G(^(II,0)) D
  1. . . Q:PM=+$P($G(^PS(50.7,+PSJORD,0)),"^",6) I PM,$D(^PS(51.2,PM,0)),$P($G(^(0)),"^",4)=1 S ^TMP("PSJMR",$J,MCT)=$P(^PS(51.2,PM,0),"^")_U_$P(^(0),"^",3)_U_PM_U_$P(^(0),"^",2)_U_$S($P(^(0),"^",6):1,1:0),MCT=MCT+1
  1. S MR=0 F S MR=$O(^PS(50.606,PSJDFNO,"MR",MR)) Q:'MR D
  1. . S X=+$G(^PS(50.606,PSJDFNO,"MR",MR,0)) Q:'X!($P($G(^TMP("PSJMR",$J,1)),"^",3)=X)
  1. . S MRNODE=$G(^PS(51.2,X,0))
  1. . I $P($G(MRNODE),"^",4)'=1 Q
  1. . S ^TMP("PSJMR",$J,MCT)=$P(MRNODE,U)_U_$P(MRNODE,U,3)_U_X_U_$P(MRNODE,U,2)_U_$S($P(MRNODE,U,6):1,1:0),MCT=MCT+1
  1. S X=0
  1. I $D(^PS(50.606,PSJDFNO,"NOUN")) F Z=0:0 S Z=$O(^PS(50.606,PSJDFNO,"NOUN",Z)) Q:'Z S X=X+1,^TMP("PSJNOUN",$J,X)=$P($G(^PS(50.606,PSJDFNO,"NOUN",Z,0)),U)_U_$P($G(^PS(50.606,PSJDFNO,"MISC")),U)_U_$P($G(^("MISC")),U,3)
  1. Q
  1. ;
  1. MEDROUTE ;* Return all med routes in the med routes file.
  1. S (MR,MCT)=0 K ^TMP("PSJMR",$J)
  1. F S MR=$O(^PS(51.2,MR)) Q:'MR S MRNODE=^PS(51.2,MR,0) I $P(^PS(51.2,MR,0),"^",4)=1 S MCT=MCT+1,^TMP("PSJMR",$J,MCT)=$P(MRNODE,U)_U_$P(MRNODE,U,3)_U_MR_U_$P(MRNODE,U,2)_U_$S($P(MRNODE,U,6):1,1:0)
  1. Q
  1. NOD K ^TMP("PSJMR",$J)
  1. S MR=+$P($G(^PS(50.7,+PSJORD,0)),"^",6) I MR,$D(^PS(51.2,MR,0)),$P(^PS(51.2,MR,0),"^",4)=1 S ^TMP("PSJMR",$J,1)=$P(^PS(51.2,MR,0),"^")_U_$P(^(0),"^",3)_U_MR_U_$P(^(0),"^",2)_U_$S($P(^(0),"^",6):1,1:0)_"^D"
  1. Q
  1. START1(PSJORD,PSJQOF) ;Entry point for IV dialog PSS*1*94
  1. ; This is the new entry point for the IV Dialog box from CPRS GUI 27. PSJORD will be an array
  1. ; sent by CPRS that contains all the IENS for all orderable items that are part of the order. The zero node of the array
  1. ; will contain the total number of orderable items in the order.
  1. ;
  1. ; PSJQOF is the quick order flag. 0=not a quick order 1=quick order
  1. ;
  1. ; If there is only one orderable item, any default defined in the Pharmacy Orderable Item file (50.7) will be
  1. ; marked with a D at the end of the data string.
  1. ;
  1. ; PSS*1*142
  1. ; If there is more than one orderable item in the order,
  1. ; and if all orderable items share the same default med route, the med route will be denoted
  1. ; with a "D" at the end of the data string, and a union (the overlapping)
  1. ; of the med routes will be returned. For example if Dextrose can be given IV or IM, and the Ampicillin is only
  1. ; given IM, IM is the only med route that will be returned because it is the only overlapping med route between
  1. ; the two orderable items. If there is no overlapping med route to be returned, then a NULL will be returned to CPRS.
  1. ;
  1. ; If the quick order flag PSJQOF is set to 1, then CPRS is expecting the overlapping med routes for the orderable items
  1. ; as well as the entire list of med routes that are flagged for IV's.
  1. ;
  1. I PSJQOF="" S PSJQOF=0
  1. K PSJORD1,^TMP("PSJMR",$J)
  1. I $G(PSJORD(0))=1 S PSJOPAC="I" D Q
  1. . S PSJORD=$P($G(PSJORD(1)),"^",1)
  1. . D MEDRT(PSJORD)
  1. . I PSJQOF=1 S MCT=$O(^TMP("PSJMR",$J,"A"),-1) D ALLMED(MCT)
  1. . M PSJORD1=^TMP("PSJMR",$J)
  1. . D REMDUP
  1. . K PSJORD
  1. . M PSJORD=PSJORD1
  1. . K PSJORD1,^TMP("PSJMR",$J)
  1. S X=0
  1. F S X=$O(PSJORD(X)) Q:X="" D
  1. . S PSJORD=$P($G(PSJORD(X)),"^",1)
  1. . D MEDRT(PSJORD)
  1. . M PSJORD1(X)=^TMP("PSJMR",$J) K ^TMP("PSJMR",$J) ;Start with fresh TMP for each OI
  1. D OVERLAP
  1. I PSJQOF=1 S MCT=$O(MRTEMP2("A"),-1) D ALLMED(MCT)
  1. M PSJORD1=^TMP("PSJMR",$J)
  1. D REMDUP
  1. D MULTIDEF(.PSJORD,.PSJORD1) ;Multiple orderable items in order - do they share same default med route?
  1. K PSJORD
  1. M PSJORD=PSJORD1
  1. K PSJORD1,MRTEMP2,MRTEMP,MRNODE,MRNODE1,^TMP("PSJMR",$J),PSSCNTR1,PSJOPAC,ZZX,SAMEDEF,DEFAULT
  1. Q
  1. MEDRT(PSJORD) ;All Med Routes for dosage form.
  1. N MR,X,PSJDFNO,MCT,PM,II
  1. S (MR,MCT,X,PSJDFNO)=0,MCT=1
  1. S PSJDFNO=+$P($G(^PS(50.7,+PSJORD,0)),U,2)
  1. S MR=+$P($G(^PS(50.7,+PSJORD,0)),"^",6) I MR,$D(^PS(51.2,MR,0)),$P($G(^(0)),"^",4)=1 S ^TMP("PSJMR",$J,1)=MR_U_$P(^PS(51.2,MR,0),"^")_U_$P(^(0),"^",3)_U_$P(^(0),"^",2)_U_"D",MCT=MCT+1
  1. ; Populate possible med routes
  1. I $P($G(^PS(50.7,+PSJORD,0)),"^",13)'="Y" D S:$O(^TMP("PSJMR",$J,""),-1)=1 $P(^TMP("PSJMR",$J,1),U,5)="D" Q
  1. . S II=0 F S II=$O(^PS(50.7,+PSJORD,3,II)) Q:'II S PM=$G(^(II,0)) D
  1. . . Q:PM=+$P($G(^PS(50.7,+PSJORD,0)),"^",6) I PM,$D(^PS(51.2,PM,0)),$P($G(^(0)),"^",4)=1 S ^TMP("PSJMR",$J,MCT)=PM_U_$P(^PS(51.2,PM,0),"^")_U_$P(^(0),"^",3)_U_$P(^(0),"^",2)_U,MCT=MCT+1
  1. S MR=0 F S MR=$O(^PS(50.606,PSJDFNO,"MR",MR)) Q:'MR D
  1. . S X=+$G(^PS(50.606,PSJDFNO,"MR",MR,0))
  1. . I X=$P($G(^PS(50.7,+PSJORD,0)),"^",6) Q ;Already counted as the default. Don't count twice.
  1. . S MRNODE=$G(^PS(51.2,X,0))
  1. . I $P($G(MRNODE),"^",4)'=1 Q
  1. . S ^TMP("PSJMR",$J,MCT)=X_U_$P(MRNODE,U)_U_$P(MRNODE,U,3)_U_$P(MRNODE,U,2)_U,MCT=MCT+1
  1. Q
  1. ALLMED(MCT) ;Return all med routes with IV flag set to 1
  1. N MR,MRNODE
  1. I MCT="" S MCT=0
  1. S (MR,MRNODE)=""
  1. F S MR=$O(^PS(51.2,MR)) Q:MR="" D
  1. . S MRNODE=$G(^PS(51.2,MR,0))
  1. . I $P(MRNODE,U,4)'=1 Q ;Not defined for all packages
  1. . I $P(MRNODE,U,6)'=1 Q ;IV flag not set
  1. . S MCT=MCT+1,^TMP("PSJMR",$J,MCT)=MR_U_$P(MRNODE,U)_U_$P(MRNODE,U,3)_U_$P(MRNODE,U,2)_U
  1. Q
  1. OVERLAP ; Only maintains any overlapping med routes between orderable items in order
  1. N MR,MRNODE,X,PSSCNTR1
  1. K MRTEMP,MRTEMP2
  1. S (MR,MRNODE,X)=""
  1. F S X=$O(PSJORD1(X)) Q:X="" D
  1. . F S MR=$O(PSJORD1(X,MR)) Q:MR="" D
  1. . . S MRNODE=$P($G(PSJORD1(X,MR)),"^",1)
  1. . . S MRTEMP(MRNODE)=$G(MRTEMP(MRNODE))+1
  1. S MR=""
  1. F S MR=$O(MRTEMP(MR)) Q:MR="" D
  1. . I MRTEMP(MR)'=$G(PSJORD(0)) K MRTEMP(MR) Q
  1. I '$D(MRTEMP) K PSJORD1 S PSJORD1="" Q ;No overlapping med routes between orderable items.
  1. S (MR,MRNODE)="",PSSCNTR1=1
  1. F S MR=$O(MRTEMP(MR)) Q:MR="" D
  1. . S MRNODE=$G(^PS(51.2,MR,0))
  1. . S MRTEMP2(PSSCNTR1)=MR_U_$P(MRNODE,U,1)_U_$P(MRNODE,U,3)_U_$P(MRNODE,U,2)_U,PSSCNTR1=PSSCNTR1+1
  1. K PSJORD1,MRTEMP
  1. M PSJORD1=MRTEMP2
  1. Q
  1. REMDUP ; Remove duplicate entries
  1. N MR,MRNODE
  1. S MR="",MRNODE=""
  1. F S MR=$O(PSJORD1(MR)) Q:MR="" D
  1. . S MRNODE=$P($G(PSJORD1(MR)),"^",2)
  1. . I $D(MRTEMP(MRNODE)) K PSJORD1(MR) Q
  1. . S MRTEMP(MRNODE)=$G(PSJORD1(MR))
  1. . I MR=1,$P($G(PSJORD1(MR)),"^",5)="D" S MRTEMP(MR)=PSJORD1(MR) Q ;Maintain default if there is one.
  1. . S MRTEMP(MR)=PSJORD1(MR)
  1. S MR=""
  1. F S MR=$O(MRTEMP(MR)) Q:MR="" D
  1. . I MR'?1.N K MRTEMP(MR)
  1. I PSJORD(0)=1 M PSJORD1=MRTEMP
  1. K MRTEMP
  1. Q
  1. MULTIDEF(PSJORD,PSJORD1) ; PSS*1*142
  1. ;Loop through the orderable items for the order. Determine what (if any) default
  1. ;med route is for each orderable item. Save this in the DEFAULT local array.
  1. ;Then compare the DEFAULT array entries with each other. If any one of the subsequent
  1. ;entries does not match the first one, that means the orderable items do not all share
  1. ;the same default, and no med route will be marked as the default when the information
  1. ;is returned to CPRS. If all of the orderable items share the same default, find that
  1. ;entry in the array of orderable items, and mark it as the default with a "D".
  1. S ZZX=0,DEFAULT=""
  1. F S ZZX=$O(PSJORD(ZZX)) Q:ZZX="" D
  1. . S DEFAULT=$G(PSJORD(ZZX))
  1. . S DEFAULT(ZZX)=$P($G(^PS(50.7,DEFAULT,0)),"^",6)
  1. S ZZX="",SAMEDEF=0
  1. F S ZZX=$O(DEFAULT(ZZX)) Q:ZZX="" D Q:SAMEDEF=0
  1. . I DEFAULT(ZZX)'=$G(DEFAULT(1)) S SAMEDEF=0 Q
  1. . S SAMEDEF=1_"^"_$G(DEFAULT(1))
  1. Q:SAMEDEF=0
  1. I $P($G(SAMEDEF),"^")=1,$P($G(SAMEDEF),"^",2)="" Q ;No orderable item has a valid default - default is ""
  1. S ZZX=""
  1. F S ZZX=$O(PSJORD1(ZZX)) Q:ZZX="" D
  1. . I $P($G(PSJORD1(ZZX)),"^",1)=$P($G(SAMEDEF),"^",2) S PSJORD1(ZZX)=PSJORD1(ZZX)_"D"
  1. Q
  1. ;
  1. IND ;*187 - indications for use
  1. K ^TMP("PSJIND",$J)
  1. N IND,I,ARR,K S K=0,I=""
  1. I $P($G(^PS(50.7,PSJORD,4)),"^",2)]"" S K=K+1,^TMP("PSJIND",$J,K)=$$ENLU^PSSGMI($P(^PS(50.7,PSJORD,4),"^",2))_"^d"
  1. F S I=$O(^PS(50.7,PSJORD,"IND","B",I)) Q:I="" D
  1. .S IND=$$ENLU^PSSGMI(I) ;convert to uppercase
  1. .I '$D(ARR(IND)) S ARR(IND)=""
  1. S I="" F S I=$O(ARR(I)) Q:I="" S K=K+1,^TMP("PSJIND",$J,K)=I
  1. Q