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

ETSLNC1.m

Go to the documentation of this file.
  1. ETSLNC1 ;O-OIFO/FM23 - LOINC APIs 2 ;01/31/2017
  1. ;;1.0;Enterprise Terminology Service;**1**;Mar 20, 2017;Build 7
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. Q
  1. ;
  1. CHKCODE(ETSLOINC) ;Check if LOINC Code exists
  1. ;
  1. ;Input
  1. ; ETSLOINC: LOINC Code with Check digit in a nnnnn-n format (i.e. 12345-6, 1-8, etc.)
  1. ;
  1. ;Output
  1. ; $$CHKCODE: IEN of the Valid Code
  1. ; or
  1. ; -1^error message
  1. ;
  1. N ETSCKDGT,ETSCODE,ETSIEN
  1. ;
  1. ;Validate that the LOINC Code is in the correct format
  1. I ETSLOINC'?1.5N1"-"1N Q "-1^Invalid LOINC Code"
  1. ;
  1. ;Look for the LOINC code in the database
  1. S ETSCKDGT=$P(ETSLOINC,"-",2),ETSCODE=$P(ETSLOINC,"-")
  1. I '$D(^ETSLNC(129.1,"B",ETSCODE)) Q "-1^LOINC Code not found"
  1. ;
  1. ; Validate that the Code is defined in the Database
  1. S ETSIEN=$O(^ETSLNC(129.1,"B",ETSCODE,""))
  1. S ETSDATA=$G(^ETSLNC(129.1,ETSIEN,0))
  1. I ETSDATA="" Q "-1^LOINC Code data missing"
  1. ;
  1. ;Validate the Check Digit
  1. I $P(ETSDATA,U,15)'=ETSCKDGT Q "-1^Invalid Check digit"
  1. ;
  1. ;Code is valid, return the IEN
  1. Q ETSIEN
  1. ;
  1. GETCODE(ETSIEN) ;Get LOINC Code by IEN
  1. ; Input -- ETSIEN LOINC file IEN
  1. ; Output -- $$GETCODE
  1. ; LOINC Code with check digit
  1. ; or
  1. ; -1^<error message> - Error
  1. ;
  1. ;Initialize default output
  1. N ETSANS,ETSDATA
  1. S ETSANS="-1^LOINC Code not found"
  1. ;
  1. ;Check for missing variable, exit if not defined
  1. Q:$G(ETSIEN)="" "-1^Missing Parameter"
  1. ;
  1. ;Set-up LOINC Code to return
  1. S ETSDATA=$G(^ETSLNC(129.1,ETSIEN,0))
  1. I ETSDATA'="" S ETSANS=$P(ETSDATA,U,1)_"-"_$P(ETSDATA,U,15)
  1. Q $G(ETSANS)
  1. ;
  1. GETNAME(ETSINPT,ETSINTY,NAME) ;Get LOINC Name Array by Code or IEN
  1. ; Input -- ETSINPT LOINC Code or IEN
  1. ; ETSINTY Input Type (Optional- Default "C")
  1. ; "C"=LOINC Code
  1. ; "I"=LOINC IEN
  1. ;
  1. ; Output -- NAME LOINC Name Array subscripts: (array will be cleared upon entry)
  1. ; ("FULLNAME")=Fully Specified Name field (#80)
  1. ; ("SHORTNAME")=ShortName field (#81)
  1. ; ("LONGNAME")=Long Common Name field (#83)
  1. ; or
  1. ; $$GETNAME 1 for success and results found
  1. ; 0 no results found
  1. ; or
  1. ; -1^<error message>
  1. ;
  1. N ETSCIEN,ETSCODE
  1. ;
  1. ;Check for result array , exit if not defined
  1. Q:'$D(NAME) "-1^Missing Return Array"
  1. ;
  1. ;Clear array pieces and re-initialize result array
  1. K NAME("FULLNAME"),NAME("LONGNAME"),NAME("SHORTNAME")
  1. ;
  1. ;Check for existence of an IEN/Code
  1. Q:$G(ETSINPT)="" "-1^Missing Code or IEN"
  1. ;
  1. ;Set Input Type to default of "C", if not defined
  1. S:$G(ETSINTY)="" ETSINTY="C"
  1. I (ETSINTY'="C"),(ETSINTY'="I") Q "-1^Invalid Input Type"
  1. ;
  1. S ETSCIEN="" ; initialize the IEN.
  1. ;
  1. ;Check input for LOINC Code or IEN
  1. ;Assume the input type is an IEN
  1. I ETSINTY="I" D Q:(ETSCIEN="") "-1^Invalid LOINC IEN"
  1. . S:$D(^ETSLNC(129.1,ETSINPT,0)) ETSCIEN=ETSINPT
  1. ;if the input type was a code, retrieve the IEN.
  1. I ETSINTY="C" D Q:(+ETSCIEN=-1) ETSCIEN
  1. . S ETSCIEN=$$CHKCODE(ETSINPT)
  1. ;
  1. ;Set-up LOINC Name array to return
  1. S NAME("FULLNAME")=$G(^ETSLNC(129.1,ETSCIEN,80))
  1. S NAME("SHORTNAME")=$G(^ETSLNC(129.1,ETSCIEN,81))
  1. S NAME("LONGNAME")=$G(^ETSLNC(129.1,ETSCIEN,83))
  1. Q 1
  1. ;
  1. GETIEN(ETSCODE) ;Retrieve the IEN if given a code.
  1. Q:$G(ETSCODE)="" "" ;Return "" if code not sent in
  1. Q $O(^ETSLNC(129.1,"B",ETSCODE,"")) ;No duplicates so return code
  1. ;
  1. GETSTAT(ETSINPT,ETSTYP) ; Retrieves the current Status.
  1. ;
  1. ;Input
  1. ; ETSINPT: LOINC Code or LOINC IEN
  1. ; ETSTYP: Input Type, either C for Code (default) or I for IEN
  1. ;
  1. ;Output
  1. ; $$GETSTAT: Current Status (Internal format^External Format)
  1. ; or
  1. ; -1^error code
  1. ;
  1. N ETSCIEN,ETSCODE,ETSSTATI,ETSANS
  1. ;
  1. ;Check for missing variable, exit if not defined
  1. Q:$G(ETSINPT)="" "-1^Missing LOINC Code"
  1. ;
  1. ;Set Input Type to default of "C", if not defined
  1. S:$G(ETSTYP)="" ETSTYP="C"
  1. S ETSTYP=$$UP^XLFSTR(ETSTYP)
  1. I (ETSTYP'="C"),(ETSTYP'="I") Q "-1^Invalid Input Type"
  1. ;
  1. ;Check input for LOINC Code or IEN
  1. ;Assume the input type is an IEN
  1. S:ETSTYP="I" ETSCIEN=ETSINPT
  1. ;
  1. ;if the input type was a code, retrieve the IEN.
  1. I ETSTYP="C" S ETSINPT=$$UP^XLFSTR(ETSINPT),ETSCIEN=$$CHKCODE(ETSINPT)
  1. ;
  1. ;Exit if the IEN was either not passed in or not found.
  1. Q:(+ETSCIEN=-1) ETSCIEN
  1. ;
  1. ;Exit if IEN, but no data for IEN
  1. Q:'$D(^ETSLNC(129.1,ETSCIEN,0)) "-1^LOINC IEN Not Found"
  1. ;
  1. ;Get LOINC Status
  1. S ETSSTATI=$P($G(^ETSLNC(129.1,ETSCIEN,4)),"^",1)
  1. ;
  1. ;Set-up LOINC Status to return
  1. ;return Active if no status found (per field definition)
  1. Q:ETSSTATI="" "^ACTIVE"
  1. ;
  1. ;return status (Internal^external) if found
  1. S ETSANS=ETSSTATI_"^"_$$EXTERNAL^DILFD(129.1,20,"",ETSSTATI)
  1. Q $G(ETSANS)
  1. ;