# Merging Ontologies and Data from Electronic Health Records
## 4 Description of Our Approach  
Given the complexity of a document in HL7 CDA format, a tool has been implemented that converts an HL7 CDA document from XML format into a JSON format. This innovative process allows for a more comfortable, easy-to-read clinical document, which can also be easily integrated in other medical software processing frameworks. In fact, thanks to its much more concise syntax and its well established semantics, JSON is nowadays often a preferred data format over XML. It is then easier to work with the new obtained JSON data representation in various ways. In this work, we propose to merge the obtained JSON data with additional knowledge extracted from related domain ontologies to offer a more complete and detailed document that is easier to read and understand due to the use of a more explicit and broader vocabulary. The end result is a clearer and more documented clinical picture of the patient, giving clinicians stronger support to make a diagnosis. The implemented approach consists of three phases, discussed in detail in the following. 1. Data acquisition: medical records in XML format are processed for conversion into JSON format. 2. Ontological mapping: the obtained JSON keywords are analysed and mapped to the corresponding semantic definitions found in related ontologies, where the meaningful keywords allowing the mapping are derived from a data cleaning and analysis subprocess. 3. Document enrichment: the semantic information is integrated with the JSON medical record to obtain a more informative document. To test the proposed approach, a real medical data repository was used, which was created and publicly shared by the HL7 organisation to allow the validation and benchmarking of medical applications with simulated but realistic clinical documents ([[https://github.com/HL7/C-CDA-Examples/tree/master](https://github.com/HL7/C-CDA-Examples/tree/master)]([https://github.com/HL7/C-CDA-Examples/tree/master](https://github.com/HL7/C-CDA-Examples/tree/master)), last accessed on 10 November 2023). The proposed document processing and integration approach has been implemented in a tool, entirely developed in the Java language. Below, a snippet of the main algorithm is shown which implements the high-level steps carried out during the processing. ClinicalDocument clinDocument = DocumentParser.buildClinicalDocument(xml); List<Keyword> jsonKeys = clinDocument.extractKeys(); List<Label> labelsList = OntologyManager.retrieveLabels(); List<Label> similarLabels = clinDocument.textSimilarity(jsonList, labelsList); List<OutLabelDetails> infoLabels; for (Label label: similarLabels){ infolabels.add(OntologyManager.retrieveData(label)); } clinDocument.dataUnion(jsonList,similarLabel,infoLabels); Classes and methods in the above code snippet are described in the following. * ClinicalDocument: a class representing a JSON object that has been built up by transforming an input CDA XML file. * DocumentParser: a class that deals finds and extract data from the XML in a CDA. * OntLabelDetails: a class holding data belonging to an ontology class, such as definition and synonyms. * buildClinicalDocument(): a method that reads the CDA XML and processes it. Given an id for the XML file as input, it calls all the methods for checking and reading the file according to its tree structure. The tree is read by starting from the root, looking for all the sections to export, which are found by means of the section tag. For each section tag found, the corresponding XML text is passed as input to appropriate methods and that will extract text data and encapsulate them in instances of appropriate Java classes. After reading all the tags, all the created instances are represented as an object of class ClinicalDocument, returned to the caller. * extractKeys(): a method that extract keywords from JSON objects. * retrieveLabels(): a method that extract labels from an ontology.