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

IBDLXDG.m

Go to the documentation of this file.
  1. IBDLXDG ;ALB/CFS - ICD-10 DIAGNOSIS CODE LOOK UP ;03/27/2012
  1. ;;3.0;AUTOMATED INFO COLLECTION SYS;**63**;APR 24, 1997;Build 80
  1. ;
  1. ;
  1. ;ICRs
  1. ; Reference to $$DIAGSRCH^LEX10CS supported by ICR #5681
  1. ; Reference to $$IMPDATE^LEXU supported by ICR #5679
  1. ; Reference to $$FREQ^LEXU supported by ICR #5679
  1. ; Reference to $$MAX^LEXU supported by ICR #5679
  1. ; Reference to $$ICDDX^ICDEX supported by ICR #5747
  1. ; Reference to ^DISV supported by ICR #510
  1. ;
  1. ;//---------
  1. ;The entry point for ICD-10 diagnosis search functionality
  1. ;can be called from applications directly
  1. ;input parameters :
  1. ; IBDDT - date of interest (Fileman format)
  1. ; IBDDFLT - default values for the search string (can be a code by default)
  1. ; IBDPARAM - parameters/string constants (see SETPARAM for details)
  1. ;returns ICD-10 code selected by the user:
  1. ; IEN file #80;ICD code value;IEN file # 757.01^description
  1. ; results
  1. ; or -1 if invalid data(press enter)
  1. ; "" if not found
  1. ; or -2 if time out
  1. ; or -3 if ^ or ^^
  1. ; or -4 in ICD10 if the user answered NO for the question "Do you wish to continue(Y/N)?"
  1. ; or -5 if no changes to the default value
  1. DIAG10(IBDDT,IBDDFLT,IBDPARAM) ;
  1. N IBDROOT,IBDRETV,IBDSPACE S IBDROOT="^ICD9("
  1. N IBDINP
  1. F D Q:IBDINP<0!($L($P(IBDINP,U,2))>1)!(IBDSPACE=1)
  1. . ;user enters ANY text like "diabetes" or code or space
  1. . S IBDSPACE=0
  1. . S IBDINP=$$SRCHSTR(IBDPARAM("SEARCH_PROMPT"),IBDPARAM("HELP ?"),IBDPARAM("HELP ??"),IBDDFLT)
  1. . ;process the space bar recall
  1. . I $P(IBDINP,U,2)=" ",$G(IBDROOT)]"" D S:IBDRETV>0 IBDSPACE=1 Q
  1. . . ;if space bar was entered then get the last code entered by the user from ^DISV
  1. . . S IBDRETV=$$SPACEBAR(IBDDT,IBDROOT,30)
  1. . . I IBDRETV<0 W "??" Q
  1. . . W $P(IBDRETV,";",2)
  1. . I IBDINP'<0 I $L($P(IBDINP,U,2))'>1 W !!,IBDPARAM("ENTER MORE") W:$L(IBDPARAM("ENTER MORE2"))>0 !,IBDPARAM("ENTER MORE2") W ! ;user should enter at least 2 characters
  1. ;if space bar was entered then get the last code entered by the user from ^DISV and quit
  1. I IBDSPACE=1,IBDRETV>0 Q IBDRETV
  1. I IBDINP<0 Q +IBDINP
  1. ;
  1. ;send the search test to Lexicon and let the user pick one
  1. S IBDRETV=$$LEXICD10($P(IBDINP,U,2),IBDDT,.IBDPARAM)
  1. ;
  1. ;if spacebar recall is supported, if code is selected, if it is valid then
  1. ;save selection in ^DISV
  1. I $G(IBDROOT)]"",IBDRETV>0 D SAVSPACE(IBDROOT,+IBDRETV)
  1. ;
  1. Q IBDRETV
  1. ;
  1. ;
  1. ;retrieves the last code selected by the user - space bar recall logic here
  1. ; if nothing then returns -1
  1. ;IBDDT - date of service
  1. ;IBDROOT - global root is used in ^DISV (ex. "^ICD9(" )
  1. ;IBDCODSY - coding system for which the user is trying to enter an ICD code. It is used to check
  1. ; if the code stored in ^DISV matches the coding system the user is using at the prompt.
  1. ; 30 - for ICD-10 diagnoses
  1. ; 1 - for ICD-9 diagnoses
  1. SPACEBAR(IBDDT,IBDROOT,IBDCODSY) ;
  1. N IBDCODE,IBDRTV,IBDX
  1. I IBDROOT="^ICD9(" D
  1. . S IBDCODE=$G(^DISV(DUZ,IBDROOT)) ;needs ICR #510 subscription
  1. . I +IBDCODE=0 S IBDRTV=-1 Q
  1. . ;check if the code in ^DISV for the ICD-10 coding system (30 in the 3rd parameter)
  1. . ;we don't need to check this for ICD-9 becuase
  1. . S IBDX=$$ICDDX^ICDEX(IBDCODE,IBDDT,IBDCODSY,"I")
  1. . S IBDRTV=$P(IBDX,U,1)_";"_$P(IBDX,U,2)_";"_$P(IBDX,U,4)
  1. ;if IBDROOT is different then implement your own logic here
  1. Q IBDRTV
  1. ;
  1. ;store the selected code for the space bar recall feature
  1. ;IBDROOT - global root is used in ^DISV (ex. "^ICD9(" )
  1. ;IBDRETV - IEN of the top level entry wiht ICD code field
  1. SAVSPACE(IBDROOT,IBDRETV) ;
  1. I +$G(DUZ)=0 Q
  1. I IBDROOT="^ICD9(" D RECALL^DILFD(80,(+IBDRETV)_",",+DUZ) Q ;need subscription to ICR #510
  1. ;if IBDROOT is different then implement your own logic here
  1. Q
  1. ;
  1. ;
  1. ;--------------
  1. ;The entry point for ICD-10 diagnosis search functionality
  1. ;can be called from applications directly
  1. ; Supported ICR 5681 ($$DIAGSRCH^LEX10CS)
  1. ;input parameters :
  1. ; IBDTXT - search string
  1. ; IBDDATE - date of interest
  1. ; IBDPAR - array with text messages and other string constants
  1. ;returns ICD-10 code selected by the user:
  1. ; IEN file #80;ICD code value^description
  1. ; or
  1. ; "" if not found
  1. ; -1 if exit : ^ or ^^
  1. ; -2 if continue searching
  1. ;
  1. LEXICD10(IBDTXT,IBDDATE,IBDPAR) ; ICD-10 Search
  1. N IBDLVTXT
  1. ;parameters check
  1. S IBDDATE=+$G(IBDDATE)
  1. I IBDDATE'?7N Q -1
  1. S IBDTXT=$G(IBDTXT)
  1. Q:'$L(IBDTXT) -1
  1. N IBDNUMB
  1. S IBDNUMB=$$FREQ^LEXU(IBDTXT)
  1. I IBDNUMB>$$MAX^LEXU(30) D I $$QUESTION(2,IBDPARAM("WISH CONTINUE"),IBDPARAM("YES OR NO"))'=1 Q -4
  1. . W !
  1. . D FORMWRIT(IBDPAR("EXCEEDS MESSAGE1")_IBDTXT_IBDPAR("EXCEEDS MESSAGE2")_IBDNUMB_IBDPAR("EXCEEDS MESSAGE3")_IBDTXT_""".",0)
  1. . D FORMWRIT("",2)
  1. . W !
  1. ;new and set variables
  1. N DIROUT,DUOUT,DTOUT,IBDEXIT,IBDICDNT
  1. N IBDRETV,IBDXX,IBDLEVEL
  1. S IBDRETV=""
  1. S IBDEXIT=0
  1. S IBDLEVEL=1,IBDLVTXT(IBDLEVEL)=IBDTXT ;level 1 stores the original search string
  1. ; main loop
  1. F Q:IBDEXIT>0 D
  1. .K IBDICDY
  1. .;get the search string from the current level and call LEX API
  1. .;don't pass the date - this will initiate the unversioned lookup for AICS to get all codes - active and inactive
  1. .S IBDICDY=$$DIAGSRCH^LEX10CS(IBDLVTXT(IBDLEVEL),.IBDICDY,,30)
  1. .;cleanup the output array:
  1. .; - leave codes active on the date
  1. .; - leave codes inactive on the date if their last status is ACTIVE
  1. .; - remove codes inactive on the date if their last status is INACTIVE
  1. .I IBDICDY>0 S IBDICDY=$$REMINARR^IBDUTICD(.IBDICDY,IBDDATE)
  1. .S:$O(IBDICDY(" "),-1)>0 IBDICDY=+IBDICDY
  1. .; Nothing found
  1. .I +IBDICDY'>0 S IBDEXIT=1 S IBDXX=-1 Q
  1. .; display the list of items and ask the user to select the item from the list
  1. .S IBDXX=$$SEL^IBDLXDG2(.IBDICDY,4)
  1. .; if ^ was entered
  1. .; if this is on the top level then quit
  1. .I IBDXX=-2,IBDLEVEL'>1 S IBDRETV=-1 S IBDEXIT=1 Q
  1. .; if lower level then go one level up
  1. .I IBDXX=-2,IBDLEVEL>1 S:IBDLEVEL>1 IBDLEVEL=IBDLEVEL-1 Q
  1. .; If timeout, or not selected, or ^^ then quit
  1. .I IBDXX=-1 S IBDRETV=-1 S IBDEXIT=1 Q
  1. .; if Code Found and Selected by the user save selection in IBDRETV and quit
  1. .I $P(IBDXX,";")'="99:CAT" S IBDRETV=IBDXX S IBDEXIT=1 Q
  1. .; If Category Found and Selected by the user:
  1. .; go to the next inner level
  1. .; change level number
  1. .S IBDLEVEL=IBDLEVEL+1
  1. .; set the new level with the new search string
  1. .; and repeat
  1. .S IBDLVTXT(IBDLEVEL)=$P($P($G(IBDXX),"^"),";",2)
  1. Q IBDRETV
  1. ;
  1. ;---------
  1. ; Clean up environment and quit
  1. EXIT ;
  1. K %,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,X,Y
  1. Q
  1. ;
  1. ;-----------
  1. ; Look-up help for ?
  1. INPHLP ;
  1. I $G(X)["???" D INPHLP3 Q
  1. I $G(X)["??" D INPHLP2 Q
  1. W !," Enter code or ""text"" for more information." Q
  1. Q
  1. ;-----------
  1. ; Look-up help for ??
  1. INPHLP2 ;
  1. W !," Enter a ""free text"" term or part of a term such as ""femur fracture""."
  1. W !!," or "
  1. W !!," Enter a ""classification code"" (ICD/CPT etc) to find the single term"
  1. W !," associated with the code."
  1. W !!," or "
  1. W !!," Enter a ""partial code"". Include the decimal when a search criterion"
  1. W !," includes 3 characters or more for code searches."
  1. Q
  1. ;--------
  1. ; Look-up help for ???
  1. INPHLP3 ;
  1. W !," Number of Code Matches"
  1. W !," ----------------------"
  1. W !!," The ICD-10 Diagnosis Code search will show the user the number of matches"
  1. W !," found, indicate if additional characters in ICD code exist, and the number"
  1. W !," of codes within the category or subcategory that are available for selection."
  1. W !," For example:"
  1. W !!," 19 matches found"
  1. W !!," M91. - Juvenile osteochondrosis of hip and pelvis (19)"
  1. W !!," This indicates that 19 unique matches or matching groups have been found"
  1. W !," and will be displayed."
  1. W !!," M91. - the ""-"" indicates that there are additional characters that specify"
  1. W !," unique ICD-10 codes available."
  1. W !!," (19) Indicates that there are 19 additional ICD-10 codes in the M91 ""family"""
  1. W !," that are possible selections."
  1. Q
  1. ;--------
  1. ;prompt the user for a date of interest
  1. ;input parameters :
  1. ; IBDPRMT - prompt
  1. ;returns YYYMMDD
  1. ; or -1 if invalid date
  1. ; or -2 if time out
  1. ; or -3 if ^
  1. ASKDATE(IBDPRMT) ;
  1. N %DT,DIROUT,DUOUT,DTOUT
  1. S %DT="AEX",%DT("A")=$G(IBDPRMT,"Enter a date: ")
  1. D ^%DT
  1. Q:Y<0 -1
  1. Q:$D(DTOUT) -2
  1. Q:X="^" -3
  1. Q (+Y)
  1. ;--------
  1. ;ask YES/NO questions
  1. ;input parameters :
  1. ; IBDDFLT- 0/null- not default, 1- yes, 2 -no
  1. ; IBDPROM - prompt string
  1. ;returns
  1. ; 2 - no,
  1. ; 1 - yes,
  1. ; 0 - no answer (time out)
  1. ; -3 - ^ or ^^
  1. QUESTION(IBDDFLT,IBDPROM,IBDHELP) ;
  1. N DIR
  1. S %=$G(IBDDFLT,2)
  1. S DIR(0)="Y",DIR("A")=IBDPROM,DIR("B")=$S(%=1:"Yes",%=2:"No",1:"")
  1. S:$L($G(IBDHELP)) DIR("?")=IBDHELP
  1. D ^DIR
  1. Q:Y["^" -3
  1. Q:Y=1 1
  1. Q:Y=0 2
  1. Q 0
  1. ;
  1. ;------------
  1. ;get search string
  1. ;input parameters :
  1. ; IBDPRMT prompt text
  1. ; IBDHLP1 "?" help text
  1. ; IBDHLP2 "??" help text
  1. ; IBDDFLT- default response
  1. ;returns piece1 ^ piece 2
  1. ; piece1:
  1. ; 0 if normal input
  1. ; or -1 if invalid data
  1. ; or -2 if time out
  1. ; or -3 if ^
  1. ; or -5 if user accepts default value then no need to validate it
  1. ; or -6 if user enters "@"
  1. ; piece2: string entered by the user
  1. SRCHSTR(IBDPRMT,IBDHLP1,IBDHLP2,IBDDFLT) ;
  1. N DIR
  1. S DIR("A")=IBDPRMT
  1. S:($G(IBDHLP1)]"") DIR("?")=IBDHLP1
  1. S:($G(IBDHLP2)]"") DIR("??")=IBDHLP2
  1. I $L($G(IBDDFLT)) S DIR("B")=IBDDFLT
  1. S DIR(0)="FAOR^0:245"
  1. D ^DIR
  1. Q:$D(DTOUT) -2
  1. Q:$D(DUOUT) -3
  1. ;Q:X="@" -6 ;quit if user entered "@" and handle deletion case in your application - not used in AICS
  1. Q:Y["^" -3
  1. Q:Y="" -1
  1. ;Q:(($L($G(IBDDFLT)))&(Y=IBDDFLT)) -5 ;if user accepts default value then no need to validate it - not used in AICS
  1. Q 0_U_Y
  1. ;
  1. ;----------
  1. ;Determines and returns ACTIVE coding system for DIAGNOSES based on date of interest
  1. ;input parameters :
  1. ; IBDICDD - date of interest
  1. ; if date of interest is null, today's date will be assumed
  1. ;returns coding system
  1. ; as a pointer to the ICD CODING SYSTEM file #80.4 (supported ICR 5780)
  1. ; 30 if ICD-10-CM is active system
  1. ; 1 if ICD-9-CM is active system
  1. ICDSYSDG(IBDICDD) ;
  1. N IBDIMPDT
  1. S IBDICDD=$S(IBDICDD<0!($L(+IBDICDD)'=7):DT,1:+$G(IBDICDD))
  1. S IBDIMPDT=$$IMPDATE^LEXU("10D")
  1. Q $S(IBDICDD'<IBDIMPDT:30,1:1)
  1. ;
  1. ;set parameters
  1. ;edit these hardcoded strings that are used for prompts, messages and so on to adjust them to your application's needs
  1. ;input parameters
  1. ; IBDPAR - local array to sets and store string constants for your messages and prompts
  1. SETPARAM(IBDPAR) ;
  1. S IBDPAR("ASKDATE")="Date of interest? "
  1. S IBDPAR("SEARCH_PROMPT")="Enter Diagnosis, a Code or a Code Fragment: "
  1. S IBDPAR("HELP ?")="^D INPHLP^IBDLXDG"
  1. S IBDPAR("HELP ??")="^D INPHLP2^IBDLXDG"
  1. S IBDPAR("NO DATA FOUND")=" No records found matching the value entered, revise search or enter ""?"" for"
  1. S IBDPAR("NO DATA FOUND 2")=" help."
  1. S IBDPAR("EXITING")=" Exiting"
  1. S IBDPAR("TRY LATER")=" Try again later"
  1. S IBDPAR("NO DATA SELECTED")=" No data selected"
  1. S IBDPAR("TRY ANOTHER")="Try another"
  1. S IBDPAR("WISH CONTINUE")="Do you wish to continue (Y/N)"
  1. S IBDPAR("EXCEEDS MESSAGE1")="Searching for """
  1. S IBDPAR("EXCEEDS MESSAGE2")=""" requires inspecting "
  1. S IBDPAR("EXCEEDS MESSAGE3")=" records to determine if they match the search criteria. This could take quite some time. Suggest refining the search by further specifying """
  1. S IBDPAR("ENTER MORE")=" Please enter at least the first two characters of the ICD-10 code or code"
  1. S IBDPAR("ENTER MORE2")=" description to start the search."
  1. S IBDPAR("YES OR NO")="Answer 'Y' for 'Yes' or 'N' for 'No'"
  1. Q
  1. ;
  1. ;
  1. ;a wrapper for ^DIWP
  1. ;accumulates a text and then writes it to the device
  1. ;input parameters :
  1. ; X - text
  1. ; IBDMODE:
  1. ; 0 - start
  1. ; 1 - accumulate
  1. ; 2 - write
  1. ;example:
  1. ;D FORMWRIT^IBDLXDG("this API is a wrapper for ^DIWP, it accumulates a text and then writes it to the device, you can use it in your application code",0)
  1. ;D FORMWRIT^IBDLXDG("some more text ",1)
  1. ;D FORMWRIT^IBDLXDG("",2)
  1. FORMWRIT(X,IBDMODE) ;
  1. N IBDLI1,DIWL,DIWR
  1. ;if "start" mode
  1. I IBDMODE=0 K ^UTILITY($J,"W")
  1. S DIWL=1,DIWR=79
  1. I $L(X)>0 D ^DIWP
  1. ;if "write" mode
  1. I IBDMODE=2 D
  1. . S IBDLI1=0 F S IBDLI1=$O(^UTILITY($J,"W",1,IBDLI1)) Q:+IBDLI1=0 W !,$G(^UTILITY($J,"W",1,IBDLI1,0))
  1. . K ^UTILITY($J,"W")
  1. Q
  1. ;
  1. ;---------------
  1. ;Initialize variables if you need , your application most likely already has this
  1. INITVARS ;
  1. D HOME^%ZIS
  1. S:$G(DT)=0 DT=$$DT^XLFDT
  1. Q
  1. ;