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

BQIGPORD.m

Go to the documentation of this file.
BQIGPORD ;VNGT/HS/BEE-Group Order Entry ; 17 Jun 2011  12:38 PM
 ;;2.3;ICARE MANAGEMENT SYSTEM;;Apr 18, 2012;Build 59
 ;
ORD(DATA,DFN,PARMS) ;EP -- BQI GROUP ORDER ENTRY
 ;
 NEW UID,II,HDR,IX,LIST,PC,LST,ORDTEXT,OUTLST,BQIDX,VFIEN
 NEW BQIORD,BQISTDT,BQITEXT,BQIPROV,BQILOC,ORDITM,ORDNAM,BQ
 ;
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIGPORD",UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIGPORD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 ;Define Header
 S HDR="T00001RESULT^T00050ERROR_MESSAGE^I00010DFN^I00010ORDER_NUMBER"_$C(30)
 S @DATA@(II)=HDR
 ;
 S VFIEN=$O(^BQI(90506.3,"B","Group Order Entry",""))
 I VFIEN="" S BMXSEC="RPC Call Failed: Group Order Entry" Q
 ;
 S DFN=$G(DFN,"")
 ;
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . N LIST,BN
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 . K LIST
 ;
 ;Pull Parameter Data
 F BQ=1:1:$L(PARMS,$C(28)) D  Q:$G(BMXSEC)'=""
 . N CHIEN,FIELD,NAME,PDATA,PFIEN,PTYP,VALUE
 . S PDATA=$P(PARMS,$C(28),BQ) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1) I NAME="" Q
 . S VALUE=$P(PDATA,"=",2,99)
 . S PFIEN=$O(^BQI(90506.3,VFIEN,10,"AC",NAME,""))
 . I PFIEN="" S BMXSEC=NAME_" not a valid parameter for this update" Q
 . S FIELD=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,3)),U,1)
 . I VALUE="",FIELD'=".001" S VALUE="@"
 . S PTYP=$P($G(^BQI(90506.3,VFIEN,10,PFIEN,1)),U,1)
 . I PTYP="D"!(PTYP="A") S VALUE=$$DATE^BQIUL1(VALUE)
 . I PTYP="C" D
 .. S CHIEN=$O(^BQI(90506.3,VFIEN,10,PFIEN,5,"B",VALUE,"")) I CHIEN="" Q
 .. S VALUE=$P(^BQI(90506.3,VFIEN,10,PFIEN,5,CHIEN,0),U,2)
 . S @NAME=VALUE
 ;
 ;Set up information for API call
 S LST(1,"DFN")=DFN
 S LST(1,"PRV")=BQIPROV
 S:$G(BQIDX)]"" LST(1,"CLN")=BQIDX
 ;
 S ORDITM=$$GET1^DIQ(90621,BQIORD_",",.11,"I") G DONE:ORDITM=""
 S ORDNAM=$$GET1^DIQ(101.43,ORDITM_",",.01,"E")
 ;
 S ORDTEXT(1,0)=ORDNAM_" created from Group Order entry in iCare."
 ;
 ;Parse out incoming text
 N CNT,I,LN,CH,LINE
 S CNT=1 F I=1:1 Q:$L(BQITEXT)=0  D
 . S LN=$E(BQITEXT,1,80)
 . F CH=$L(LN):-1:1 I $E(LN,CH)=" " Q
 . I $L(BQITEXT)<81 S BQITEXT="",LINE=LN
 . E  I CH>1 S BQITEXT=$E(BQITEXT,CH+1,999999),LINE=$E(LN,1,CH-1)
 . E  S BQITEXT=$E(BQITEXT,81,999999),LINE=LN
 . S CNT=CNT+1,ORDTEXT(CNT,0)=LINE
 S ORDTEXT(0)="^100.0451^"_CNT_U_CNT_U_DT_U_U
 K CNT,I,LN,CH,LINE
 ;
 ;Check for duplicate orders
 ;
 ;Pull all active orders
 D AGET^ORWORR("",DFN,2,"","","","")
 I $D(^TMP("ORR",$J)) D
 . ;
 . ;Look for duplicate order
 . NEW ORLIST,CNT,ORD
 . S ORLIST="" F  S ORLIST=$O(^TMP("ORR",$J,ORLIST)) Q:ORLIST=""  D  Q:$D(OUTLST)
 .. S CNT=.1 F  S CNT=$O(^TMP("ORR",$J,ORLIST,CNT)) Q:'CNT  D  Q:$D(OUTLST)
 ... S ORD=$P($P($G(^TMP("ORR",$J,ORLIST,CNT)),U),";")
 ... I $D(^OR(100,ORD,.1,"B",ORDITM)) S OUTLST(1)="^^DUPLICATE ORDER - ORIGINAL ORDER #"_ORD
 . K ^TMP("ORR",$J)
 ;
 ;Call Group Order API
 I '$D(OUTLST) D GRPORD^BEHOOGP(.OUTLST,.LST,ORDITM,BQISTDT,BQILOC,"",.ORDTEXT)
 ;
 ;Return Success/Failure Information
 S II=$G(II)+1
 I $P($G(OUTLST(1)),U,3)="ORDER CREATED" S @DATA@(II)="1^"_U_DFN_U_$P(OUTLST(1),U,2)_$C(30)
 I $G(OUTLST(0))'="" S @DATA@(II)="0^"_$G(OUTLST(0))_U_DFN_U_$C(30)
 ;
DONE ;
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
MACT(DATA,FAKE) ;EP -- BQI CHK SCR MAMM STS
 NEW UID,II,ACTIVE,DIC,X,IEN,Y
 ;
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIGPORD",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIGPORD D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S @DATA@(II)="T00001ACTIVE"_$C(30)
 ;
 S ACTIVE="Y"
 S DIC="^ORD(101.43,",DIC(0)="X"
 S X="SCREENING MAMMOGRAM"
 D ^DIC
 S IEN=+Y
 I IEN="-1" S ACTIVE="N" G XMACT
 ;
 ;Check if INACTIVE
 S X=$$GET1^DIQ(101.43,IEN_",",.1,"I")
 I X]"",X<DT S ACTIVE="N"
 ;
XMACT S II=II+1,@DATA@(II)=ACTIVE_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
ERR ;
 D ^%ZTER
 NEW Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
 Q