BCQMAPI ; IHS/OIT/FBD - MAGIC MAPPER API ;05/07/18 07:49;FS
;;1.0;IHS CODE MAPPING;;MAY 07, 2018;Build 21
;
MM(BCQMF,LOOKUP,LKFORM,VALUE1,VALUE2,VALUE3,VALUE4,VALUE5,VALUE6,BCQMDATE,RETVAL) ;PEP; table oriented magic mapper
;this API will be called to obtained code values based
;on an entry in a that file that is passed
; input:
; 1 - File number in which the code lives
; NEW FILE INTRODUCTION: ICD OPERATION/PROCEDURE (80.1) for ICD10 Procedure codes.
; 2 - lookup value into the table in file
; the caller must pass a value that will not fail a DIC lookup into the table
; must be a unique lookup value
; EXAM - pass standard IHS code, e.g. 34
; ICD10 Procedures - pass standard IHS ICD10 code, e.g. 5A02210, F0636KZ, F003GZZ..
; NOTE: there is no unique lookup value in EDUCATION topics so caller must pass the IEN of the topic
; there are tons of dupes
; 3 - lookup value format, is this an I (internal value IEN) or E - External value DEFAULT IS "E"
; VALUE1 - VALUE6 - additional values to check (e.g exam result), these values
; will be used in the MUMPS code field as additional checks
; caller will have to be told what order to pass the values in for each table
; that will be in the technical documentation
; E.g. MEASUREMENT TYPE: VALUE1=RESULT, VALUE2=QUALIFIER;QUALIFIER;QUALIFIER, VALUE3=visit ien
; EXAM: VALUE1=RESULT, VALUE2=visit ien
; HEALTH FACTOR: == NO OTHER VALUES NEEDED
; EDUCATION: ==== NO OTHER VALUES NEEDED
; IMMUNIZATION: VALUE1=VISIT SERVICE CATEGORY
;
;SEE THE USER MANUAL FOR COMPLETE DESCRIPTION OF THIS API
;
K @RETVAL
;I BCQMF'?.N1.".".N S BCQMF=$O(^DIC("B",BCQMF,0))
I '$G(BCQMF) Q "-1^invalid file number" ;no valid file # passed
I '$D(^DD(BCQMF,0)) Q "-1^invalid file number"
I '$D(^DIC(BCQMF,0)) Q "-1^invalid file number"
S LOOKUP=$G(LOOKUP)
I $G(LOOKUP)="" Q "-1^no lookup valued passed"
S LKFORM=$G(LKFORM)
S BCQMDATE=$G(BCQMDATE)
I BCQMDATE="" S BCQMDATE=DT
S VALUE1=$G(VALUE1)
S VALUE2=$G(VALUE2)
S VALUE3=$G(VALUE3)
S VALUE4=$G(VALUE4)
S VALUE5=$G(VALUE5)
S VALUE6=$G(VALUE6)
;NEW BCQMFIEL,BCQMFV,BCQMX,BCQMY,BCQMMAP,BCQMC,BCQMZ,S,BCQMS,D,C,X,Y
S BCQMC=0
S BCQMX=$O(^BCQM(9002023,"B",BCQMF,0))
I 'BCQMX Q "-1^Table File not supported"
;do a DIC lookup of LOOKUP value into table BCQMF, then get the appropriate piece
S DIC=BCQMF,DIC(0)="M",X=$S(LKFORM="I":"`"_LOOKUP,1:LOOKUP) D ^DIC
I Y=-1 Q "-1^invalid lookup value"
S BCQMFV=+Y
S BCQMFIEL=$P(^BCQM(9002023,BCQMX,0),U,2)
I BCQMFIEL]"" S BCQMFV=$$GET1^DIQ(BCQMF,BCQMFV,BCQMFIEL)
I BCQMFV="" Q "-1^something went wrong"
I $D(^BCQM(9002023,BCQMX,2)) X ^BCQM(9002023,BCQMX,2) ;CODE PUT IN FOR EDUCATION TOPIC BUT MIGHT BE ABLE TO BE USED FOR OTHER TABLES
;Now go through all entries in 9002023 for this file and execute M logic for value checks
;I BCQMF=9999999.09 S BCQMZ=VALUE1 D PROCESS S BCQMZ=VALUE2 D PROCESS S BCQMZ="*ANY*" D PROCESS Q BCQMC
F BCQMZ=BCQMFV,"*ANY*" D PROCESS
Q BCQMC
PROCESS ;
S BCQMY=0 F S BCQMY=$O(^BCQM(9002023,BCQMX,1,"B",BCQMZ,BCQMY)) Q:BCQMY'=+BCQMY D
.S X=0 I $D(^BCQM(9002023,BCQMX,1,BCQMY,1)) X ^BCQM(9002023,BCQMX,1,BCQMY,1) I 'X Q ;doesn't match
.;looks like we got a match so set up codes in retval arry
.S BCQMS=0 F S BCQMS=$O(^BCQM(9002023,BCQMX,1,BCQMY,2,BCQMS)) Q:BCQMS'=+BCQMS D
..S D=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.03)
..I D]"",BCQMDATE'>D Q ;inactive
..S S=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.01)
..S C=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.02)
..I S]"",C]"" S BCQMC=BCQMC+1,@RETVAL@(BCQMC,S)=C
Q
MMMEAS ;test
S X=$$MM(9999999.07,"BP","E","120/80",,,,,,DT,"OUT")
W !,X,!
;ZW OUT
Q
MMEXAM ;test
S X=$$MM("EXAM","09",,"RF",,,,,,DT,"OUT")
W !,X,!
;ZW OUT
Q
MMEDUC ;test
KILL OUT
S X=$$MM(9999999.09,1109,"I",,,,,,,DT,"OUT")
W !,X,!
;ZW OUT
Q
MMICD10 ;test
KILL OUT
S X=$$MM(80.1,"F02Z5ZZ",,,,,,,,DT,"OUT")
W !,X,!
;ZW OUT
Q
;
PRIMPOV() ;PEP - return SNOMED to use for primary pov
Q $$GET1^DIQ(9002022,1,.02)
;
EMERPOV() ;PEP - return SNOMED to use for V EMERGENCY VISIT (In Future, for now eCQM module will map it locally)
Q ;$$GET1^DIQ(9002022,2,.02)
;
HANDED(V,D,RETVAL) ;PEP = get snomed handedness
K @RETVAL
NEW X,Y,BCQMC
I $G(V)="" Q ""
S BCQMC=0
S X=$O(^BCQM(9002022,1,1,"B",V,0))
I 'X Q ""
S Y=0 F S Y=$O(^BCQM(9002022,1,1,X,1,Y)) Q:Y'=+Y D
.S BCQMC=BCQMC+1,@RETVAL@(BCQMC,"SNOMED")=$P($G(^BCQM(9002022,1,1,X,1,Y,0)),U,1)
Q BCQMC
TESTIMM ;
S X=$$MM^BCQMAPI(9002084.81,16,"I",10,,,,,,DT,"CODES")
;input :
; 1 - file number of BI TABLE CONTRA REASON
; 2 - ien of entry in BI TABLE CONTRA REASON
; 3 - "I" - this tells the mapper you are passing internal ien vs external value
; 4 - ien of entry in the BI TABLE VACCINE GROUP
; 5-9 ARE BLANK
; 10 - date contraindication documented
; 11 - array you want the snomed codes to be passed back in
; output:
; E.G. CODES(1,"SNOMED")=315640000
; CODES(2,"SNOMED")=1111111
; you will only get back 1 or more snomed codes e.g. for flu anaphylaxsis you will get back 2
; we have the second parameter to tell what coding system as some mappings also pass back "LOINC" codes
; although so far, imm contraindications will not pass back loinc codes.
Q
BCQMAPI ; IHS/OIT/FBD - MAGIC MAPPER API ;05/07/18 07:49;FS
+1 ;;1.0;IHS CODE MAPPING;;MAY 07, 2018;Build 21
+2 ;
MM(BCQMF,LOOKUP,LKFORM,VALUE1,VALUE2,VALUE3,VALUE4,VALUE5,VALUE6,BCQMDATE,RETVAL) ;PEP; table oriented magic mapper
+1 ;this API will be called to obtained code values based
+2 ;on an entry in a that file that is passed
+3 ; input:
+4 ; 1 - File number in which the code lives
+5 ; NEW FILE INTRODUCTION: ICD OPERATION/PROCEDURE (80.1) for ICD10 Procedure codes.
+6 ; 2 - lookup value into the table in file
+7 ; the caller must pass a value that will not fail a DIC lookup into the table
+8 ; must be a unique lookup value
+9 ; EXAM - pass standard IHS code, e.g. 34
+10 ; ICD10 Procedures - pass standard IHS ICD10 code, e.g. 5A02210, F0636KZ, F003GZZ..
+11 ; NOTE: there is no unique lookup value in EDUCATION topics so caller must pass the IEN of the topic
+12 ; there are tons of dupes
+13 ; 3 - lookup value format, is this an I (internal value IEN) or E - External value DEFAULT IS "E"
+14 ; VALUE1 - VALUE6 - additional values to check (e.g exam result), these values
+15 ; will be used in the MUMPS code field as additional checks
+16 ; caller will have to be told what order to pass the values in for each table
+17 ; that will be in the technical documentation
+18 ; E.g. MEASUREMENT TYPE: VALUE1=RESULT, VALUE2=QUALIFIER;QUALIFIER;QUALIFIER, VALUE3=visit ien
+19 ; EXAM: VALUE1=RESULT, VALUE2=visit ien
+20 ; HEALTH FACTOR: == NO OTHER VALUES NEEDED
+21 ; EDUCATION: ==== NO OTHER VALUES NEEDED
+22 ; IMMUNIZATION: VALUE1=VISIT SERVICE CATEGORY
+23 ;
+24 ;SEE THE USER MANUAL FOR COMPLETE DESCRIPTION OF THIS API
+25 ;
+26 KILL @RETVAL
+27 ;I BCQMF'?.N1.".".N S BCQMF=$O(^DIC("B",BCQMF,0))
+28 ;no valid file # passed
IF '$GET(BCQMF)
QUIT "-1^invalid file number"
+29 IF '$DATA(^DD(BCQMF,0))
QUIT "-1^invalid file number"
+30 IF '$DATA(^DIC(BCQMF,0))
QUIT "-1^invalid file number"
+31 SET LOOKUP=$GET(LOOKUP)
+32 IF $GET(LOOKUP)=""
QUIT "-1^no lookup valued passed"
+33 SET LKFORM=$GET(LKFORM)
+34 SET BCQMDATE=$GET(BCQMDATE)
+35 IF BCQMDATE=""
SET BCQMDATE=DT
+36 SET VALUE1=$GET(VALUE1)
+37 SET VALUE2=$GET(VALUE2)
+38 SET VALUE3=$GET(VALUE3)
+39 SET VALUE4=$GET(VALUE4)
+40 SET VALUE5=$GET(VALUE5)
+41 SET VALUE6=$GET(VALUE6)
+42 ;NEW BCQMFIEL,BCQMFV,BCQMX,BCQMY,BCQMMAP,BCQMC,BCQMZ,S,BCQMS,D,C,X,Y
+43 SET BCQMC=0
+44 SET BCQMX=$ORDER(^BCQM(9002023,"B",BCQMF,0))
+45 IF 'BCQMX
QUIT "-1^Table File not supported"
+46 ;do a DIC lookup of LOOKUP value into table BCQMF, then get the appropriate piece
+47 SET DIC=BCQMF
SET DIC(0)="M"
SET X=$SELECT(LKFORM="I":"`"_LOOKUP,1:LOOKUP)
DO ^DIC
+48 IF Y=-1
QUIT "-1^invalid lookup value"
+49 SET BCQMFV=+Y
+50 SET BCQMFIEL=$PIECE(^BCQM(9002023,BCQMX,0),U,2)
+51 IF BCQMFIEL]""
SET BCQMFV=$$GET1^DIQ(BCQMF,BCQMFV,BCQMFIEL)
+52 IF BCQMFV=""
QUIT "-1^something went wrong"
+53 ;CODE PUT IN FOR EDUCATION TOPIC BUT MIGHT BE ABLE TO BE USED FOR OTHER TABLES
IF $DATA(^BCQM(9002023,BCQMX,2))
XECUTE ^BCQM(9002023,BCQMX,2)
+54 ;Now go through all entries in 9002023 for this file and execute M logic for value checks
+55 ;I BCQMF=9999999.09 S BCQMZ=VALUE1 D PROCESS S BCQMZ=VALUE2 D PROCESS S BCQMZ="*ANY*" D PROCESS Q BCQMC
+56 FOR BCQMZ=BCQMFV,"*ANY*"
DO PROCESS
+57 QUIT BCQMC
PROCESS ;
+1 SET BCQMY=0
FOR
SET BCQMY=$ORDER(^BCQM(9002023,BCQMX,1,"B",BCQMZ,BCQMY))
IF BCQMY'=+BCQMY
QUIT
Begin DoDot:1
+2 ;doesn't match
SET X=0
IF $DATA(^BCQM(9002023,BCQMX,1,BCQMY,1))
XECUTE ^BCQM(9002023,BCQMX,1,BCQMY,1)
IF 'X
QUIT
+3 ;looks like we got a match so set up codes in retval arry
+4 SET BCQMS=0
FOR
SET BCQMS=$ORDER(^BCQM(9002023,BCQMX,1,BCQMY,2,BCQMS))
IF BCQMS'=+BCQMS
QUIT
Begin DoDot:2
+5 SET D=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.03)
+6 ;inactive
IF D]""
IF BCQMDATE'>D
QUIT
+7 SET S=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.01)
+8 SET C=$$GET1^DIQ(9002023.12,BCQMS_","_BCQMY_","_BCQMX,.02)
+9 IF S]""
IF C]""
SET BCQMC=BCQMC+1
SET @RETVAL@(BCQMC,S)=C
End DoDot:2
End DoDot:1
+10 QUIT
MMMEAS ;test
+1 SET X=$$MM(9999999.07,"BP","E","120/80",,,,,,DT,"OUT")
+2 WRITE !,X,!
+3 ;ZW OUT
+4 QUIT
MMEXAM ;test
+1 SET X=$$MM("EXAM","09",,"RF",,,,,,DT,"OUT")
+2 WRITE !,X,!
+3 ;ZW OUT
+4 QUIT
MMEDUC ;test
+1 KILL OUT
+2 SET X=$$MM(9999999.09,1109,"I",,,,,,,DT,"OUT")
+3 WRITE !,X,!
+4 ;ZW OUT
+5 QUIT
MMICD10 ;test
+1 KILL OUT
+2 SET X=$$MM(80.1,"F02Z5ZZ",,,,,,,,DT,"OUT")
+3 WRITE !,X,!
+4 ;ZW OUT
+5 QUIT
+6 ;
PRIMPOV() ;PEP - return SNOMED to use for primary pov
+1 QUIT $$GET1^DIQ(9002022,1,.02)
+2 ;
EMERPOV() ;PEP - return SNOMED to use for V EMERGENCY VISIT (In Future, for now eCQM module will map it locally)
+1 ;$$GET1^DIQ(9002022,2,.02)
QUIT
+2 ;
HANDED(V,D,RETVAL) ;PEP = get snomed handedness
+1 KILL @RETVAL
+2 NEW X,Y,BCQMC
+3 IF $GET(V)=""
QUIT ""
+4 SET BCQMC=0
+5 SET X=$ORDER(^BCQM(9002022,1,1,"B",V,0))
+6 IF 'X
QUIT ""
+7 SET Y=0
FOR
SET Y=$ORDER(^BCQM(9002022,1,1,X,1,Y))
IF Y'=+Y
QUIT
Begin DoDot:1
+8 SET BCQMC=BCQMC+1
SET @RETVAL@(BCQMC,"SNOMED")=$PIECE($GET(^BCQM(9002022,1,1,X,1,Y,0)),U,1)
End DoDot:1
+9 QUIT BCQMC
TESTIMM ;
+1 SET X=$$MM^BCQMAPI(9002084.81,16,"I",10,,,,,,DT,"CODES")
+2 ;input :
+3 ; 1 - file number of BI TABLE CONTRA REASON
+4 ; 2 - ien of entry in BI TABLE CONTRA REASON
+5 ; 3 - "I" - this tells the mapper you are passing internal ien vs external value
+6 ; 4 - ien of entry in the BI TABLE VACCINE GROUP
+7 ; 5-9 ARE BLANK
+8 ; 10 - date contraindication documented
+9 ; 11 - array you want the snomed codes to be passed back in
+10 ; output:
+11 ; E.G. CODES(1,"SNOMED")=315640000
+12 ; CODES(2,"SNOMED")=1111111
+13 ; you will only get back 1 or more snomed codes e.g. for flu anaphylaxsis you will get back 2
+14 ; we have the second parameter to tell what coding system as some mappings also pass back "LOINC" codes
+15 ; although so far, imm contraindications will not pass back loinc codes.
+16 QUIT