# Distance measure for hierarchical nominal data

I have categorical data which follow a hierarchical structure (in fact they're medical codes). For instance:

C10: Diabetes Mellitus
E00: Senile dementia
E10: Schizophrenia
E2B1: Chronic Depression
G20: High Blood Pressure
K05: Chronic Kidney Disease
K20: Prostatism

A simple measure like the Levenshtein distance, which looks at the number of primary edits needed to transform one word to the other, is not appropriate as it does not capture the hierarchical ordering, for example:

$$D(C10,E10)=1$$
$$D(E00,E10)=1$$

As you can see, the distance for these two cases is $$1$$. But the problem is that E00 and E10 are semantically more related (they're both mental disorders, and this is capture by the first character E). Hence, I would really appreciate some ideas as I do not think that distance measures like Manhattan, Gower or the Levenshtein are appropriate enough to capture this hierarchical structure. Maybe giving more weight to the first character that determines the disease class? Some other measures I am not aware? Thank you!