OCXOZ0C	;SLC/RJS,CLA - Order Check Scan ;NOV 8,2009 at 18:44
	;;3.0;ORDER ENTRY/RESULTS REPORTING;**32,221,243**;Dec 17,1997;Build 242
	;;  ;;ORDER CHECK EXPERT version 1.01 released OCT 29,1998
	;
	; ***************************************************************
	; ** Warning: This routine is automatically generated by the   **
	; ** Rule Compiler (^OCXOCMP) and ANY changes to this routine  **
	; ** will be lost the next time the rule compiler executes.    **
	; ***************************************************************
	;
	Q
	;
CHK302	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK6+19^OCXOZ02.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK302 Variables
	; OCXDF(34) ---> Data Field: ORDER NUMBER (NUMERIC)
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(55) ---> Data Field: SITE FLAGGED RESULT (BOOLEAN)
	; OCXDF(96) ---> Data Field: ORDERABLE ITEM NAME (FREE TEXT)
	; OCXDF(147) --> Data Field: PATIENT LOCATION (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,102, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: SITE FLAGGED FINAL IMAGING RESULT)
	; ORDITEM( ---------> GET ORDERABLE ITEM FROM ORDER NUMBER
	; PATLOC( ----------> PATIENT LOCATION
	;
	I $L(OCXDF(55)),(OCXDF(55)) S OCXDF(96)=$$ORDITEM(OCXDF(34)),OCXDF(147)=$P($$PATLOC(OCXDF(37)),"^",2),OCXOERR=$$FILE(DFN,102,"9,96,147") Q:OCXOERR 
	Q
	;
CHK314	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK35+18^OCXOZ04.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK314 Variables
	; OCXDF(113) --> Data Field: LAB TEST ID (NUMERIC)
	; OCXDF(114) --> Data Field: LAB TEST PRINT NAME (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,103, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: HL7 LAB TEST RESULTS ABNORMAL)
	;
	I $L(OCXDF(113)) S OCXDF(114)=$$PRINTNAM^ORQQLR1(OCXDF(113)),OCXOERR=$$FILE(DFN,103,"12,13,96,114") Q:OCXOERR 
	Q
	;
CHK324	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK34+16^OCXOZ04.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK324 Variables
	; OCXDF(34) ---> Data Field: ORDER NUMBER (NUMERIC)
	; OCXDF(96) ---> Data Field: ORDERABLE ITEM NAME (FREE TEXT)
	; OCXDF(113) --> Data Field: LAB TEST ID (NUMERIC)
	; OCXDF(114) --> Data Field: LAB TEST PRINT NAME (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,105, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: HL7 LAB ORDER RESULTS CRITICAL)
	; ORDITEM( ---------> GET ORDERABLE ITEM FROM ORDER NUMBER
	;
	S OCXDF(96)=$$ORDITEM(OCXDF(34)) I $L(OCXDF(113)) S OCXDF(114)=$$PRINTNAM^ORQQLR1(OCXDF(113)),OCXOERR=$$FILE(DFN,105,"12,13,96,114") Q:OCXOERR 
	Q
	;
CHK336	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK6+20^OCXOZ02.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK336 Variables
	; OCXDF(34) ---> Data Field: ORDER NUMBER (NUMERIC)
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(55) ---> Data Field: SITE FLAGGED RESULT (BOOLEAN)
	; OCXDF(96) ---> Data Field: ORDERABLE ITEM NAME (FREE TEXT)
	; OCXDF(147) --> Data Field: PATIENT LOCATION (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,109, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: SITE FLAGGED FINAL CONSULT RESULT)
	; ORDITEM( ---------> GET ORDERABLE ITEM FROM ORDER NUMBER
	; PATLOC( ----------> PATIENT LOCATION
	;
	I $L(OCXDF(55)),(OCXDF(55)) S OCXDF(96)=$$ORDITEM(OCXDF(34)),OCXDF(147)=$P($$PATLOC(OCXDF(37)),"^",2),OCXOERR=$$FILE(DFN,109,"9,96,147") Q:OCXOERR 
	Q
	;
CHK347	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK58+20^OCXOZ05.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK347 Variables
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(131) --> Data Field: PHARMACY LOCAL ID (FREE TEXT)
	; OCXDF(136) --> Data Field: CLOZAPINE ANC W/IN 7 FLAG (BOOLEAN)
	; OCXDF(137) --> Data Field: CLOZAPINE ANC W/IN 7 RESULT (NUMERIC)
	; OCXDF(139) --> Data Field: CLOZAPINE WBC W/IN 7 FLAG (BOOLEAN)
	; OCXDF(140) --> Data Field: CLOZAPINE WBC W/IN 7 RESULT (NUMERIC)
	;
	;      Local Extrinsic Functions
	;
	S OCXDF(137)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",3),";",2) I $L(OCXDF(137)) D CHK349
	S OCXDF(136)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",3),";",1) I $L(OCXDF(136)),'(OCXDF(136)) D CHK371^OCXOZ0D
	S OCXDF(139)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",2),";",1) I $L(OCXDF(139)),'(OCXDF(139)) D CHK375^OCXOZ0D
	S OCXDF(140)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",2),";",2) I $L(OCXDF(140)) D CHK378^OCXOZ0D
	Q
	;
CHK349	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK347+15.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK349 Variables
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(131) --> Data Field: PHARMACY LOCAL ID (FREE TEXT)
	; OCXDF(136) --> Data Field: CLOZAPINE ANC W/IN 7 FLAG (BOOLEAN)
	; OCXDF(137) --> Data Field: CLOZAPINE ANC W/IN 7 RESULT (NUMERIC)
	;
	;      Local Extrinsic Functions
	;
	I (OCXDF(137)<1.5) S OCXDF(136)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",3),";",1) I $L(OCXDF(136)),(OCXDF(136)) D CHK353
	I (OCXDF(137)>1.499) D CHK355
	Q
	;
CHK353	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK349+13.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK353 Variables
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(130) --> Data Field: CLOZAPINE LAB RESULTS (FREE TEXT)
	; OCXDF(131) --> Data Field: PHARMACY LOCAL ID (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,114, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: CLOZAPINE ANC < 1.5)
	;
	S OCXDF(130)=$P($$CLOZLABS^ORKLR(OCXDF(37),"",OCXDF(131)),"^",4),OCXOERR=$$FILE(DFN,114,"130") Q:OCXOERR 
	Q
	;
CHK355	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK349+14.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK355 Variables
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(131) --> Data Field: PHARMACY LOCAL ID (FREE TEXT)
	; OCXDF(136) --> Data Field: CLOZAPINE ANC W/IN 7 FLAG (BOOLEAN)
	; OCXDF(137) --> Data Field: CLOZAPINE ANC W/IN 7 RESULT (NUMERIC)
	;
	;      Local Extrinsic Functions
	;
	S OCXDF(136)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",3),";",1) I $L(OCXDF(136)),(OCXDF(136)) D CHK358
	I (OCXDF(137)<"2.0") S OCXDF(136)=$P($P($$CLOZLABS^ORKLR(OCXDF(37),7,OCXDF(131)),"^",3),";",1) I $L(OCXDF(136)),(OCXDF(136)) D CHK505^OCXOZ0G
	Q
	;
CHK358	; Look through the current environment for valid Event/Elements for this patient.
	;  Called from CHK355+13.
	;
	Q:$G(OCXOERR)
	;
	;    Local CHK358 Variables
	; OCXDF(37) ---> Data Field: PATIENT IEN (NUMERIC)
	; OCXDF(130) --> Data Field: CLOZAPINE LAB RESULTS (FREE TEXT)
	; OCXDF(131) --> Data Field: PHARMACY LOCAL ID (FREE TEXT)
	;
	;      Local Extrinsic Functions
	; FILE(DFN,115, ----> FILE DATA IN PATIENT ACTIVE DATA FILE  (Event/Element: CLOZAPINE ANC >= 1.5)
	;
	S OCXDF(130)=$P($$CLOZLABS^ORKLR(OCXDF(37),"",OCXDF(131)),"^",4),OCXOERR=$$FILE(DFN,115,"130") Q:OCXOERR 
	Q
	;
FILE(DFN,OCXELE,OCXDFL)	;     This Local Extrinsic Function logs a validated event/element.
	;
	N OCXTIMN,OCXTIML,OCXTIMT1,OCXTIMT2,OCXDATA,OCXPC,OCXPC,OCXVAL,OCXSUB,OCXDFI
	S DFN=+$G(DFN),OCXELE=+$G(OCXELE)
	;
	Q:'DFN 1 Q:'OCXELE 1 K OCXDATA
	;
	S OCXDATA(DFN,OCXELE)=1
	F OCXPC=1:1:$L(OCXDFL,",") S OCXDFI=$P(OCXDFL,",",OCXPC) I OCXDFI D
	.S OCXVAL=$G(OCXDF(+OCXDFI)),OCXDATA(DFN,OCXELE,+OCXDFI)=OCXVAL
	;
	M ^TMP("OCXCHK",$J,DFN)=OCXDATA(DFN)
	;
	Q 0
	;
ORDITEM(OIEN)	;  Compiler Function: GET ORDERABLE ITEM FROM ORDER NUMBER
	Q:'$G(OIEN) ""
	;
	N OITXT,X S OITXT=$$OI^ORQOR2(OIEN) Q:'OITXT "No orderable item found."
	S X=$G(^ORD(101.43,+OITXT,0)) Q:'$L(X) "No orderable item found."
	Q $P(X,U,1)
	;
PATLOC(DFN)	;  Compiler Function: PATIENT LOCATION
	;
	N OCXP1,OCXP2
	S OCXP1=$G(^TMP("OCXSWAP",$J,"OCXODATA","PV1",2))
	S OCXP2=$P($G(^TMP("OCXSWAP",$J,"OCXODATA","PV1",3)),"^",1)
	I OCXP2 D
	.S OCXP2=$P($G(^SC(+OCXP2,0)),"^",1,2)
	.I $L($P(OCXP2,"^",2)) S OCXP2=$P(OCXP2,"^",2)
	.E  S OCXP2=$P(OCXP2,"^",1)
	.S:'$L(OCXP2) OCXP2="NO LOC"
	I $L(OCXP1),$L(OCXP2) Q OCXP1_"^"_OCXP2
	;
	S OCXP2=$G(^DPT(+$G(DFN),.1))
	I $L(OCXP2) Q "I^"_OCXP2
	Q "O^OUTPT"
	;
