Metadata-Version: 2.4
Name: acmc
Version: 0.0.3
Summary: A Tool for Automating the Curation of Medical Concepts derived from Coding Lists
Project-URL: Repository, https://git.soton.ac.uk/meldb/concepts-processing
Project-URL: Documentation, https://git.soton.ac.uk/meldb/concepts-processing/docs
Project-URL: Issues, https://git.soton.ac.uk/meldb/concepts-processing/-/issues
Author-email: Jakub Dylag <j.j.dylag@soton.ac.uk>, Michael Boniface <m.j.boniface@soton.ac.uk>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright 2024 Jakub Dylag
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Requires-Python: >=3.9
Requires-Dist: aiosqlite
Requires-Dist: click
Requires-Dist: cramjam
Requires-Dist: et-xmlfile
Requires-Dist: fastparquet
Requires-Dist: fsspec
Requires-Dist: gitdb
Requires-Dist: gitpython
Requires-Dist: greenlet
Requires-Dist: iniconfig
Requires-Dist: lxml
Requires-Dist: numpy
Requires-Dist: openpyxl
Requires-Dist: pandas-stubs
Requires-Dist: pluggy
Requires-Dist: pyarrow
Requires-Dist: pyomop
Requires-Dist: pytest
Requires-Dist: pyyaml
Requires-Dist: requests
Requires-Dist: simpledbf
Requires-Dist: smmap
Requires-Dist: sqlalchemy
Requires-Dist: tables
Requires-Dist: types-pyyaml
Requires-Dist: types-requests
Description-Content-Type: text/markdown

# A Tool for Automating the Curation of Medical Concepts derived from Coding Lists (ACMC)

### Jakub J. Dylag 1, Roberta Chiovoloni 3, Ashley Akbari 3, Simon D. Fraser 2, Michael J. Boniface 1

1 Digital Health and Biomedical Engineering, School of Electronics and Computer Science, Faculty of Engineering and Physical Sciences, University of Southampton
2 School of Primary Care Population Sciences and Medical Education, University of Southampton 
3 Population Data Science, Swansea University Medical School, Faculty of Medicine, Health & Life Science, Swansea University 

*Correspondence to: Jakub J. Dylag, Digital Health and Biomedical Engineering, School of Electronics and Computer Science, Faculty of Engineering and Physical Sciences, University of Southampton, J.J.Dylag@soton.ac.uk*

### Citation
> Dylag JJ, Chiovoloni R, Akbari A, Fraser SD, Boniface MJ. A Tool for Automating the Curation of Medical Concepts derived from Coding Lists. GitLab [Internet]. May 2024. Available from: https://git.soton.ac.uk/meldb/concepts-processing

## Introduction

This tool automates the verification, translation and organisation of medical coding lists defining  phenotypes for inclusion criteria in cohort analysis. By processing externally sourced clinical inclusion criteria into actionable code lists, this tool ensures consistent and efficient curation of cohort definitions. These code lists can be subsequently used by data providers to construct study cohorts.

## Requirements

- Python 3.9 or higher

## Installation

To install the `acmc` package, simply run:

```bash
pip install acmc
```

Once installed, you'll be ready to use the `acmc` tool along with the associated vocabularies.

## Getting Started

### Install Clinically Assured NHS TRUD Code Mappings

1. **Register at TRUD**

	Registry your account with TRUD  at [NHS TRUD](https://isd.digital.nhs.uk/trud/user/guest/group/0/account/form).

3. **Subscribe and Accept Licenses**: Subscribe to the following data files:

   - [NHS Read Browser](https://isd.digital.nhs.uk/trud/users/guest/filters/2/categories/9/items/8/releases)
   - [NHS Data Migration](https://isd.digital.nhs.uk/trud/users/guest/filters/0/categories/8/items/9/releases)
   - [ICD10 Edition 5 XML](https://isd.digital.nhs.uk/trud/users/guest/filters/0/categories/28/items/259/releases)
   - [OPCS-4.10 Data Files](https://isd.digital.nhs.uk/trud/users/guest/filters/0/categories/10/items/119/releases)

   After subscribing, you'll receive an API key once your request is approved (usually within a few hours).

4. **Get TRUD API KEY**

	Copy your API key from [NHS TRUD Account Management](https://isd.digital.nhs.uk/trud/users/authenticated/filters/0/account/manage) and store it securely.

7. **Add TRUD API KEY to as an environment variable**

	To set the environment variable temporarily (for the current session), run:

	On macOS/Linux:

   ```bash
   export ACMC_TRUD_API_KEY="your_api_key_here"
   ```

   On Windows (Command Prompt or PowerShell):

   ```bash
   setx ACMC_TRUD_API_KEY "your_api_key_here"
   ```

4. **Download and Install TRUD Resources**:

	Run the following `acmc` command to download and process the TRUD resources:

   ```bash
   acmc trud install
   ```

### Install OMOP Vocabularies 

1. **Register with [OHDSI Athena](https://athena.ohdsi.org/auth/login)**

2. **Download vocabularies from [OHDSI Athena](https://athena.ohdsi.org/vocabulary/list)**

	* Required vocabularies include:
	  * 1) SNOMED
	  * 2) ICD9CM
	  * 17) Readv2
	  * 21) ATC
	  * 55) OPCS4
	  * 57) HES Specialty
	  * 70) ICD10CM
	  * 75) dm+d
	  * 144) UK Biobank
	  * 154) NHS Ethnic Category
	  * 155) NHS Place of Service

	You will be notified by email (usually within an hour) with a vocabularies version number and link to download a zip file of OMOP database tables in CSV format. The subject will be `OHDSI Standardized Vocabularies. Your download link` from `pallas@ohdsi.org`

```
Content of your package

Vocabularies release version: v20240830
acmc-omop Vocabularies:
SNOMED	-	Systematic Nomenclature of Medicine - Clinical Terms (IHTSDO)
ICD9CM	-	International Classification of Diseases, Ninth Revision, Clinical Modification, Volume 1 and 2 (NCHS)
Read	-	NHS UK Read Codes Version 2 (HSCIC)
ATC	-	WHO Anatomic Therapeutic Chemical Classification
OPCS4	-	OPCS Classification of Interventions and Procedures version 4 (NHS)
HES Specialty	-	Hospital Episode Statistics Specialty (NHS)
ICD10CM	-	International Classification of Diseases, Tenth Revision, Clinical Modification (NCHS)
dm+d	-	Dictionary of Medicines and Devices (NHS)
UK Biobank	-	UK Biobank (UK Biobank)
NHS Ethnic Category	-	NHS Ethnic Category
NHS Place of Service	-	NHS Admission Source and Discharge Destination
Installation of the OHDSI Standardized Vocabularies

Please execute the following process:

    Click on this link to download the zip file. Typical file sizes, depending on the number of vocabularies selected, are between 30 and 1500 MB.
    Unpack.
    Reconstitute CPT-4. See below for details.
    If needed, create the tables.
    Load the unpacked files into the tables.
```

Download the OMOP file onto your computer and note the path to the file

4. **Install OMOP vocabularies**

	Run the following `acmc` command to create a local OMOP database from the OMOP zip file with a specific version:

	```bash
	acmc omop install -f <path to downloaded OMOP zip file> -v <release version from email>
	```
Expected output:

```bash
[INFO] - Installing OMOP from zip file: ../data/acmc-omop.zip
[INFO] - Extracted OMOP zip file ../data/acmc-omop.zip to vocab/omop/
[INFO] - Processing 1 of 9 tables: vocab/omop/CONCEPT.csv
[INFO] - Processing 2 of 9 tables: vocab/omop/DOMAIN.csv
[INFO] - Processing 3 of 9 tables: vocab/omop/CONCEPT_CLASS.csv
[INFO] - Processing 4 of 9 tables: vocab/omop/RELATIONSHIP.csv
[INFO] - Processing 5 of 9 tables: vocab/omop/DRUG_STRENGTH.csv
[INFO] - Processing 6 of 9 tables: vocab/omop/VOCABULARY.csv
[INFO] - Processing 7 of 9 tables: vocab/omop/CONCEPT_SYNONYM.csv
[INFO] - Processing 8 of 9 tables: vocab/omop/CONCEPT_ANCESTOR.csv
[INFO] - Processing 9 of 9 tables: vocab/omop/CONCEPT_RELATIONSHIP.csv
[INFO] - OMOP installation completed
```

## **Example Usage**

Follow these steps to initialize and manage a phenotype using `acmc`. In this example, we use a source concept list for the Concept Set `Abdominal Pain` created from [ClinicalCodes.org](ClinicalCodes.org). The source concept codes are read2. We genereate versioned phenotypes for read2 and translate to snomed in normalised, standard formats. 

1. **Initialize a phenotype in the workspace**

	Use the followijng `acmc` command to initialize the phenotype in a local Git repository:

```bash
acmc phen init
```

Expected Output:

```bash
[INFO] - Initialising Phenotype in directory: <path>/concepts-processing/workspace/phen
[INFO] - Creating phen directory structure and config files
[INFO] - Phenotype initialised successfully
```

2. **Copy example medical code lists to the phenotype codes directory**

	From the command prompt, copy medical code lists `/examples/codes`to the phenotype code directory:

```bash
cp -r ./examples/codes/* ./workspace/phen/codes
```

   - You can view the source code list here [`res176-abdominal-pain.csv`](.//examples/codes/clinical-codes-org/Symptom%20code%20lists/Abdominal%20pain/res176-abdominal-pain.csv)
   - Alternatively, place your code lists in `./workspace/phen/codes`.

3. **Copy the example phenotype configuration file to the phenotype directory**

	From the command prompt, copy example phenotype configuration files `/examples/config.json` to the phenotype directory:

```bash
cp -r ./examples/config1.yaml ./workspace/phen/config.yaml
```

   - You can view the configuarion file here [`config.json`](./examples/config.json) 
   - Alternatively, place your own `config.json` file in `./workspace/phen`.
     
4. **Validate the phenotype configuration**

	Use the followijng `acmc` command to validate the phenotype configuration to ensure it's correct:

```bash
acmc phen validate
```

Expected Output:

```bash
[INFO] - Validating phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
```

5. **Generate phenotype in Read2 code format**

	Use the following `acmc` command to generate the phenotype in `read2` format:

```bash
acmc phen map -t read2
```

Expected Output:

```bash
[INFO] - Processing phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Validating phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - Processing read2 codes...
[INFO] - Converting to target code type read2
[INFO] - Saved mapped concepts to <path>/concepts-processing/workspace/phen/map/read2.csv
[INFO] - Phenotype processed successfully
```

The concept sets translating read2 to the acmc normalised CSV format will be stored in `./workspace/phen/concept-set/snomed/` in, e.g. `./workspace/phen/concept-set/read2/ABDO_PAIN.csv`.

6. **Publish phenotype at an initial version**

	Use the following `acmc` command to publish the phenotype at an initial version:

```bash
acmc phen publish
```

Expected Output:

```bash
[INFO] - Validating phenotype: /home/mjbonifa/datahdd/brcbat/derived_datasets/mjbonifa/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - New version: v1.0.3
[INFO] - Phenotype published successfully
```

7. **Generate phenotype in SNOWMED code format**

Generate the phenotype in `snomed` format:

```bash
acmc phen map -t snomed
```

Expected Output:

```bash
[INFO] - Processing phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Validating phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - Processing read2 codes...
[INFO] - Converting to target code type snomed
[INFO] - Saved mapped concepts to <path>/concepts-processing/workspace/phen/map/snomed.csv
[INFO] - Phenotype processed successfully
```

The concept sets translating read2 to snomed will be stored in acmc CSV format in `./workspace/phen/concept-set/snomed/`, e.g. `./workspace/phen/concept-set/snomed/ABDO_PAIN.csv`

8. **Get a copy of the previous version from the repo**

	Use the following `acmc` command to retrieve a copy of the previous version (`v1.0.3`) from the repository:

```bash
acmc phen copy -v v1.0.3
```

Expected Output:

```bash
[INFO] - Validating phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - Copying repo <path>/concepts-processing/workspace/phen to <path>/concepts-processing/workspace/v1.0.3
[INFO] - Checking out version v1.0.3...
[INFO] - Phenotype copied successfully
```

A copy of the phenotype will be created in the directory `./workspace/v1.0.3`

9. **Compare the previous version `v1.0.3` with the latest version**

	Use the following `acmc` command to compare the previous version `v1.0.3` with the latest version in the repository:

```bash
acmc phen diff -old ./workspace/v1.0.3/
```

Expected Output:

```bash
[INFO] - Validating phenotype: ./workspace/v1.0.3/
[INFO] - Phenotype validated successfully
[INFO] - Validating phenotype: <path>/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - Phenotypes diff'd successfully
```

A report comparing the phenotype versions will be created in the workspace called './workspace/phen/v1.0.3_diff.md'

10. **Publish the phenotype at the next version**

	Use the following `acmc` command to publish the phenotype at the next version:

```bash
acmc phen publish
```

Expected Output:

```bash
[INFO] - Validating phenotype: /home/mjbonifa/datahdd/brcbat/derived_datasets/mjbonifa/concepts-processing/workspace/phen
[INFO] - Phenotype validated successfully
[INFO] - New version: v1.0.4
[INFO] - Phenotype published successfully
```

## Support

If you need help please open an [issue in the repository](https://git.soton.ac.uk/meldb/concepts-processing/-/issues)

## Contributing

Please contacted the corresponding author Jakub Dylag at J.J.Dylag@soton.ac.uk.

## Acknowledgements  

This project was developed in the context of the [MELD-B](https://www.southampton.ac.uk/publicpolicy/support-for-policymakers/policy-projects/Current%20projects/meld-b.page) project, which is funded by the UK [National Institute of Health Research](https://www.nihr.ac.uk/) under grant agreement NIHR203988.

## License

This work is licensed under a [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).

![apache2](https://img.shields.io/github/license/saltstack/salt)
