ORWGAPI4	; SLC/STAFF - Graph Data, indexed ;8/21/06  07:52
	;;3.0;ORDER ENTRY/RESULTS REPORTING;**215,260,243**;Dec 17, 1997;Build 242
	;
EDU(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(9000010.16,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(9000010.16,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D EDU^ORWGAPIA(NODE,.VALUE,.VALUES)
	.. S VALUE=VALUE("VALUE"),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.16,.06)_U_VALUES ;*****************************
	.. S RESULT=9000010.16_U_ITEM_U_DATE_"^^" ;_VALUE
	.. S RESULT=9000010.16_U_ITEM_U_DATE_U_DATE2_U ;_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
EXAM(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(9000010.13,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(9000010.13,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D EXAM^ORWGAPIA(NODE,.VALUE,.VALUES)
	.. S VALUE=$G(VALUE("VALUE")),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.13,.04)_U_VALUES ;*****************************
	.. S RESULT=9000010.13_U_ITEM_U_DATE_U_DATE2_U_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
HF(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(9000010.23,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(9000010.23,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D HF^ORWGAPIA(NODE,.VALUE,.VALUES)
	.. S VALUE=VALUE("VALUE"),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.23,.04)_U_VALUES ;*****************************
	.. S RESULT=9000010.23_U_ITEM_U_DATE_U_DATE2_U_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
IMM(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(9000010.11,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(9000010.11,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D IMM^ORWGAPIA(NODE,.VALUE,.VALUES)
	.. S VALUE=$G(VALUE("VALUE")),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.11,.04)_U_VALUES ;*****************************
	.. S CNT=CNT+1
	.. S RESULT=9000010.11_U_ITEM_U_DATE_U_DATE2_U_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
MH(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(601.2,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(601.2,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D MH^ORWGAPIA(.VALUE,NODE,.VALUES) S VALUE=$P($G(VALUE(2)),U,2,3)_U_VALUES ;*****************************
	.. S RESULT=601.2_U_ITEM_U_DATE_U_DATE2_U ;_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
OP(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,NUM,RESULT,VALUE,VALUES K VALUE
	S DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO),VALUES=""
	S NUM=""
	F  S NUM=$O(^PXRMINDX(45,"ICD0","PNI",DFN,NUM)) Q:NUM=""  D
	. S DATE=""
	. F  S DATE=$O(^PXRMINDX(45,"ICD0","PNI",DFN,NUM,ITEM,DATE)) Q:DATE=""  D
	.. I DATE>START Q
	.. I DATE<BACKTO Q
	.. S NODE=""
	.. F  S NODE=$O(^PXRMINDX(45,"ICD0","PNI",DFN,NUM,ITEM,DATE,NODE)) Q:NODE=""  D
	... I '$L($G(^DGPT(+NODE,0))) Q  ; ****** remove this when PTF patch is released **********
	... D PTF^ORWGAPIA(NODE,.VALUE,.VALUES) S VALUE=$G(VALUE("DISCHARGE STATUS"))_U_VALUES ;*****************************
	... S RESULT=45_"OP"_U_ITEM_U_DATE_U_DATE2_U ;_VALUE
	... D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
POV(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,TYPE,VALUE,VALUES K VALUE
	S DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	S TYPE=""
	F  S TYPE=$O(^PXRMINDX(9000010.07,"PPI",DFN,TYPE)) Q:TYPE=""  D
	. S DATE=""
	. F  S DATE=$O(^PXRMINDX(9000010.07,"PPI",DFN,TYPE,ITEM,DATE)) Q:DATE=""  D
	.. I DATE>START Q
	.. I DATE<BACKTO Q
	.. S NODE=""
	.. F  S NODE=$O(^PXRMINDX(9000010.07,"PPI",DFN,TYPE,ITEM,DATE,NODE)) Q:NODE=""  D
	... D POV^ORWGAPIA(NODE,.VALUE,.VALUES)
	... S VALUE=VALUE("CLINICAL TERM"),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.07,.15)_U_VALUES ;*****************************
	... S CNT=CNT+1
	... S RESULT=9000010.07_U_ITEM_U_DATE_U_DATE2_U_VALUE
	... D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
PROB(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,DTONSET,DTRESOLV,ICD9,NODE,PRIORITY,PROB,PROBDX,PSTATUS,RESULT,STATUS,VALUE
	K ^TMP("ORWGRPC TEMP",$J)
	S DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	S STATUS=""
	F  S STATUS=$O(^PXRMINDX(9000011,"PSPI",DFN,STATUS)) Q:STATUS=""  D
	. S PRIORITY=""
	. F  S PRIORITY=$O(^PXRMINDX(9000011,"PSPI",DFN,STATUS,PRIORITY)) Q:PRIORITY=""  D
	.. S DATE=""
	.. F  S DATE=$O(^PXRMINDX(9000011,"PSPI",DFN,STATUS,PRIORITY,ITEM,DATE)) Q:DATE=""  D
	... I DATE>START Q
	... I DATE<BACKTO Q
	... S NODE=""
	... F  S NODE=$O(^PXRMINDX(9000011,"PSPI",DFN,STATUS,PRIORITY,ITEM,DATE,NODE)) Q:NODE=""  D
	.... S ^TMP("ORWGRPC TEMP",$J,ITEM,DATE,NODE)=""
	S ICD9=""
	F  S ICD9=$O(^TMP("ORWGRPC TEMP",$J,ICD9)) Q:ICD9=""  D
	. S DATE=""
	. F  S DATE=$O(^TMP("ORWGRPC TEMP",$J,ICD9,DATE)) Q:DATE=""  D
	.. S NODE=""
	.. F  S NODE=$O(^TMP("ORWGRPC TEMP",$J,ICD9,DATE,NODE)) Q:NODE=""  D
	... D PROB^ORWGAPIA(.PROB,.PSTATUS,.PROBDX,.DTONSET,.DTRESOLV,NODE)
	... S RESULT=9000011_U_ITEM_U_DTONSET_U_DATE2_U_$$EXT^ORWGAPIX(PSTATUS,9000011,.12)
	... D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	K ^TMP("ORWGRPC TEMP",$J)
	Q
	;
PROBX(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	D PROBX4^ORWGAPID(.DATA,ITEM,START,DFN,.CNT,.TMP)
	Q
	;
PROC(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,TYPE,VALUE,VALUES K VALUE
	S DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	S TYPE=""
	F  S TYPE=$O(^PXRMINDX(9000010.18,"PPI",DFN,TYPE)) Q:TYPE=""  D
	. S DATE=""
	. F  S DATE=$O(^PXRMINDX(9000010.18,"PPI",DFN,TYPE,ITEM,DATE)) Q:DATE=""  D
	.. I DATE>START Q
	.. I DATE<BACKTO Q
	.. S NODE=""
	.. F  S NODE=$O(^PXRMINDX(9000010.18,"PPI",DFN,TYPE,ITEM,DATE,NODE)) Q:NODE=""  D
	... D CPT^ORWGAPIA(NODE,.VALUE,.VALUES)
	... S VALUE=VALUE("PRINCIPAL PROCEDURE"),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.18,.07)_U_VALUES ;*****************************
	... S RESULT=9000010.18_U_ITEM_U_DATE_U_DATE2_U_VALUE
	... D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
SKIN(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(9000010.12,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(9000010.12,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D SKIN^ORWGAPIA(NODE,.VALUE,.VALUES)
	.. S VALUE=$G(VALUE("VALUE")),VALUE=VALUE_U_$$EVALUE^ORWGAPIU(VALUE,9000010.12,.04)_U_VALUES ;*****************************
	.. S CNT=CNT+1
	.. S RESULT=9000010.12_U_ITEM_U_DATE_U_DATE2_U_VALUE
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
VITAL(DATA,ITEM,START,DFN,CNT,TMP,BACKTO)	; from ORWGAPIR
	I ITEM=99999 D BMIDATA^ORWGAPIX(.DATA,ITEM,START,DFN,.CNT,TMP) Q
	N DATE,DATE2,NODE,RESULT,VALUE,VALUES K VALUE
	S DATE="",DATE2="",CNT=$G(CNT),BACKTO=+$G(BACKTO)
	F  S DATE=$O(^PXRMINDX(120.5,"PI",DFN,ITEM,DATE)) Q:DATE=""  D
	. I DATE>START Q
	. I DATE<BACKTO Q
	. S NODE=""
	. F  S NODE=$O(^PXRMINDX(120.5,"PI",DFN,ITEM,DATE,NODE)) Q:NODE=""  D
	.. D VITAL^ORWGAPIA(.VALUE,NODE,.VALUES) S VALUE=$P($G(VALUE(7)),U)
	.. I $P($G(VALUE(3)),U,2)="PAIN",VALUE=99 S VALUE="(99)"
	.. S RESULT=120.5_U_ITEM_U_DATE_U_DATE2_U_VALUE_U_U_VALUES ;*****************************
	.. D SETUP^ORWGAPIW(.DATA,RESULT,TMP,.CNT)
	Q
	;
