# Merging Ontologies and Data from Electronic Health Records
## 4 Description of Our Approach
### Data Acquisition
This is a heuristic that was introduced, as more words would likely indicate a very specific issue that would be unlikely to be found within an ontology. * Ontology filtering: the selected ontology is processed to extract a list of useful terms that could be related to the patient's medical record. This is achieved by parsing the ontology with the supporting library Jena ([[https://jena.apache.org](https://jena.apache.org)]([https://jena.apache.org](https://jena.apache.org)), last accessed on 10 November 2023), which converts all its semantic concepts into corresponding class objects whose names can then be easily combined with the data of the patient's clinical document. ```
1{
2\"title\":\"Patient Chart Summary\",
3\"date\":201308151030-0800\",
4\"patient\":{
5\"id\":\"#444222222\",
6\"name\":\"Free\",
7\"last_name\":\"Betterhalf\",
8\"gender\":\"female\",
9\"maritalStatus\":\"married\",
10\"birthTime\":\"19750501\",
111\"religious\":\"Christian (non-Catholic, non-specific)\"
12},
13\"allergiesSection\":{
14\"title\":\"Allergies, Adverse Reactions and Alerts\",
15\"date\":20140104123506-0800\",
16\"allergies\":[
17{
18\"allergen\":\"penicillin\",
19\"type\":\"drug allergy\",
20\"documentation_date\":\"Jan 4 2014\",
21\"reactions\":[The following code snippet shows the ontology filtering process in detail. ```
/**ExtrapolatingclassnamessupportedbytheApacheJenablecurrent**/ privateList<String>extrapolationByOntology(){ OntModelmodel=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); model.read(ontologyPath); listLabel=model.listClasses().toList().stream().filter(s->s.getURI()!=null&&s.getLabel(null)!=null).map(s->s.getLabel(null)).toList() returnlistLabel; }
```
The last step implementing the ontological matching is the search for correspondences between the clinical keywords data obtained from the clinical document and the available ontology classes. This, in fact, allows us to later build an enriched representation of the patient's EHR, where the set of additional related data is bound to the JSON converted clinical document. To correctly find the semantic relationships between the ontology concepts and the clinical data terms we used a well-known natural language processing (NLP) technique: we applied a filtering layer based on the Jaccard distance, which is widely adopted as an effective criteria to compute the similarity between two sets of words with the aim of revealing their association. This step is performed as shown in detail in the following code snippet:
```
/**CalculatesthesimilaritybetweentextusingtheJaccardDistanceclassbelongingto thepackageorg.apache.comoms.text.similarity**/ privateListLabel>textsimilarity(List<Keyword>jsons,List<String>labels){ List<Label>toReturn=newArrayList<Label>(); for(Keywordobj:jsons){ Stringkeys=obj.toString(); for(Stringstr:labels){ doublejaccardResult=jaccardDistance.apply(keys,str); if(jaccardResult>=0.7){ toReturn.add(newLabel(Keys,str,jaccardResult)); }}} returntoReturn; }
```

### Document Enrichment

The final stage consists of the actual building of a single manageable document that can be viewed by doctors, aggregating the enhanced clinical data and the additional semantic information obtained into a single JSON file. This will thus contain added notes to the original medical data, i.e., detailed explanations of the diseases or synonyms or opposites of them. The following section discusses the result of the enrichment for real sample data, and gives a graphical representation of data resulting from the merging between clinical data and an ontology. ## 5 Validation

In order to validate the proposed approach, we processed a set of CDA documents extracted from the HL7 official public test data repository as an overall functional test case. Specifically, we processed a set of HL7 files simulating the medical story of the imaginary patient \"[PERSON]\". Each file represents a report of one of her visits performed by a clinical specialist. The considered patient's fascicle totalled 35 CDA files, the union of which constituted her EHR.