0

I'm working on an ICD10 diagnosis code application. I need to determine if one ICD10 code falls in a certain range. For example:

Code: 4A1H7EZ

Range: 4A1H7CZ - 4A1H7HZ

This should return 'True'.

I've tried converting the alpha characters to numbers (a=0, b=1 etc) but the resulting number conflicts with other ranges/codes.

Regex isn't my strong point, any suggestions would be appreciated.

Kieran Quinn
  • 1,085
  • 2
  • 22
  • 49

3 Answers3

2

Do you have to use regex? As seen here in comparing 2 strings alphabetically for sorting purposes javascript auto compares strings.

So "4A1H7EZ" > "4A1H7CZ" && "4A1H7EZ" < "4A1H7HZ" will return true

Community
  • 1
  • 1
Guy Grin
  • 1,968
  • 2
  • 17
  • 38
  • Interesting but only works if the last digits are always letters. In my case, the last 2 digits could be alphanumeric. Example: _4A0J72Z_ – Kieran Quinn Oct 27 '15 at 15:12
  • I'm not sure I understand you - `"4A0J723" > "4A0J722"` yields `true`. However I did not mention that letters are "larger" than numbers so `"4A0J72Z" > "4A0J729"` will also yield `true` and also there is a difference between cased letters – Guy Grin Oct 27 '15 at 15:36
  • Sorry, been busy. This actually seems to work quite well on all the tests I've performed so far – Kieran Quinn Nov 02 '15 at 10:27
  • 1
    Yes, good solution, but you might get caught out by `X` which is a padding character, not a diagnostic indicator (except when it is the initial character). There are sometimes decimal places used, which you'd have to remove before comparison. Finally, you can hit very subtle encoding issues on different platforms, e.g. once I found spaces were ignored in string comparison on some platforms, but not others. You might want to make sure that the ICD codes are ASCII. My R package `icd9` (`icd10` branch on github) https://github.com/jackwasey/icd9/tree/icd10 has lots of regexes for ICD-10 codes. – Jack Wasey Feb 02 '16 at 10:32
1

David has the right answer for doing this in Javascript.

However, an "ICD10 diagnosis code application" probably should be using a database; and given that, you should really solve this with SQL, in which case it would be trivial.

A query like this would return any range that matched a given code:

select * from ranges where diag_code between range_start and range_end
0

You should use a loop and compare each index one by one. With somethings like that:

for entry, index in code:
  if entry.isNumeric:
      if range[index] < entry and rang2[index] > entry:
         return false

  else
      if compareAlpha(range[index], entry) > 1 and compareAlpha(range2[index], entry ) < 0:
         return false
return true

(not tested)

David
  • 1,177
  • 3
  • 11
  • 26