ICD 9 codes vary in length between 3 and 5 characters long.


When the Italian local authority supplies Capitolo cases for each hospital we need to convert to ICD 9. Our aim is not to randomly assign ICD 9 codes, but to assign a code / cases to a hospital on a calculated probability of the hospital dealing with that discipline instead. We do this by creating a frequency / distribution table. The stages are as follows:

 

1.Combine all the hospital ICD 9 data we have into one table to become national ICD9 diagnostics.

2.Remove rows where ICD9 code is not start with 0 to 9 character.

3.Drop the serial and ammap_region columns.

4.Process the the duplicate codes taking into consideration the year and summing up the cases to leave just one code per year with the cases summed.

5.Spilt the national table into years creating a new table for each year i.e national_icd9_diagnostics_2023


The above stages can be completed by running a PHP file called Create national ICD9 tables per year v0.1.php


6.For each table insert a column call capitolo (VARCHAR(2)) which is the major diagnostic category (MDC)

7.We will end up with four columns called year, capitolo, icd9 and cases.

8.Running the following SQL query to will populate the capitolo column:

UPDATE `national_icd9_diagnostics` a

JOIN `capitolo_icd9_reference_table` b

ON LEFT(a.`icd9`, 3) >= b.`start` AND LEFT(a.`icd9`, 3) <= b.`end`

SET a.`capitolo` = b.`capitolo`;

The table will end up like this:

9.The frequency / distribution table calculation is based upon: capitolo (MDC) ICD9 divided by the total ICD9 cases in that capitolo (MDC) range

Take the following example:

The national ICD9 cases table has two rows

And after running the PHP to create frequency / distribution table


Stages 6 to 9 can be completed by running a PHP file called Capitolo (MDC) to ICD9 frequency-disribution table creatation v0.2.php