Automatic Coding at Scale: Design and Deployment of a Nationwide System for Normalizing Referrals in the Chilean Public Healthcare System
Year: 2023

Abstract:
The disease coding task involves assigning a unique identifier from a controlled vocabulary to each disease mentioned in a clinical document. This task is relevant since it allows information extraction from unstructured data to perform, for example, epidemiological studies about the incidence and prevalence of diseases in a determined context. However, the manual coding process is subject to errors as it requires medical personnel to be competent in coding rules and terminology. In addition, this process consumes a lot of time and energy, which could be allocated to more clinically relevant tasks. These difficulties can be addressed by developing computational systems that automatically assign codes to diseases. In this way, we propose a two-step system for automatically coding diseases in referrals from the Chilean public healthcare system. Specifically, our model uses a state-of-the-art NER model for recognizing disease mentions and a search engine system based on Elasticsearch for assigning the most relevant codes associated with these disease mentions. The system’s performance was evaluated on referrals manually coded by clinical experts. Our system obtained a MAP score of 0.63 for the subcategory level and 0.83 for the category level, close to the best-performing models in the literature. This system could be a support tool for health professionals, optimizing the coding and management process. Finally, to guarantee reproducibility, we publicly release the code of our models and experiments.

heading: 1 Introduction
text: The clinical text represents a significant proportion of patient’s health records, commonly found in a non-structured format. These texts have particular challenges due to the extensive use of abbreviations, the variability of clinical language across medical specialties, and its restricted availability for privacy reasons (Dalianis, 2018). Due to the complexity of its analysis, this data is commonly discarded in projects that seek to support clinical decisionmaking (Kong, 2019).
Clinical coding involves mapping medical texts into codes using a controlled vocabulary consistent across different departments, hospitals, or even countries (Dong et al., 2022). The World Health Organization maintains an open, controlled vocabulary called the International Classification of Diseases (ICD), which is used in almost every country. Currently, the most widely used revision is the tenth (ICD-10) (World Health Organization, 2015), and they are developing its eleventh revision, which will include not only diseases (World Health Organization, 2023).
Regarding the Chilean public health system, the ICD-10 terminology is used for coding hospital discharges (morbidity coding by each healthcare provider) and deaths (mortality coding by the Ministry of Health). Having patients’ data normalized using these controlled vocabularies enables the ability to summarize information automatically and
335
not deal with the noisiness of free-text data. The already-digested information from the normalized data empowers data analysts who are not experts in NLP to add more complex information into their workflows.
The Waiting Time Management System (SIGTE, in Spanish) contains electronic records of referrals from the Chilean Waiting List, which is the system that manages the high demand existent for consultation by specialists (Ministerio de Salud de Chile, 2011). This data provided by 29 health services contain information about the medical diagnoses of patients but is not standardized (Báez et al., 2022).
As of November 2022, SIGTE recorded 25,374,491 waiting list referrals, of which 18,716,629 correspond to "new specialty referrals" and are associated with patient pathologies. Of these referrals, approximately 5,760,750 (30.7 %) have an ICD-10 code. This calculation was performed by searching for a regular expression formatted as an ICD-10 code in the free-text diagnosis fields.
Clinical experts perform the disease coding task manually, which is not optimal for several reasons. Firstly, since this process is subject to errors, medical personnel must have significant competence in coding rules and a thorough knowledge of specialized terminologies, such as ICD, which also get updated frequently. In other words, expert coding staff must be familiar with the clinical field, analytical and focused, and have fundamental skills for inspecting and analyzing highly specialized texts. In addition, manual coding is time-consuming (Yan et al., 2022), which could be optimized by a support system, and this time could be used for other tasks relevant to clinical decision-making.
These difficulties can be efficiently addressed using computational systems capable of automatically performing the coding task using NLP. Currently, most automatic coding systems are based on an end-to-end architecture based on deep learning techniques. Although these systems have boosted the performance of several coding tasks, they cannot incorporate context-specific rules, such as code priority, medical assumptions, code definition, and synonyms.
In this work, we developed an automated disease coding system, thus being able to code the entire historical waiting list in Chile, identifying a total of 18,716,629 referrals. Our system is based on two steps; first, the automatic extraction of diseases is
addressed using a state-of-the-art NER model, and then, using a search engine, the most probable code for each disease found is identified. Finally, we explored the potential applications derived from this system and studied in more depth the most frequent diseases in the country today.

heading: 2 Related Work
text: The disease coding task involves transforming clinical texts, commonly written by physicians in a non-structured format, into codes following medical terminologies. This is not an easy task since a medical ontology such as ICD in Spanish has 14,668 codes, an example of extreme multi-label classification (Barros et al., 2022). We have identified two major groups of computational methods proposed to solve this task; rule-based coding and neural network-based coding.

heading: 2.1 Rule-based Models
text: This approach involves designing hand-crafted rules to represent and simulate the flow that clinical experts follow when assigning codes. Most of the studies are based on using regular expressions and keywords to transform diseases found in the text into their respective codes. However, these methods are not feasible since manually capturing all the relations between texts and codes is time-consuming and complex.
Different approaches based on machine learning have been proposed to address this issue. In this way, features extracted from statistical models such as decision trees and support vector machines, among others, are incorporated into the manual rules (Stanfill et al., 2010; Teng et al., 2022; Farkas and Szarvas, 2008). Another method is to create a list of synonyms of the original text to calculate a word distance with respect to the code descriptions of the terminology. Despite their disadvantages, these methods have yielded high results in the literature, effectively supporting manual coding performed by humans (Zhou et al., 2020).

heading: 2.2 Models based on neural networks
text: Deep learning-based methods have significantly improved the disease coding task in recent years. The advantage of using these models is that the healthcare-specific domain knowledge is no longer needed for the manual development of complex rules. In contrast, these methods can automatically build features powerful enough to capture the rela-
tionships between clinical texts and their respective codes.
Most proposed systems are based on posing the problem as a multi-label text classification task (Karimi et al., 2017; Mullenbach et al., 2018; Yu et al., 2019; Cao et al., 2020). Thus, the algorithm’s input is text, while the output can be one or more codes associated with diseases. Unlike traditional text classification problems, this problem is considered extreme since the number of possible labels increases to thousands (depending on the terminology).
The main disadvantage of this approach is that manual coding requires incorporating contextspecific rules, such as code priority, medical assumptions, code definition, and synonyms, among other types of information, to improve system performance. In the case of deep learning, this is not considered since the systems are commonly created using an end-to-end approach, meaning that no human knowledge is involved when creating the features or making the predictions.
To solve the previous problem, we followed another approach used in the literature, which consists of mixing the previous ideas using two sequential steps; the first one uses deep learning algorithms, while the second allows us to incorporate medical knowledge into the computational system. Firstly, we used a Named Entity Recognition model for automatically recognizing sequences of words in the text which are associated with diseases. Then, each disease found is associated with its most likely ICD-10 code, a task better known as Entity Linking (Kraljevic et al., 2021; Wiegreffe et al., 2019). Nowadays, the most commonly used methods for solving the NER task are based on deep neural networks such as transformers-based models or recurrent neural networks, while a frequent technique for assigning codes is to use distance algorithms or search engines to compare the diseases found with the code descriptions of the terminology.

heading: 2.3 Commercial Systems
text: A handful of commercial products offer information extraction from clinical data, including automatic coding. These products usually are delivered as services and offered by leading cloud providers such as Amazon Web Services with Amazon Comprehend Medical1, Google Cloud with
1https://aws.amazon.com/comprehend/ medical/
Google Cloud Healthcare Data Engine2 and Microsoft Azure with Azure Cognitive Service for Language3. The problem with these services is that they do not offer automatic coding for languages other than English.
Data privacy concerns may arise from using this third-party software to extract patients’ information. Some healthcare providers may prohibit sending data to systems outside the primary source due to potential cybersecurity issues.

heading: 3 Data and Methods
text: The Chilean Waiting List is characteristic of the the public healthcare system. This list arises due to the high demand for medical care and the limited capacity of the public health system to meet it. Entry on the waiting list begins when a patient goes to primary care or secondary care physician to treat pathology. The patient has two possible paths: if the pathology is included in the “Garantías Explícitas en Salud” (GES) program, the patient enters a process where his or her health problem is assured a maximum waiting time for medical attention. If the GES program does not cover the pathology, the referral is classified in one of these five options: New Specialty Consultations (CNE), Follow-up Consultations (CCE), Diagnostic Procedures (Proc), Surgical Intervention (IQ) and Complex Surgical Intervention (IQC). In any of these alternatives, the patient is placed on a waiting list and must wait a variable amount of time to receive medical attention from a specialist.
The Chilean Waiting List comprises 25,374,491 referrals, divided into five categories: 18,716,629 correspond to CNE type referrals, 4,391,257 to Proc type referrals, 2,222,545 to IQ type referrals, 39,266 to CCE type referrals, and finally, 4,794 to IQC type referrals. In particular, this work will focus on CNE-type referrals.
Within the Chilean Waiting database, 73 attributes are separated into two main types of sets. The first set corresponds to the attributes associated with the person (date of birth, sex, national identifier). In contrast, the second set corresponds to the administrative information associated with the referral given to the person (date of admission, date of discharge, the benefit provided, specialty, diagnostic suspicion, and diagnostic confirmation).
2https://cloud.google.com/healthcare 3https://azure.microsoft.com/
en-in/products/cognitive-services/ language-service
For the analysis of the diagnoses present in the referrals, two free-text attributes representing medical diagnoses are considered: diagnostic suspicion and diagnostic confirmation. Table 1 shows the frequency of referrals according to medical specialty, while Table 2 shows corpus statistics of the texts analyzed.
We used 10,000 referrals from the historical Chilean Waiting List to train the NER module for disease recognition. As detailed in (Báez et al., 2020; Báez et al., 2022), these referrals were previously consolidated by a team of clinical experts, thus constituting the so-called Chilean Waiting list corpus. In addition, we performed rounds of evaluation of the NER performance, identifying diseases that the model could not identify. Thus, these diseases were incorporated as new examples of the model training process.

heading: 4 Proposed System
text: To code the narratives, we first used a NER model to automatically recognize sequences of words in the text associated with diseases. Then, each disease found is associated with its most likely ICD-10 code through a search engine. Figure 1 shows an overview of our proposed system.

heading: 4.1 NER Model
text: As shown in Figure 1, the input of our system is the referral written by the physician in an unstructured format. These texts are used as input for the automatic disease recognition model. In particular, this NER model is based on the work proposed in (Rojas et al., 2022a), where a simple but highly effective architecture for medical entity recogni-
tion is introduced. This model, named Multiple LSTM-CRF (MLC), is a deep neural network system composed of three main modules, emphasizing the impact of using domain-specific contextualized embeddings.
The first layer of the MLC approach, the “stacked embedding layer”, transforms the texts associated with the diagnoses into a vector representation using character-level contextual embeddings and static word embeddings, both trained in the clinical domain. Then, in the encoding layer, a recurrent neural network is used to obtain longdistance dependencies between words in the sentence, thus obtaining a better context to improve the previous layer’s representations. Finally, the classification layer assigns the most probable label to each word in the diagnosis using the CRF algorithm, identifying which parts of the text correspond to the beginning and end of a disease.
Regarding the experimental setup, the disease model was trained to 150 epochs using an SGD optimizer with mini-batches of size 32 and a learning rate of 0.1. As mentioned, to encode sentences, we used two types of representations; a 300-dimensional word embedding model trained on the Chilean Waiting List corpus4 and characterlevel contextualized embeddings retrieved from the Clinical Flair model (Rojas et al., 2022b). To implement the model and perform our experiments, we used the Flair framework, widely used by the NLP research community (Akbik et al., 2019).

heading: 4.2 Search Engine
text: The output of the NER step is a list containing all the diseases mentioned in the referral. This second module aims to assign an ICD-10 code to each disease found, which can be used later for clinical decisions or management. The assignment of the ICD-10 code is done through a search engine tool based on Elasticsearch5, an open-source search and analytics engine. This system can assign similarities between the mention of the disease and each of the codes of the ICD-10 tabular list.
Unlike the algorithms of distance comparison between words, this search engine has an index that contains each of the ICD-10 diseases represented through a series of synonymous sentences extracted from different sources of information, simulating
4https://zenodo.org/record/3924799 5Registered trademark of Elasticsearch B.V. Available at
https://www.elastic.co/elasticsearch/
in a better way the process followed by clinical experts to determine the code of a disease.
For example, in the index, the code “K02.2” contains the canonical code description “Caries of cementum” and multiple synonymous definitions, such as “Cement caries” and “Root caries”. This is important as disease mentions found in unstructured diagnoses are rarely equivalent to the exact definition.
The sources of information used for the extraction of synonymous disease definitions were as follows:
Tabular list of ICD-10 terminology: This is the
basis of the index, which tells us which codes we will assign to the disease mentions.
Alphabetical index of ICD-10 terminology: The guide for the manual assignment of codes to diseases and was obtained using the “web scraping” technique from the website of the Spanish Ministry of Health 6.
IRIS dictionary: It maps natural language sentences to an ICD-10 code. This dictionary was built from the mortality coding rounds con-
6https://eciemaps.mscbs.gob.es/ ecieMaps/browser/index_10_2008.html
ducted in the Chilean Department of Statistics and Health Information.
UMLS: Spanish definitions from multiple vocabularies were extracted from the metatresaurus database.
DEIS abbreviations: Manually constructed list of abbreviations and their expansions.

heading: 4.3 Experiments
text: In our experiments, we measure how well the predictions made by the model fit compared to the decisions made by clinical experts. In this way, a subset of the referrals described in Section 3 was selected to be manually coded by a team of two clinical coders. The manual annotation process and system validation steps are provided below.

heading: 4.3.1 Manual coding
text: The clinical experts carried out the annotation process using Excel software. For this purpose, a file containing a unique identifier for each referral, the associated diagnostic suspicion, and a blank column for the actual coding was provided to the coders. This way, the expert coders identified disease codes in 1,188 clinical narratives from the Chilean Waiting List for a new specialty.
It is important to mention that in this process, codes were identified at the referral level, not at the entity level; therefore, it is not possible to determine the performance of the NER model in this experiment. In future work, specialized software such as INCEpTION, could be used, as proposed in the work of (Báez et al., 2020). This software would make it possible to identify which parts of the text refer to diseases. On the other hand, only diseases were coded, but future research could extend it to new entity types, such as clinical procedures or clinical findings.

heading: 4.3.2 Metric
text: The Mean Average Precision (MAP) metric is used to evaluate the performance of our coding system. This metric is widely used in works that address the same automatic coding task. This metric is defined as follows:
AveP =
∑ (P (k) · rel(k))
number of relevant documents , (1)
where P(k) represents the precision at position k, and rel(k) is an indicator function equal to 1 if the
element in rank k is a relevant document and 0 otherwise.
The MAP is computed using the Python implementation of the TREC evaluation tool, trectools, by (Palotti et al., 2019), where an adaptation was applied, in which the coded diagnoses have to be ordered based on a ranking, which for this work is considered the order in which the mention was found and subsequently the code was assigned.

heading: 5 Results

heading: 5.1 Coding Performance
text: The ICD-10 consists of a solitary coded catalog composed of categories with three characters, each of which can be additionally subdivided into as many as ten subcategories of four characters.
We computed the MAP metric over the test set at the category (e.g. K02) and subcategory (e.g. K02.2) levels. We achieved a MAP of 0.83 for the category and 0.63 for the subcategory level.
To underline the difficulty of achieving outstanding results in coding, we analyzed the results obtained only by clinical experts. The expert coders achieved an agreement MAP of 0.75 for subcategory and 0.83 for category level. Several reasons, such as the subjectivity in clinical judgment, the complexity of coding guidelines, the evolving nature of medicine, the time pressure and workload, personal bias, and lack of standardization, could explain the low agreement score.

heading: 6 Error Analysis
text: To better understand the errors made by our coding system, we performed a granular analysis of the scores obtained among the different specialties in the corpus. Tables 3 and 4 show the top 14 best and
10 worst scores according to the specialties. We noted that in the top 14 best specialties the diagnostic suspicions registered in the referral were written straightforwardly and were specific diagnoses, such as “lipoma”, “caries”, and “nephrolithiasis”, avoiding other clinical information like comorbidity, medication intake, or some other medical history. Furthermore, it can be noted that half of these referrals are related to dental diagnosis.
On the other hand, the top 10 worst specialties share in common that most of the diagnoses are very unspecific, with the incorporation of nonmedical information such as the patient’s phone number, patient’s address, physician’s name, the specialty the patient is referred to and information about comorbidity. Besides, several referrals are without a diagnosis but with the text “unspecific consultation” or “other”.

heading: 7 Model Deployment and Use Cases
text: Due to internal regulations, we could not send patients’ data to third-party systems such as cloud providers or academic supercomputing clusters (Ministerio Secretaría Regional de la Presidencia, 1999). For this reason, we deployed the whole coding system on-premise on a bare metal machine with a GPU compute module (NVIDIA RTX A40007) to process the coding requests from the whole department efficiently.
The complete automatic coding system was deployed as a pair of microservices running inside containers to ease portability. One container hosts
7The compute module has 16 GB of GPU memory and 6.144 CUDA cores. More information at https://www.nvidia.com/en-us/ design-visualization/rtx-a4000/
the NER module and exposes an API as a web service listening to disease-mention detection requests. The other container consists of the recommended implementation of the Elasticsearch software, which also exposes its API as a web service listening to mention-coding requests.
To code the waiting list and schedule recurrent coding when new data arrives, we used the KNIME8 software, a visual-programming data mining platform. We chose this software because of its ease of use for non-expert developers. The workflow starts with the raw waiting list, which is first passed through the NER module to detect disease mentions, and then each mention is sent to the coding module to assign the most relevant code.
The automatic coding result from the workflow mentioned above is persisted on a table inside a database that stores each disease mention for each referral along with the predicted code from the system.

heading: 8 Conclusions
text: In this work, we created a nationwide system to improve the management of the Chilean public healthcare system. Specifically, we addressed the challenge of creating an automated system to code the diseases present in the Chilean Waiting List referrals. We developed and validated a model based on two steps: a NER model to recognize disease mentions and a search engine based on Elasticsearch to assign the codes to each disease. This mapping system was enriched with several terminology resources used in real life by manual coders to assign codes, thus partially simulating
8Registered trademark of KNIME GmbH. Available at https://www.knime.com/
the pipeline followed by these professionals when solving this task.
The system allowed us to assign codes to 18,716,629 referrals, thus demonstrating its efficiency and effectiveness. The performance obtained in our experiments was 0.83 according to the MAP score, which is close to the most advanced systems currently in the coding task. The model was deployed into production in the Department of Health Statistics and Information Systems of the Ministry of Health of Chile.
The use of this system could be an important support for the management of waiting lists. In addition, since 75% of the Chilean population is in the public healthcare system, the analysis of the new specialty consultations can be used for epidemiological studies, such as the one done on the incidence of psoriasis (Lecaros et al., 2021).

heading: Acknowledgements
text: This work was funded by ANID Chile: Basal Funds for Center of Excellence FB210005 (CMM); Millennium Science Initiative Program ICN17_002 (IMFD) and ICN2021_004 (iHealth), Fondecyt grant 11201250, and National Doctoral Scholarship 21220200. We also acknowledge Daily Piedra and Marcela Carmona for their work on annotating and coding the test dataset.

heading: Future Work
text: In future work, specialized software such as INCEpTION, could be used, as proposed in the work of (Báez et al. , 2020). This software would make it possible to identify which parts of the text refer to diseases. On the other hand, only diseases were coded, but future research could extend it to new entity types, such as clinical procedures or clinical findings