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

BPCGDX.m

Go to the documentation of this file.
BPCGDX ; IHS/OIT/MJL - PROGRAM TO GET LIST OF DIAGNOSES ;
 ;;1.5;BPC;;MAY 26, 2005
DXLIST(BPCRES,BPCX,BPCMAX,BPCMORE,BPCPARAM) ;EP REMOTE PROC: BPC GETDIAGNOSISLIST
 S BPCGUI=1
 ;
 ; BPCRES     - The output array (ICD9 code data)
 ; BPCRES(1)  - Total number of entries (BPCMAX or less)
 ;  subscript - sequence number (2 thru value of BPCMAX +1)
 ;  Piece (delimited by "^")
 ;    1       - Description
 ;    2       - IEN
 ;    3       - Category (e.g.
 ;    4       - Data (in ^ICD9(code,0) )
 ; BPCX       - Input string (e.g. 250,DIAB,etc.)
 ; BPCMAX     - Maximum number of elements to return in BPCRES
 ; BPCMORE    - More data
 ;  Piece (delimited by "|")
 ;    1       - Next IEN
 ;    2       - Next ICD9 code
 ;    3       - Next description ref
 ; BPCPARAM   - Reserved for future use
 ;
EN ;
 S U="^",XWBWRAP=1,BPCCTR=0,BPCSUB=$J,BPCGUI=$G(BPCGUI),BPCLEN=$L(BPCX),BPCC="",BPCMORE=$G(BPCMORE)
 K:'BPCMORE ^BGUTMP(BPCSUB,1) K BPCRES S BPCSEQ=$G(^BGUTMP(BPCSUB,1)),BPCLSQP=$P(BPCSEQ,U,2),BPCLSQA=BPCSEQ
 I BPCX="" S BPCRES(0)=-1,BPCRES(1)="NO SEARCH PARAMETER GIVEN!" D KILL Q
 S BPCMAX=$G(BPCMAX) S:'BPCMAX BPCMAX=$S(BPCGUI:50,1:1E10)
 I 'BPCMORE,BPCPARAM'="" S BPCPVS="" F BPCN=1:1:$L(BPCPARAM,"|") S BPCPRM1=$P(BPCPARAM,"|",BPCN),BPCPV=$P(BPCPRM1,"="),BPCPVS=BPCPVS_$S(BPCN>1:",",1:"")_BPCPV,@BPCPV=$P(BPCPRM1,"=",2)
 D @$S(BPCMORE:"SETRES",BPCX?.N.1"."1N.N:"GETNUM",$D(^AICDKWLC(1,1,"B",BPCX)):"KWLC",$D(^ICD9("AIHS",BPCX)):"GETKWD",1:"GETTXT"),SETRES:'BPCMORE,KILL
 Q
 ;
GETNUM ; Handles numeric entries
 ;
 S BPCC=$O(^ICD9("BA",BPCX),-1),BPCNEXT=$O(^ICD9("BA",BPCC)),BPCFND=$E(BPCNEXT,1,BPCLEN)=BPCX
 I 'BPCFND F  S BPCNEXT=$O(^ICD9("BA",BPCNEXT)) Q:BPCNEXT=""  I $E(BPCNEXT,1,BPCLEN)=BPCX S BPCC=$O(^ICD9("BA",BPCNEXT),-1) S BPCFND=1 Q
 I BPCFND F  S BPCC=$O(^ICD9("BA",BPCC)) Q:BPCC=""!($E(BPCC,1,BPCLEN)'=BPCX)   S BPCI="" F  S BPCI=$O(^ICD9("BA",BPCC,BPCI)) Q:BPCI=""  D SETMATCH
 K BPCC,BPCFND,BPCNEXT
 Q
 ;
KWLC ; Look in Keyword Lookup Control file for synonyms
 ;
 S BPCSVX=BPCX,BPCN=0
 S BPCN="" F  S BPCN=$O(^AICDKWLC(1,1,"B",BPCSVX,BPCN)) Q:BPCN=""   S BPCN1=0 F  S BPCN1=$O(^AICDKWLC(1,1,BPCN,1,BPCN1)) Q:BPCN1=""  S BPCX=^(BPCN1,0) D @$S($D(^ICD9("AIHS",BPCX)):"GETKWD",1:"GETTXT")
 K BPCN,BPCN1,BPCSVX
 Q
 ;
GETKWD ; Handles keywords
 ;
 S BPCI="" F  S BPCI=$O(^ICD9("AIHS",BPCX,BPCI)) Q:BPCI=""  D SETMATCH
 Q
 ;
GETTXT ; Handles text entries
 ;
 S BPCC=$O(^ICD9("D",BPCX),-1) F  S BPCC=$O(^ICD9("D",BPCC)) Q:BPCC=""!($E(BPCC,1,BPCLEN)'=BPCX)  S BPCI="" F  S BPCI=$O(^ICD9("D",BPCC,BPCI)) Q:BPCI=""  D SETMATCH
 Q
 ;
SETMATCH ;
 ; Validate the ICD9 code : It doesn't start with an E, It's not
 ; inactive, and if Patient sex is set, and if sex is defined for this
 ; code, they're equal.
 S BPCDATA=$G(^ICD9(BPCI,0))
 Q:$E(BPCDATA)="E"  Q:$P(BPCDATA,U,9)'=""  I $G(BPCPSEX)'="",$P(BPCDATA,U,10)'="",BPCPSEX'=$P(BPCDATA,U,10) Q
 S BPCDESC=$G(^ICD9(BPCI,1)),BPCCAT=$P(BPCDATA,U,5),BPCCDE=$P(BPCDATA,U,1) S:BPCCAT'="" BPCCAT=$G(^ICM(BPCCAT,0))
 S:BPCCDE BPCCDE=+BPCCDE
 S:'$D(^BGUTMP(BPCSUB,1,BPCCDE)) BPCSEQ=BPCCDE,^BGUTMP(BPCSUB,1,BPCCDE)=BPCDESC_U_BPCI_U_BPCCAT_U_BPCDATA
 Q
 ;
SETRES ; Copy from ^BPCTMP to BPCRES
 ;
 I BPCSEQ="" S BPCRES(0)=-1,BPCRES(1)="vEnter another Selection, Code or Diagnosis!" Q
 S:'BPCMORE BPCSEQ=BPCCDE,$P(^BGUTMP(BPCSUB,1),U,1)=BPCSEQ,BPCLSQA=BPCSEQ
 S BPCSEQ=BPCLSQP F BPCCTR=1:1:BPCMAX S BPCSEQ=$O(^BGUTMP(BPCSUB,1,BPCSEQ)) Q:BPCSEQ=""  S BPCRES(BPCCTR)=^(BPCSEQ)
 S:BPCSEQ="" BPCCTR=BPCCTR-1 S BPCRES(0)=BPCCTR
 I BPCSEQ'="" S BPCCTR=BPCCTR+1,BPCRES(0)=BPCCTR,BPCRES(BPCCTR)="..MORE",$P(^BGUTMP(BPCSUB,1),U,2)=BPCSEQ Q
 K @BPCPVS,BPCPV,BPCPVS,^BGUTMP(BPCSUB,1)
 Q
 ;
KILL ;
 K BPCC,BPCCAT,BPCCDE,BPCCTR,BPCDATA,BPCDESC,BPCGUI,BPCI,BPCLEN,BPCLSQA,BPCLSQP,BPCMAX,BPCMORE,BPCN,BPCNEXT,BPCPARAM,BPCPRM1,BPCSEQ,BPCSUB,BPCX,BPCXS
 Q