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

ONCRPC.m

Go to the documentation of this file.
ONCRPC ;Hines OIFO/GWB - Extract VACCR data via ONC VACCR RPC ;09/22/11
 ;;2.2;ONCOLOGY;**1**;Jul 31, 2013;Build 8
 ;;
EN1(RESULT,DATEUSED,START,END) ;Entry point
 K ^TMP("ONCRPC")
 N VERSION
 S VERSION=$O(^ONCO(160.16,"B","VACCR EXTRACT"))
 S EXTRACT=$O(^ONCO(160.16,"B",VERSION,0))
 S OUT=0
 S U="^"
 D SETUP
 S RESULT=$NA(^TMP("ONCRPC"))
 Q
 ;
SETUP ;Loop through appropriate cross-reference
 N BLANK,DCLC,FDNUM,IEN,NC,NINE,TPG,ZERO,ZNINE,X
 N DIVISION,FACPNT,ONCDST,ONCSAPI,OSPIEN,RC,RESULT,STAT1
 S BLANK=" "
 S (IEN,ZERO)=0
 S NINE=9,ZNINE="09"
 ;
 ;VACCR/STATE EXTRACT
 ;Loop through DATE CASE COMPLETED (165.5,90) "AAD" cross-reference
 I DATEUSED=1 S START=START-1 F  S START=$O(^ONCO(165.5,"AAD",START)) Q:(START<1)!(START>END)  F  S IEN=$O(^ONCO(165.5,"AAD",START,IEN)) Q:IEN<1  D
 .Q:$G(^ONCO(165.5,IEN,0))=""
 .D LOOP
 ;
 ;VACCR/STATE EXTRACT
 ;Loop through DATE CASE LAST CHANGED (165.5,198) "AAE" cross-reference
 I DATEUSED=2 S START=START-1 F  S START=$O(^ONCO(165.5,"AAE",START)) Q:(START<1)!(START>END)  F  S IEN=$O(^ONCO(165.5,"AAE",START,IEN)) Q:IEN<1  D
 .Q:$G(^ONCO(165.5,IEN,0))=""
 .D LOOP
 ;
 Q
 ;
LOOP ;Apply extract selection rules
 N LINE,RULES,VALID,JUMP
 S RULES=0
 F  S RULES=$O(^ONCO(160.16,EXTRACT,"RULES",RULES)) Q:RULES<1  D
 .S LINE=^ONCO(160.16,EXTRACT,"RULES",RULES,0)
 .X LINE
 Q:'VALID
 S DIVISION=$P($G(^ONCO(165.5,IEN,"DIV")),U,1)
 Q:DIVISION=""
 S OSPIEN=$O(^ONCO(160.1,"C",DIVISION,0))
 Q:OSPIEN=""
 S FACPNT=$P($G(^ONCO(160.1,OSPIEN,1)),U,4)
 Q:FACPNT=""
 S STAT1=$P($G(^ONCO(160.19,FACPNT,0)),U,1)
 S:$P(^ONCO(165.5,IEN,24),U,25)="" $P(^ONCO(165.5,IEN,24),U,25)=DT
 D OUTPUT(IEN,EXTRACT,JUMP,.OUT)
 D END^ONCSNACR(.ONCDST)
 D TRAILER^ONCSAPIR(.ONCDST)
 Q
 ;
OUTPUT(IEN,EXTRACT,JUMP,OUT) ;Output
 S ONCDST=$NA(^TMP("ONCRPC",IEN))
 S RC=$$RBQPREP^ONCSED01(.ONCSAPI,.ONCDST)
 S ACD160=$P(^ONCO(165.5,IEN,0),U,2)
 N POS S POS=0
 F  S POS=$O(^ONCO(160.16,EXTRACT,"FIELD","B",POS)) Q:POS<1  D  Q:OUT
 .N NODE S NODE=0
 .F  S NODE=$O(^ONCO(160.16,EXTRACT,"FIELD","B",POS,NODE)) Q:NODE<1  D  Q:OUT
 ..N STRING,DEFAULT,FILL,LEN
 ..Q:$G(^ONCO(160.16,EXTRACT,"FIELD",NODE,0))=""
 ..;D DISPLAY(DEVICE,$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,1)_U_$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,4),.OUT)
 ..S LEN=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,2)
 ..S STRING=$TR(^ONCO(160.16,EXTRACT,"FIELD",NODE,1),"~","^")
 ..S DEFAULT=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,2),U,1)
 ..S FILL=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,3),U,1)
 ..D DATA(IEN,ACD160,STRING,DEFAULT,FILL,LEN,JUMP,NODE,POS)
 Q
 ;
DATA(IEN,ACD160,STRING,DEFAULT,FILL,LEN,JUMP,NODE,POS) ;Compute extract value
 N ACDANS,EXIT S EXIT=0
 I JUMP'="0" D
 .I POS<$P(JUMP,U) Q
 .I POS>$P(JUMP,U,2) Q
 .N I
 .S EXIT=1
 .F I=1:1:LEN W BLANK
 Q:EXIT
 X STRING
 ;
 ;If value = "", extract DEFAULT value
 I ACDANS="" D  Q
 .N I,X S X=""
 .I DEFAULT=8 D  Q
 ..F I=1:1:LEN D WRITE^ONCSNACR(.ONCDST,DEFAULT)
 .I @DEFAULT="09" D WRITE^ONCSNACR(.ONCDST,@DEFAULT) Q
 .F I=1:1:LEN D WRITE^ONCSNACR(.ONCDST,@DEFAULT)
 ;
 ;If value too long, truncate to LENGTH (160.161,1)
 ;If value too short, pad with FILL (160.161,6)
 I $L(ACDANS)=LEN D WRITE^ONCSNACR(.ONCDST,ACDANS) Q
 I $L(ACDANS)>LEN D WRITE^ONCSNACR(.ONCDST,$E(ACDANS,1,LEN)) Q
 E  D  Q
 .N JUST,STUFF,I,REM,CAL
 .S JUST=$P(FILL,","),STUFF=$P(FILL,",",2)
 .S REM=LEN-$L(ACDANS)
 .I JUST="R" D WRITE^ONCSNACR(.ONCDST,ACDANS)
 .F I=1:1:REM D WRITE^ONCSNACR(.ONCDST,@STUFF)
 .I JUST="L" D WRITE^ONCSNACR(.ONCDST,ACDANS)
 Q
 ;
CLEANUP ;Cleanup
 K DATEUSED,END,START