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

BMXADOFS.m

Go to the documentation of this file.
BMXADOFS ; IHS/CIHA/GIS - RPC CALL FOR EXTENDED FUNCTIONALITY OF BMXNet UTILITIES ; 31 Jul 2009  12:42 PM
 ;;4.0;BMX;**4**;JUN 28, 2010;Build 4
 ; THIS IS THE ADO RECORDSET FILER: ADO -> FILEMAN
 ; CONTAINS SPECIAL CODE RELATED TO FILING PROPLEMS, POVS, FAMILY HX, PERSONAL HX AND NOTES 
 ;
 ; 
TPOV ; ADD POV TEST
 S DATA=".01|`8718"_$C(30)_".02|`53"_$C(30)_".03|`3909"_$C(30)_".04|DM---I"_$C(30)_".12|P"_$C(30,31)
 D FILE^BMXADOF(.XXX,9000010.07,"",DATA) W !,XXX K XXX,DATA Q
 ;
TH ; HX TEST
 S DATA=".01|250.00"_$C(30)_".02|`53"_$C(30)_".03|JUL 15,2004"_$C(30)_".04|FAMILY HX OF LUNG CA"_$C(30,31)
 D FILE^BMXADOF(.XXX,9000014,"",DATA) W !,XXX K XXX,DATA Q
 ;
TNOTE ; TEST ADDING A NOTE TO A PROBLEM
 N DATA,XXX,PROBIEN,FACNIEN,FACIEN,DAS
 S PROBIEN=3,FACIEN=4587
 S FACNIEN=$$FACNIEN(PROBIEN,FACIEN) ; YOU MUST SPECIFY THE PROBLEM IEN AND THE FACILITY IEN
 S DAS=PROBIEN_","_FACNIEN_","
 S DATA=".03|NEW NOTE #2"_$C(30,31) ; THE DATA STRING JUST CONTAINS THE NOTE FIELD.
 ; THE OTHER FIELDS (INCLUDING .01) ARE ADDED BY BMXADOF
 D FILE^BMXADOF(.XXX,9000011.1111,DAS,DATA) W !,XXX
 Q
 ;
 ; -----------------------------------------------------------------------------------------------------
 ; 
SPEC(FILE,DATA,UFLG) ;EP - SPECIAL DATA MODS FOR SPECIFIC FILES
 I FILE=9000010.07 S DATA=$$POV(DATA) Q DATA
 I FILE=9000011 S DATA=$$PROB(DATA,$G(UFLG)) Q DATA
 I FILE=9000013!(FILE=9000014) S DATA=$$HX(DATA) Q DATA
 I FILE=9000011.1111 S DATA=$$NOTE(DATA,$G(DAS(2)),$G(DAS(1))) Q DATA
 ; I FILE=9000010.18,DATA'["|.04|" G DSTG
 Q DATA
 ;
HX(DATA) ; INPUT STRING TRANSFORM FOR PHX AND FHX
 N NARR,NIEN,%,A,B,X,Y,%DT
 I DATA[".01|`" G HNARR
 S DATA=$$ICD(DATA,.01) I DATA="" Q ""
HNARR I DATA'[".04|'" G HDT
 S DATA=$$NARR(DATA,.04)
HDT I DATA'[".03|" Q DATA
 S X=+$P(DATA,".03|",2) I X?7N Q DATA
 S %DT="" D ^%DT
 I Y'?7N Q DATA
 S A=$P(DATA,".03|")
 S B=$P(DATA,".03|",2) S B=$P(B,$C(30),2)
 S DATA=A_".03|"_Y
 I $L(B) S DATA=DATA_$C(30)_B
 Q DATA
 ; 
POV(DATA) ; POV INPUT STRING TRANSFORM
 N NARR,NIEN,%,CIEN
 S CIEN=$P($P(DATA,$C(30)),".01|",2)
 I CIEN?1N.N G PVNARR
 S DATA=$$ICD(DATA,.01) I DATA="" Q ""
PVNARR I DATA'[".04|'" Q DATA
 S DATA=$$NARR(DATA,.04)
 Q DATA
 ; 
PROB(DATA,UFLG) ; PROBLEM LIST INPUT STRING TRANSFORM
 N NARR,NIEN,%,PNUM,FACIEN,DFN,X,A,B
PNARR I DATA'[".05|" G PICD
 S %=$P(DATA,".05|",2)
 S NARR=$P(%,$C(30))
 I NARR'?1"`"1.N S DATA=$$NARR(DATA,.05) ; STUFF THE NARR LOOKUP VALUE IN THE DATA STRING
 I '$L(DATA) Q ""
PICD S %=$P(DATA,"|") I %'=.01,DATA'[($C(30)_".01|") G PNUM
 S DATA=$$ICD(DATA,.01) I DATA="" Q ""
PNUM I $G(UFLG)="E" Q DATA ; STOP HERE IF IN EDIT MODE
 I $P(DATA,($C(30)_".07|"),2) G TODAY ; GET NEXT PROB NUM
 S DFN=+$P(DATA,".02|`",2)
 I 'DFN S DATA="" Q ""
 S FACIEN=+$P(DATA,".06|`",2)
 I 'FACIEN Q ""
 S PNUM=$$NEXTPBN(DFN,FACIEN)
 I 'PNUM Q ""
 S X=$L(DATA,$C(30))
 S A=$P(DATA,$C(30),1,X-1),B=$P(DATA,$C(30),X)
 S DATA=A_$C(30)_".07|"_PNUM_$C(30)_B
TODAY I $P(DATA,($C(30)_".08|"),2) Q DATA ; GET TODAY'S DATE
 S X=$L(DATA,$C(30))
 S A=$P(DATA,$C(30),1,X-1),B=$P(DATA,$C(30),X)
 S DATA=A_$C(30)_".08|"_$G(DT)_$C(30)_B
 Q DATA
 ;
NOTE(DATA,PIEN,FNIEN) ; GIVEN A DATA STRING CONTAINING THE NOTE, THE PROBLEM IEN, AND THE FAC-NOTE IEN:
 ; ADD NOTE # AND STATUS TO THE DATA STRING
 I $G(DATA)'[".03|" Q ""
 I '$D(^AUPNPROB(+$G(PIEN),11,+$G(FNIEN),0)) Q ""
 N NUM
 I DATA'[".04|" S DATA=".04|A"_$C(30)_DATA
 I DATA'[".01|" D
 . S NUM=$$NEXTNOTE(PIEN,FNIEN)
 . I 'NUM Q
 . S DATA=".01|"_NUM_$C(30)_DATA
 Q DATA
 ;
 ;Test ICD lookup
TSTICD N XXICD,PIECE,PARM,DIR,DIRUT,DUOUT,DTOUT,DIROUT,X,Y,IEN
 S DIR("A",1)="",DIR("A")="Enter the ICD Code: "
 S DIR(0)="FA^1:98"
 D ^DIR I +Y<1,+$E(Y,2,99)<1 Q
 S XXICD=Y
 ;
 S DIR("A",1)="",DIR("A")="Enter the piece to check (1 or 2): "
 S DIR(0)="FA^1:98"
 D ^DIR I Y'=1,Y'=2 Q
 S PIECE=Y
 ;
 I PIECE=1 S PARM=".01|"_XXICD_$C(30)_".02|"_$C(30)_".03|ABC"
 I PIECE=2 S PARM=".01|"_$C(30)_".02|"_XXICD_$C(30)_".03|ABC"
 S X=$$ICD(PARM,$S(PIECE="1":".01",1:".02"))
 W !,$TR(X,$C(30),"{")
 I PIECE=1 S IEN=$P(X,"|",2)
 I PIECE=2 S IEN=$P(X,"|",3)
 S IEN=$P($TR($TR(IEN,"`"),"{"),$C(30))
 I IEN>0 W !,$$GET1^DIQ(80,IEN_",",.01,"E")
 Q
 ;
TI N XXX S XXX=$$ICD(".01|250.00"_$C(30)_".02|123"_$C(30)_".03|ABC",.01) W !,$TR(XXX,$C(30),"{") Q
ICD(DATA,FLD) ; VERIFY ICD CODE AND GET LOOKUP VALUE
 I '$G(FLD) Q ""
 I '$L($G(DATA)) Q ""
 N %,A,B
 S %=$P(DATA,"|")
 ;
 ;Process Piece .01
 I %=FLD D  Q DATA
 . NEW IEN,OVAL,CODE
 . S IEN=""
 . S CODE=$P(DATA,"|",2)
 . S (CODE,OVAL)=$P(CODE,$C(30))
 . I CODE?1"`"1.N Q
 . ;
 . ;Pull appropriate ICD-9/ICD-10 code
 . ;
 . ;ICD-9 Only (Pre-AICD build)
 . I $$VERSION^XPDUTL("AICD")<4.0 D
 .. S IEN=$O(^ICD9("BA",CODE_" ",0))
 .. I $L($T(CODEN^ICDCODE)) S IEN=+$$CODEN^ICDCODE(IEN,80) I IEN<0 S IEN=""
 . ;
 . ;ICD-9 or ICD-10
 . I $$VERSION^XPDUTL("AICD")>3.51 D
 .. NEW STR
 .. ;
 .. ;Date has passed - First look for ICD-10
 .. I $$IMP^ICDEXA(30)'>DT D  Q:IEN]""
 ... S STR=$$ICDDATA^ICDXCODE(30,CODE,DT,"E")
 ... S IEN=$P(STR,"^") S:IEN<0 IEN=""
 .. ;
 .. ;If not found - Look in ICD-9 - Might be lookup of historical info
 .. I IEN="" D
 ... S STR=$$ICDDATA^ICDXCODE(1,CODE,DT,"E")
 ... S IEN=$P(STR,"^") S:IEN<0 IEN=""
 . S %=IEN
 . ; 
 . I OVAL=% S DATA="" Q
 . I '% S DATA="" Q
 . S A=$P(DATA,"|")
 . S B=$P(DATA,"|",2,999)
 . S B=$P(B,$C(30),2,999)
 . S DATA=A_"|`"_%
 . I $L(B) S DATA=DATA_$C(30)_B
 . Q
 ;
 ;Process piece .02
 S %=$P(DATA,($C(30)_FLD_"|"),2) D
 . NEW OVAL,CODE,IEN
 . S IEN=""
 . S (CODE,OVAL)=$P(%,$C(30))
 . I CODE?1"`"1.N Q
 . ;
 . ;Pull appropriate ICD-9/ICD-10 code
 . ;
 . ;ICD-9 Only (Pre-AICD build)
 . I $$VERSION^XPDUTL("AICD")<4.0 D
 .. S IEN=$O(^ICD9("BA",CODE_" ",0))
 .. I $L($T(CODEN^ICDCODE)) S IEN=+$$CODEN^ICDCODE(IEN,80) I IEN<0 S IEN=""
 . ;
 . ;ICD-9 or ICD-10
 . I $$VERSION^XPDUTL("AICD")>3.51 D
 .. NEW STR
 .. ;
 .. ;Date has passed - First look for ICD-10
 .. I $$IMP^ICDEXA(30)'>DT D  Q:IEN]""
 ... S STR=$$ICDDATA^ICDXCODE(30,CODE,DT,"E")
 ... S IEN=$P(STR,"^") S:IEN<0 IEN=""
 .. ;
 .. ;If not found - Look in ICD-9 - Might be lookup of historical info
 .. I IEN="" D
 ... S STR=$$ICDDATA^ICDXCODE(1,CODE,DT,"E")
 ... S IEN=$P(STR,"^") S:IEN<0 IEN=""
 . S %=IEN
 . ;
 . I OVAL=% S DATA="" Q
 . I '% S DATA="" Q
 . S A=$P(DATA,($C(30)_FLD_"|"))
 . S B=$P(DATA,($C(30)_FLD_"|"),2,999)
 . S B=$P(B,$C(30),2,999)
 . S DATA=A_$C(30)_FLD_"|`"_%
 . I $L(B) S DATA=DATA_$C(30)_B
 . Q
 Q DATA
 ; 
NARR(DATA,FLD) ; SUBSTITUTE A LOOKUP VALUE FOR NARRATIVE DATA IN THE DATA STRING
 N A,B,C,X,Y,DIC,Z
 I '$G(FLD) Q ""
 I '$L($G(DATA)) Q ""
 S Z=FLD_"|"
 S A=$P(DATA,Z)
 S B=$P(DATA,Z,2)
 S NARR=$P(B,$C(30))
 S NARR=$$UP^XLFSTR(NARR) ; CONVERT ALL NARRATIVE TO UPPERCASE
 S C=$P(B,$C(30),2,999)
 S DIC="^AUTNPOV(",DIC(0)="L",X=NARR
 D ^DIC I Y=-1 Q ""
 S DATA=A_FLD_"|`"_+Y
 I $L(C) S DATA=DATA_$C(30)_C
 D ^XBFMK
 Q DATA
 ;
FACNIEN(PIEN,FIEN) ; GIVEN A PROBLEM IEN AND FACILITY IEN, RETURN THE FACILITY-NOTE IEN
 I '$D(^AUPNPROB(+$G(PIEN),0)) Q ""
 I '$D(^DIC(4,+$G(FIEN),0)) Q ""
 N FNIEN
 S FNIEN=$O(^AUPNPROB(PIEN,11,"B",FIEN,0)) I FNIEN Q FNIEN ; IF AN FNIEN EXISTS RETURN IT
 ; OTHERWISE-CREATE THE FM STUB NODES FOR THE FACILITY SUBFILE
 S FNIEN=$O(^AUPNPROB(PIEN,11,999999),-1)+1
 S ^AUPNPROB(PIEN,11,FNIEN,0)=FIEN
 S ^AUPNPROB(PIEN,11,FNIEN,11,0)="^9000011.1111IA^^"
 S ^AUPNPROB(PIEN,11,"B",FIEN,FNIEN)=""
 Q FNIEN
 ;
NEXTPBN(DFN,FIEN) ; RETURN THE NEXT AVAILABLE PROBLEM NUMBER FOR A PATIENT AT THE FACILITY
 N MAX,PIEN,X,Y
 S MAX=0,PIEN=0
 F  S PIEN=$O(^AUPNPROB("AC",DFN,PIEN)) Q:'PIEN  D  ; FIND ALL PROBLEMS FOR THIS PATIENT
 . S X=$G(^AUPNPROB(PIEN,0)) I '$L(X) Q
 . I $P(X,U,6)'=FIEN Q  ; ONLY CHECK NUMBERS AT THIS FACILITY
 . S Y=$P(X,U,7)
 . I Y>MAX S MAX=Y ; GET THE HIGHEST NUMBER THUS FAR
 . Q
 S MAX=(MAX\1)+1 ; GET NEXT AVAILABLE INTEGER
 Q MAX
 ;
NN W $$NEXTNOTE(3,1) Q
NEXTNOTE(PIEN,FNIEN) ; RETRUN THE NEXT NOTE NUMBER FOR A PROBLEM AND FACILITY-NOTE IEN
 I '$D(^AUPNPROB(+$G(PIEN),11,+$G(FNIEN),0)) Q ""
 N MAX,NIEN,X,Y
 S MAX=0,NIEN=0
 F  S NIEN=$O(^AUPNPROB(PIEN,11,FNIEN,11,NIEN)) Q:'NIEN  D
 . S X=$G(^AUPNPROB(PIEN,11,FNIEN,11,NIEN,0)) I '$L(X) Q
 . S Y=+X
 . I Y>MAX S MAX=Y
 . Q
 S MAX=MAX+1
 Q MAX
 ;
PIENN(PIEN) ; GIVEN A PROBLEM IEN, RETURN PROBLEM NARRATIVE (ICD)
 N X,IIEN,NARR,ICD,ENTRYDT
 S X=$G(^AUPNPROB(PIEN,0)) I '$L(X) Q ""
 S IIEN=$P(X,U) I 'IIEN Q ""
 S ENTRYDT=$P(X,U,8)
 S ICD=""
 ;
 ;Pull appropriate ICD-9/ICD-10 code
 ;
 D
 . NEW STR
 . ;
 . ;First try to locate ICD-10
 . S STR=$$ICDDATA^ICDXCODE(30,IIEN,ENTRYDT,"I")
 . S ICD=$S($P(STR,"^")<0:"",1:$P(STR,"^",2)) Q:ICD]""
 . ;
 . ;If not an ICD-10 code try ICD-9 (could be before date or a historical entry)
 . S STR=$$ICDDATA^ICDXCODE(1,IIEN,ENTRYDT,"I")
 . S ICD=$S($P(STR,"^")<0:"",1:$P(STR,"^",2))
 ;  
 I '$L(ICD) Q ""
 S NARR=$$GET1^DIQ(9000011,PIEN,".05") I '$L(NARR) Q ""
 S:$E(NARR,1)="*" NARR=$E(NARR,2,9999)
 S X=NARR_" ("_ICD_")"
 Q X
 ;
DESC(CODE) ;EP - Return the description for the specified code
 ;
 N DESC
 S DESC=""
 ;
 ;Pull appropriate ICD-9/ICD-10 code
 ;
 ;ICD-9
 I $$VERSION^XPDUTL("AICD")<4.0 D
 . S CODE=$O(^ICD9("BA",CODE_" ",0))
 . S DESC=$$GET1^DIQ(80,CODE_",",3,"E")
 ;
 ;ICD-9 or ICD-10
 I $$VERSION^XPDUTL("AICD")>3.51 D
 . NEW STR
 . ;
 . ;First try to locate ICD-10
 . I $$IMP^ICDEXA(30)'>DT D  Q:DESC]""
 .. S STR=$$ICDDATA^ICDXCODE(30,CODE,DT,"E")
 .. S DESC=$P(STR,"^",4)
 . ;
 . ;If not an ICD-10 code try ICD-9 (could be before date or a historical entry)
 . I DESC="" D
 .. S STR=$$ICDDATA^ICDXCODE(1,CODE,DT,"E")
 .. S DESC=$P(STR,"^",4)
 ;
 Q DESC