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

BSTSAPIF.m

Go to the documentation of this file.
  1. BSTSAPIF ;GDIT/HS/BEE-Standard Terminology API Function Calls ; 5 Nov 2012 9:53 AM
  1. ;;2.0;IHS STANDARD TERMINOLOGY;**1**;Dec 01, 2016;Build 36
  1. ;
  1. Q
  1. ;
  1. VSBTRMF(IN) ;PEP - Returns whether a given term is in a particular subset
  1. ;
  1. ;Input
  1. ; OUT - Output variable/global to return information in (VAR)
  1. ; IN - P1 - Description Id of term to check
  1. ; - P2 - The subset to look in
  1. ; - P3 (Optional) - The code set Id (default SNOMED US EXT '36')
  1. ; - P4 (Optional) - LOCAL - Pass 1 to perform local listing, otherwise leave
  1. ; blank for remote listing
  1. ; - P5 (Optional) - DEBUG - Pass 1 to display debug information
  1. ;
  1. ;Output
  1. ;
  1. ; VAR = 1:Term is in the provided subset
  1. ; 0:Term is not in the provided subset
  1. ;
  1. NEW FOUT,STS,%D
  1. ;
  1. S STS=$$VALSBTRM^BSTSAPIB("FOUT",IN)
  1. Q FOUT
  1. ;
  1. ICD2SMD(OUT,IN) ;EP - Returns a list of SMOMED codes for the specified ICD9 code
  1. ;
  1. ;Input
  1. ; OUT - OUTPUT array of SNOMED concepts to return
  1. ; IN - The ICD9 Code to search on
  1. ;
  1. I $G(IN)="" Q
  1. ;
  1. NEW NMID,CIEN,RCNT,%D
  1. ;
  1. ;Get IEN for SNOMED
  1. S NMID=$O(^BSTS(9002318.1,"B",36,"")) Q:NMID=""
  1. ;
  1. ;Loop through entries and find matches
  1. S RCNT=0,CIEN="" F S CIEN=$O(^BSTS(9002318.4,"I",NMID,IN,CIEN)) Q:CIEN="" D
  1. . ;
  1. . NEW DTSID,CONC
  1. . ;
  1. . S DTSID=$$GET1^DIQ(9002318.4,CIEN_",",.08,"I") Q:DTSID=""
  1. . ;
  1. . S CONC=$$GET1^DIQ(9002318.4,CIEN_",",.02,"I") Q:CONC=""
  1. . ;
  1. . ;Set up return entry
  1. . S RCNT=RCNT+1 S @OUT@(RCNT)=CONC_U_DTSID
  1. Q 1
  1. ;
  1. DILKP(OUT,IN) ;EP - Performs a drug ingredient lookup on a specified value
  1. ;
  1. ;Input
  1. ; IN - P1 - The exact term to lookup
  1. ; - P2 - Lookup Type (N-NDC,V-VUID)
  1. ; - P3 (Optional) - LOCAL - Pass 1 or blank to perform local listing
  1. ; Pass 2 for a remote DTS listing
  1. ; - P4 (Optional) - DEBUG - Pass 1 to display debug information
  1. ; - P5 (System Use Only) - TBYPASS - Pass 1 to bypass server timeout checks, otherwise
  1. ; leave blank. Do not use for regular calls
  1. ;
  1. ;Output
  1. ; Function returns - [1]^[2]^[3]
  1. ; [1] - 2:Remote information returned
  1. ; 1:Local information returned
  1. ; 0:No Information Returned
  1. ; [2] - Primary Remote Error Message
  1. ; [3] - Secondary Remote Error Message (if applicable)
  1. ;
  1. ; VAR(#) record is returned for any exact match
  1. ;
  1. ; VAR(1,"RXN","CON")=RxNorm Code
  1. ; VAR(1,"RXN","TRM")=RxNorm Term
  1. ; VAR(1,"RXN","TDC")=RxNorm Tradename code
  1. ; VAR(1,"RXN","TDT")=RxNorm Tradename term
  1. ; VAR(1,"RXN","TTY")=First TTY value for the RxNorm
  1. ;
  1. NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BSTSAPIF D UNWIND^%ZTER" ; SAC 2009 2.2.3.17
  1. ;
  1. N SEARCH,NMID,SNAPDT,MAX,LOCAL,NMIEN,RLIST,I,LTYPE,RXSTR,UNSTR,%D
  1. N RESULT,DEBUG,BSTSR,BSTSI,BSTSWS,RES,BSTSD,X,%,%H,UPSRCH,CONC,CONCDT,TBYPASS
  1. K @OUT
  1. ;
  1. I $G(DT)="" D DT^DICRW
  1. S IN=$G(IN,"")
  1. S SEARCH=$P(IN,U) I $TR(SEARCH," ")="" Q "0^Invalid Search String"
  1. S LTYPE=$P(IN,U,2) I LTYPE'="N",LTYPE'="V" Q "0^Invalid Lookup Type"
  1. S SNAPDT=DT_".2400"
  1. S SNAPDT=$$FMDT2XML^BSTSUTIL(SNAPDT)
  1. S LOCAL=$P(IN,U,3),LOCAL=$S(LOCAL=2:"",1:"1")
  1. S DEBUG=$P(IN,U,4),DEBUG=$S(DEBUG=1:"1",1:"")
  1. S TBYPASS=$P(IN,U,5),TBYPASS=$S(TBYPASS=1:"1",1:"")
  1. ;
  1. S BSTSWS("SEARCH")=SEARCH
  1. S BSTSWS("SNAPDT")=SNAPDT
  1. S BSTSWS("MAXRECS")=100
  1. S BSTSWS("TBYPASS")=TBYPASS
  1. ;
  1. S BSTSWS("NAMESPACEID")=1552
  1. I LTYPE="N" S BSTSWS("PROPERTY")=110,BSTSWS("LTYPE")="N"
  1. E S BSTSWS("PROPERTY")=209,BSTSWS("LTYPE")="V"
  1. S NMID=1552
  1. ;
  1. ;Perform RxNorm DTS Lookup
  1. ;
  1. ;Make DTS Lookup call
  1. S BSTSR=1,BSTSD=""
  1. I LOCAL'=1 S BSTSR=$$DILKP^BSTSWSV1("RESULT",.BSTSWS,DEBUG) S:+BSTSR $P(BSTSR,U)=2
  1. ;
  1. ;If no results, try performing local search
  1. I $D(RESULT)<10 S BSTSD=$$VNLKP^BSTSLKP("RESULT",.BSTSWS)
  1. ;
  1. ;If local search and no record try DTS Lookup
  1. I $D(RESULT)<10,LOCAL S BSTSR=$$DILKP^BSTSWSV1("RESULT",.BSTSWS,DEBUG) S:+BSTSR $P(BSTSR,U)=2,BSTSD=""
  1. ;
  1. ;Define output for no results
  1. S:$D(RESULT)<10 BSTSD=0
  1. ;
  1. ;Get the concept information
  1. S CONC=$P($G(RESULT(1)),U)
  1. S RXSTR=""
  1. ;
  1. S:CONC]"" RXSTR=$$CNCLKP^BSTSAPI("CONCDT",CONC_"^"_BSTSWS("NAMESPACEID")_"^^1")
  1. S @OUT@(1,"RXN","CON")=CONC
  1. S @OUT@(1,"RXN","TRM")=$G(CONCDT(1,"FSN","TRM")) ;$P(RXSTR,U,2)
  1. S @OUT@(1,"RXN","TDC")=$G(CONCDT(1,"IAR",1,"CON"))
  1. S @OUT@(1,"RXN","TDT")=$G(CONCDT(1,"IAR",1,"TRM"))
  1. S @OUT@(1,"RXN","TTY")=$G(CONCDT(1,"TTY",1,"TTY"))
  1. ;
  1. S $P(BSTSR,U)=$S(BSTSD=0:0,(+BSTSR)>0:+BSTSR,1:1)
  1. Q BSTSR
  1. ;
  1. ASSOC(IN) ;EP - Returns the associations for each type (SMD, RxNorm, UNII)
  1. ;
  1. ;Input
  1. ; IN - P1 - The exact term to lookup
  1. ; - P2 (Optional) - The code set Id or Name (default SNOMED US EXT '36')
  1. ; ID NAME
  1. ; 32770 ECLIPS
  1. ; 5180 FDA UNII
  1. ; 32773 GMRA Allergies with Maps
  1. ; 32772 GMRA Signs Symptoms
  1. ; 32771 IHS VANDF
  1. ; 32774 IHS Med Route
  1. ; 1552 RxNorm R
  1. ; 36 SNOMED CT US Extension
  1. ; - P3 (Optional) - Snapshot Date to check (default DT)
  1. ; - P4 (Optional) - LOCAL - Pass 1 or blank to perform local listing
  1. ; Pass 2 for remote DTS listing
  1. ; - P5 (Optional) - DEBUG - Pass 1 to display debug information
  1. ;
  1. ;Output
  1. ;Function returns - [1]^[2]^[3]
  1. ; Where:
  1. ; [1] - SNOMED Association(s) - ";" Delimited
  1. ; [2] - RxNorm Association(s) - ";" Delimited
  1. ; [3] - UNII Association(s) - ";" Delimited
  1. ;
  1. NEW RES,BSTSVAR,%D
  1. ;
  1. S RES=$$VALTERM^BSTSAPI("BSTSVAR",$G(IN))
  1. I +RES D Q RES
  1. . ;
  1. . NEW CNT,SMD,RXN,UNI,CON
  1. . ;
  1. . ;SNOMED
  1. . S (SMD,CNT)="" F S CNT=$O(BSTSVAR(1,"ASM",CNT)) Q:CNT="" D
  1. .. S CON=$G(BSTSVAR(1,"ASM",CNT,"CON")) Q:CON=""
  1. .. S SMD=SMD_$S(SMD]"":";",1:"")_CON
  1. . ;
  1. . ;RxNorm
  1. . S (RXN,CNT)="" F S CNT=$O(BSTSVAR(1,"ARX",CNT)) Q:CNT="" D
  1. .. S CON=$G(BSTSVAR(1,"ARX",CNT,"CON")) Q:CON=""
  1. .. S RXN=RXN_$S(RXN]"":";",1:"")_CON
  1. . ;
  1. . ;UNII
  1. . S (UNI,CNT)="" F S CNT=$O(BSTSVAR(1,"AUN",CNT)) Q:CNT="" D
  1. .. S CON=$G(BSTSVAR(1,"AUN",CNT,"CON")) Q:CON=""
  1. .. S UNI=UNI_$S(UNI]"":";",1:"")_CON
  1. .;
  1. . S RES=SMD_U_RXN_U_UNI
  1. ;
  1. Q ""
  1. ;
  1. DI2RX(IN) ;EP - Performs a drug ingredient lookup on a specified value
  1. ; Returns only the first RxNorm mapping as a function call output
  1. ;
  1. ;Input
  1. ; IN - P1 - The exact term to lookup
  1. ; - P2 - Lookup Type (N-NDC,V-VUID)
  1. ; - P3 (Optional) - LOCAL - Pass 1 or blank to perform local listing,
  1. ; Pass 2 for remote DTS listing
  1. ; - P4 (Optional) - DEBUG - Pass 1 to display debug information
  1. ;
  1. ;Output
  1. ; Function returns - [1]^[2]
  1. ; [1] - The RxNorm Code of the first RxNorm mapping (if more than one)
  1. ; [2] - The RxNorm Term of the first RxNorm mapping
  1. ; [3] - The RxNorm Tradename code
  1. ; [4] - The RxNorm Tradename term
  1. ; [5] - The first TTY value for the RxNorm
  1. ;
  1. ;
  1. NEW DOUT,STS,RES,%D
  1. ;
  1. S STS=$$DILKP^BSTSAPI("DOUT",IN)
  1. I 'STS Q ""
  1. S $P(RES,U)=$G(DOUT(1,"RXN","CON"))
  1. S $P(RES,U,2)=$G(DOUT(1,"RXN","TRM"))
  1. S $P(RES,U,3)=$G(DOUT(1,"RXN","TDC"))
  1. S $P(RES,U,4)=$G(DOUT(1,"RXN","TDT"))
  1. S $P(RES,U,5)=$G(DOUT(1,"RXN","TTY"))
  1. Q RES
  1. ;
  1. USEARCH(OUT,IN) ;EP - Perform Codeset Universe Search
  1. ;
  1. ;Input
  1. ; OUT - Output variable/global to return information in (VAR)
  1. ; IN - P1 - Search string
  1. ; - P2 - Search Type - (F-Fully specified name, S-Synonyms)
  1. ; - P3 (Optional) - Namespace ID - Default to SNOMED US EXT (#36)
  1. ; ID NAME
  1. ; 5180 FDA UNII
  1. ; 32773 GMRA Allergies with Maps
  1. ; 32772 GMRA Signs Symptoms
  1. ; 32771 IHS VANDF
  1. ; 1552 RxNorm R
  1. ; 36 SNOMED CT US Extension
  1. ;
  1. ; - P4 (Optional) - Maximum number of concepts/terms to return (default 25)
  1. ; - P5 (Optional) - DEBUG - Pass 1 to display debug information
  1. ;
  1. ;Output
  1. ; Function returns - [1]^[2]^[3]
  1. ; [1] - 2:Remote information returned
  1. ; 1:Local information returned
  1. ; 0:No Information Returned
  1. ; [2] - Primary Remote Error Message
  1. ; [3] - Secondary Remote Error Message (if applicable)
  1. ;
  1. ; VAR(#) - List of Records
  1. ;
  1. NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BSTSAPIF D UNWIND^%ZTER" ; SAC 2009 2.2.3.17
  1. ;
  1. N SEARCH,STYPE,NMID,SUB,SNAPDT,MAX,BCTCHRC,BCTCHCT,LOCAL,SLIST,%D
  1. N RESULT,DEBUG,BSTSR,BSTSI,RET,DAT,BSTSWS,BSTSD,X,%,%H,INDATE
  1. K @OUT
  1. ;
  1. I $G(U)="" S U="^"
  1. I $G(DT)="" D DT^DICRW
  1. S IN=$G(IN,"")
  1. S SEARCH=$P(IN,U) Q:($TR(SEARCH," ")="") "0^Invalid Search String"
  1. S STYPE=$P(IN,U,2) I STYPE'="F",STYPE'="S" Q "0^Invalid Search Type"
  1. S NMID=$P(IN,U,3) S:NMID="" NMID=36 S:NMID=30 NMID=36
  1. S SUB=$P(IN,U,6)
  1. S SNAPDT="" S:SNAPDT]"" SNAPDT=$$DATE^BSTSUTIL(SNAPDT)
  1. S INDATE=$P(SNAPDT,".")
  1. S:SNAPDT="" SNAPDT=DT_".0001"
  1. S SNAPDT=$$FMTE^BSTSUTIL(SNAPDT)
  1. S MAX=$P(IN,U,5) S:'MAX MAX=25
  1. S RET="PSBIXCA"
  1. S DAT=""
  1. S BCTCHRC=""
  1. S BCTCHCT="" I BCTCHRC,'BCTCHCT S BCTCHCT=MAX
  1. S LOCAL=""
  1. S DEBUG=$P(IN,U,6),DEBUG=$S(DEBUG=1:"1",1:"")
  1. ;
  1. S BSTSWS("SEARCH")=SEARCH
  1. S BSTSWS("STYPE")=STYPE
  1. S BSTSWS("NAMESPACEID")=NMID
  1. S BSTSWS("SUBSET")=SUB
  1. S BSTSWS("SNAPDT")=SNAPDT
  1. S BSTSWS("INDATE")=INDATE
  1. S BSTSWS("MAXRECS")=MAX
  1. S BSTSWS("BCTCHRC")=BCTCHRC
  1. S BSTSWS("BCTCHCT")=BCTCHCT
  1. S BSTSWS("RET")=RET
  1. S BSTSWS("DAT")=DAT
  1. S BSTSWS("DEBUG")=DEBUG
  1. ;
  1. S BSTSI=0
  1. ;
  1. ;Make DTS search call
  1. S BSTSR=1
  1. ;
  1. ;DTS Call
  1. S BSTSR=$$USEARCH^BSTSWSV1(OUT,.BSTSWS,DEBUG) S:+BSTSR $P(BSTSR,U)=2
  1. ;
  1. ;Now loop through and get the detail
  1. I $D(RESULT) D
  1. . ;
  1. . NEW DLIST,ERSLT
  1. . ;
  1. . ;Define scratch global
  1. . S DLIST=$NA(^TMP("BSTSCMCL",$J)) ;DTS Return List
  1. . ;
  1. . NEW RCNT
  1. . ;
  1. . S RCNT="" F S RCNT=$O(RESULT(RCNT)) Q:RCNT="" D
  1. .. ;
  1. .. NEW REC,CONCID,DTSID,DSCID,STATUS
  1. .. S REC=RESULT(RCNT)
  1. .. ;
  1. .. S CONCID=$P(RESULT(RCNT),"^")
  1. .. S DTSID=$P(RESULT(RCNT),"^",2)
  1. .. S DSCID=$P(RESULT(RCNT),"^",3)
  1. .. ;
  1. .. ;Not Found or in need of update
  1. .. S BSTSWS("DTSID")=DTSID
  1. .. ;
  1. .. ;Clear result file
  1. .. K @DLIST
  1. .. ;
  1. .. ;Get Detail for concept
  1. .. S STATUS=$$DETAIL^BSTSCMCL(.BSTSWS,.ERSLT)
  1. .. ;
  1. .. ;Assemble output for RPC
  1. .. S @SLIST@(RCNT)=$P($G(@DLIST@(1,"CONCEPTID")),U)
  1. ;
  1. Q BSTSR
  1. ;
  1. ;BSTS*1.0*7;Added EQUIV API Call
  1. EQUIV(OUT,IN) ;PEP - Returns equivalent laterality concepts
  1. ;
  1. ;Input
  1. ; OUT - Output variable/global to return information in (VAR)
  1. ; IN - P1 - Concept Id
  1. ; - P2 - Laterality Attribute|Qualifier
  1. ; 7771000 or 272741003|7771000 - Laterality|Left
  1. ; 24028007 or 272741003|24028007 - Laterality|Right
  1. ; 51440002 or 272741003|51440002 - Laterality|Bilateral
  1. ;
  1. ;Output
  1. ; OUT(#) = Matching Concept ID [1] ^ Matching Laterality Attribute|Qualifier [2] ^ Exact Match (1/0) [3]
  1. ; ^ entry is lateralized or is an equivalent lateralized concept (1/0)
  1. ;BSTS*2.0*1;Now returning all lateralized concepts for an unlateralized input concept
  1. NEW CONC,LAT,NCNT,BSTSVAR,STS,ENTLOG,AT,ECNC,ATLAT,MLAT,LTLST,LT,LTLAT
  1. ;
  1. I $G(IN)="" Q
  1. I $G(OUT)="" Q
  1. ;
  1. K @OUT
  1. ;
  1. ;Retrieve concept id
  1. S CONC=$P(IN,U) Q:CONC=""
  1. S ATLAT=$P(IN,U,2) I ATLAT]"",$L(ATLAT,"|")=1 S ATLAT="272741003"_"|"_ATLAT
  1. S LAT=$P(ATLAT,"|",2)
  1. S AT=$P(ATLAT,"|")
  1. ;
  1. ;Get the concept detail
  1. S STS=$$CNCLKP^BSTSAPI("BSTSVAR",CONC)
  1. ;
  1. ;Set up the passed in entry, and if laterality non-lateralized entry
  1. S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CONC_U_ATLAT_U_1_U_$S(ATLAT]"":1,$G(BSTSVAR(1,"EQM","LAT"))]"":1,1:"0") S:ATLAT]"" LTLAT(CONC,ATLAT)=""
  1. I ATLAT="" S ENTLOG(CONC)=""
  1. E S ENTLOG(CONC,ATLAT)=""
  1. I ATLAT]"" D
  1. . S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CONC_U_U_0_U
  1. . S ENTLOG(CONC)=""
  1. ;
  1. ;Now look for a matching equivalant concept
  1. S ECNC=$G(BSTSVAR(1,"EQM","CON")) I ECNC]"" D
  1. . NEW ELAT
  1. . S ELAT=$G(BSTSVAR(1,"EQM","LAT")) S:ELAT]"" ELAT="272741003|"_$O(^BSTS(9002318.6,"D","LAT",ELAT,""))
  1. . S NCNT=$G(NCNT)+1,@OUT@(NCNT)=ECNC_U_ELAT_U_1_U S:ELAT]"" LTLST(ECNC,ELAT)=""
  1. . I ELAT="" S ENTLOG(ECNC)="" Q
  1. . ;
  1. . ;Log entry
  1. . S ENTLOG(ECNC,ELAT)=""
  1. . ;
  1. . ;If laterality, catch the parent concept as well as non-exact match
  1. . S NCNT=$G(NCNT)+1,@OUT@(NCNT)=ECNC_U_U_0_U
  1. . Q
  1. ;
  1. ;Now look for a concept with matching laterality
  1. S MLAT="" F S MLAT=$O(BSTSVAR(1,"EQC",MLAT)) Q:MLAT="" D
  1. . NEW ILAT,CON
  1. . ;
  1. . ;Get SNOMED for the laterality
  1. . S ILAT=$O(^BSTS(9002318.6,"D","LAT",MLAT,"")) Q:ILAT=""
  1. . ;
  1. . ;Get the concept
  1. . S CON=$G(BSTSVAR(1,"EQC",MLAT,"CON"))
  1. . ;
  1. . ;Look for match - if not a match return as non-exact match
  1. . I LAT'=ILAT D Q
  1. .. I LAT="" D
  1. ... S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CON_U_U_0_U
  1. ... I $G(BSTSVAR(1,"LAT")),'$D(ENTLOG(CONC,ILAT)) S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CONC_U_"272741003|"_ILAT_U_0 S:ILAT]"" LTLST(CONC,"272741003|"_ILAT)=""
  1. . ;
  1. . ;Set entry
  1. . S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CON_U_U_1_U
  1. ;
  1. ;BSTS*2.0*1;Add remaining lateralized concepts
  1. I ATLAT="",$G(BSTSVAR(1,"LAT")) F LT="272741003|7771000","272741003|24028007","272741003|51440002" I '$D(LTLST(CONC,LT)) D
  1. . S NCNT=$G(NCNT)+1,@OUT@(NCNT)=CONC_U_LT_U_0_U
  1. ;
  1. Q
  1. ;
  1. ERR ;
  1. D ^%ZTER
  1. Q