Skip to content

Commit

Permalink
Updated the EFI codesets to include SNOMED (#193)
Browse files Browse the repository at this point in the history
* Added SNOMED codes to EFI code sets

* Reduced file size of terminolgy mapping file
  • Loading branch information
rw251 committed Mar 7, 2024
1 parent 6e4a085 commit 991e930
Show file tree
Hide file tree
Showing 38 changed files with 1,080,894 additions and 0 deletions.
95 changes: 95 additions & 0 deletions scripts/efi-mapping.js
@@ -0,0 +1,95 @@
// This is a one-off script to generate SNOMED lists for all the EFI code sets
//
// EFI currently only has Readv2 and CTV3 code sets. This is what is implemented
// in any system that calculates EFI. In order to be consistent with what exists
// in GP practices, we keep the Readv2 and CTV3 codes and do not attempt to
// validate them. However, now that all codes in the database are SNOMED, we need
// a way to generate the equivalent SNOMED code sets. Therefore we use the NHS
// mapping from Read and CTV to SNOMED. This script is therefore a one off process
// to create those files, but is retained here for transparency, and also in case
// a similar script is needed in future.

// Get all efi scripts
const fs = require('fs');
const { join } = require('path');

console.log('Loading lookup files...');
const ctv3ToSNOMED = {};
fs.readFileSync(
join(__dirname, '..', 'shared', 'terminology-mapping', 'ctv3sctmap2_uk_20200401000001.txt'),
'utf8'
)
.split('\n')
.slice(1)
.map((x) => {
const [mapId, code, termId, termType, conceptId] = x.split('\t');
if (conceptId === '_DRUG') return;
if (!ctv3ToSNOMED[code]) ctv3ToSNOMED[code] = [conceptId];
else ctv3ToSNOMED[code].push(conceptId);
});
const readv2ToSNOMED = {};
fs.readFileSync(
join(__dirname, '..', 'shared', 'terminology-mapping', 'rcsctmap2_uk_20200401000001.txt'),
'utf8'
)
.split('\n')
.slice(1)
.map((x) => {
const [mapId, code, termId, conceptId] = x.split('\t');
if (!readv2ToSNOMED[code]) readv2ToSNOMED[code] = [conceptId];
else readv2ToSNOMED[code].push(conceptId);
});
const SNOMED_DEFINITIONS = JSON.parse(
fs.readFileSync(
join(__dirname, '..', '..', 'nhs-snomed', 'files', 'processed', 'latest', 'defs-single.json'),
'utf8'
)
);

console.log('Processing EFI files...');
const CODE_SET_DIR = join(__dirname, '..', 'shared', 'clinical-code-sets');
fs.readdirSync(CODE_SET_DIR).forEach((dir) => {
fs.readdirSync(join(CODE_SET_DIR, dir)).forEach((condition) => {
if (condition.indexOf('efi') === 0) {
const snomedCodes = {};
fs.readFileSync(join(CODE_SET_DIR, dir, condition, '1', `${condition}.ctv3.txt`), 'utf8')
.split('\n')
.map((x) => {
if (x.trim().length < 3) return;
const [code] = x.trim().split('\t');
if (!ctv3ToSNOMED[code]) {
console.log(`No mapping for ctv3 code ${code} in ${condition}`);
} else {
ctv3ToSNOMED[code].forEach((conceptId) => {
snomedCodes[conceptId] = true;
});
}
});
fs.readFileSync(join(CODE_SET_DIR, dir, condition, '1', `${condition}.readv2.txt`), 'utf8')
.split('\n')
.map((x) => {
if (x.trim().length < 3) return;
const [code] = x.trim().split('\t');
if (!readv2ToSNOMED[code]) {
console.log(`No mapping for readv2 code ${code} in ${condition}`);
} else {
readv2ToSNOMED[code].forEach((conceptId) => {
snomedCodes[conceptId] = true;
});
}
});
fs.writeFileSync(
join(CODE_SET_DIR, dir, condition, '1', `${condition}.snomed.txt`),
Object.keys(snomedCodes)
.map((x) => {
if (!SNOMED_DEFINITIONS[x]) {
console.log(`No defintion for ${x}`);
process.exit();
}
return `${x}\t${SNOMED_DEFINITIONS[x]}`;
})
.join('\n')
);
}
});
});
@@ -0,0 +1,83 @@
3723001 Arthritis (disorder)
8847002 Spondylosis (disorder)
9631008 Ankylosing spondylitis (disorder)
19063003 Arthroplasty of knee (procedure)
22193007 Degenerative joint disease of hand (disorder)
27813003 Intra-articular injection (procedure)
33952002 Localized osteoarthrosis (disorder)
35885006 Hyperuricemia (disorder)
37895003 Osteoarthrosis of the carpometacarpal joint of the thumb (disorder)
48440001 Arthritis due to gout (disorder)
67315001 Degenerative joint disease of shoulder region (disorder)
68449006 Coxitis (disorder)
69896004 Rheumatoid arthritis (disorder)
90560007 Inflammatory disorder due to increased blood urate level (disorder)
161567008 History of rheumatoid arthritis (situation)
161568003 History of osteoarthritis (situation)
168662003 Plain X-ray hip joint abnormal (finding)
168668004 Plain X-ray knee abnormal (finding)
179342005 Knee joint operation (procedure)
179343000 Cemented knee arthroplasty (& total (& named variants)) (procedure)
190828008 Gouty arthropathy (disorder)
201727001 Arthropathy in ulcerative colitis (disorder)
201764007 Rheumatoid arthritis of cervical spine (disorder)
201766009 Rheumatoid arthritis of shoulder (disorder)
201768005 Rheumatoid arthritis of acromioclavicular joint (disorder)
201769002 Rheumatoid arthritis of elbow (disorder)
201771002 Rheumatoid arthritis of wrist (disorder)
201772009 Rheumatoid arthritis of metacarpophalangeal joint (disorder)
201773004 Rheumatoid arthritis of proximal interphalangeal joint of finger (disorder)
201774005 Rheumatoid arthritis of distal interphalangeal joint of finger (disorder)
201775006 Rheumatoid arthritis of hip (disorder)
201776007 Rheumatoid arthritis of sacroiliac joint (disorder)
201777003 Rheumatoid arthritis of knee (disorder)
201779000 Rheumatoid arthritis of ankle (disorder)
201780002 Rheumatoid arthritis of subtalar joint (disorder)
201781003 Rheumatoid arthritis of talonavicular joint (disorder)
201783000 Rheumatoid arthritis of first metatarsophalangeal joint (disorder)
201784006 Rheumatoid arthritis of lesser metatarsophalangeal joint (disorder)
201785007 Rheumatoid arthritis of interphalangeal joint of toe (disorder)
201791009 Flare of rheumatoid arthritis (disorder)
201818008 Osteoarthritis (& [allied disorders])
201819000 Generalized osteoarthritis (disorder)
201826000 Erosive osteoarthrosis (disorder)
201893003 Osteoarthritis NOS: [lower leg] or [knee] (disorder)
202655008 (Spondylosis and allied disorders) or (arthritis of spine) or (osteoarthritis of spine)
239791005 Seropositive rheumatoid arthritis (disorder)
239792003 Seronegative rheumatoid arthritis (disorder)
239793008 Rheumatoid arthritis with organ / system involvement (disorder)
239795001 Rheumatoid arthritis with multisystem involvement (disorder)
239862000 Idiopathic osteoarthritis (disorder)
239868001 Osteoarthritis of finger joint (disorder)
239872002 Osteoarthritis of hip (disorder)
239873007 Osteoarthritis of knee (disorder)
239881008 Otto's pelvis (disorder)
265170009 Total prosthetic replacement of knee joint using cement (procedure)
267004000 History of musculoskeletal disease (situation)
267891004 Localized osteoarthritis, unspecified, of the pelvic region and thigh (disorder)
267969005 Spondylosis and allied disorders (disorder)
268524007 Rheumatology disorder monitoring (regime/therapy)
274135002 Arthritis/arthrosis (disorder)
275554004 History of arthritis (situation)
275902004 Rheumatoid arthritis monitoring (regime/therapy)
275920008 Arthritis monitoring (regime/therapy)
287006005 Rheumatoid arthritis of multiple joints (disorder)
287007001 Rheumatoid arthritis of hand joint (disorder)
287008006 Rheumatoid arthritis of ankle and/or foot (disorder)
301877006 Injection of steroid into knee joint (procedure)
307817008 Arthroplasty of knee using cement (procedure)
308143008 Seropositive erosive rheumatoid arthritis (disorder)
371081002 Arthritis of knee (disorder)
396275006 Osteoarthritis (disorder)
399269003 Arthropathy (disorder)
416956002 Undifferentiated inflammatory polyarthritis (disorder)
417373000 Inflammatory polyarthropathy (disorder)
429192004 Rheumatoid arthritis of foot (disorder)
430698003 Replacement of total knee joint (procedure)
443349002 Disease activity score in rheumatoid arthritis (assessment scale)
445478004 Degenerative joint disease of pelvis (disorder)
450521003 Osteoarthritis of patellofemoral joint (disorder)
414821000000101 [X]Seropositive rheumatoid arthritis, unspecified (disorder)
408751000000108 [X]Other seropositive rheumatoid arthritis (disorder)
425481000000106 [X]Other specified rheumatoid arthritis (disorder)
425091000000101 [X]Rheumatoid arthritis with involvement of other organs or systems (disorder)
@@ -0,0 +1,21 @@
5370000 Atrial flutter (disorder)
49436004 Atrial fibrillation (disorder)
134377004 Atrial fibrillation monitoring (regime/therapy)
163000006 On examination - pulse irregularly irregular (finding)
164889003 Electrocardiographic atrial fibrillation (finding)
164890007 Electrocardiographic atrial flutter (finding)
175146007 Implantation of intravenous pacemaker for atrial fibrillation (procedure)
195080001 Atrial fibrillation and flutter (disorder)
233910005 Lone atrial fibrillation (disorder)
233911009 Non-rheumatic atrial fibrillation (disorder)
266306001 (Atrial fibrillation) or (atrial flutter) (disorder)
282825002 Paroxysmal atrial fibrillation (disorder)
300996004 Controlled atrial fibrillation (disorder)
312442005 History of atrial fibrillation (situation)
314208002 Rapid atrial fibrillation (disorder)
440028005 Permanent atrial fibrillation (disorder)
440059007 Persistent atrial fibrillation (disorder)
248411000000105 Atrial fibrillation annual review (regime/therapy)
716981000000106 Atrial fibrillation monitoring second letter (procedure)
715941000000109 Excepted from atrial fibrillation quality indicators - patient unsuitable (finding)
717381000000109 Excepted from atrial fibrillation quality indicators - informed dissent (finding)
64 changes: 64 additions & 0 deletions shared/clinical-code-sets/conditions/efi-chd/1/efi-chd.snomed.txt
@@ -0,0 +1,64 @@
1755008 Old myocardial infarction (disorder)
3546002 Aortocoronary artery bypass graft with saphenous vein graft (procedure)
4557003 Preinfarction syndrome (disorder)
11101003 Percutaneous transluminal coronary angioplasty (procedure)
22298006 Myocardial infarction (disorder)
23687008 Coronary artery spasm (disorder)
25106000 Impending infarction (disorder)
31413008 Operative procedure on coronary artery (procedure)
36969009 Placement of stent in coronary artery (procedure)
46109009 Subendocardial ischemia (disorder)
53741008 Coronary arteriosclerosis (disorder)
57054005 Acute myocardial infarction (disorder)
59021001 Angina decubitus (disorder)
59139008 Crushing chest pain (finding)
67682002 Coronary artery atheroma (disorder)
73795002 Acute myocardial infarction of inferior wall (disorder)
102594003 Electrocardiogram abnormal (finding)
161499004 H/O: cardiovascular disease (& [heart disorder] or [myocardial problem]) (situation)
161503005 History of myocardial infarct at age greater than sixty (situation)
161504004 History of angina pectoris (situation)
164861001 Electrocardiographic myocardial ischemia (finding)
170594001 Angina control - good (finding)
170595000 Angina control - poor (finding)
170597008 Angina control - worsening (finding)
175006004 Coronary artery operations (& bypass) (procedure)
194795001 Ischaemic heart disease (& [arteriosclerotic]) (disorder)
194796000 (Myocardial infarction (& [acute] or [silent] or [cardiac rupture following])) or (coronary thrombosis) (disorder)
194828000 Angina (disorder)
194841001 Coronary (atherosclerosis or artery disease) or triple vessel disease of the heart (disorder)
194861007 Certain current complications following acute myocardial infarction (disorder)
194863005 Atrial septal defect due to and following acute myocardial infarction (disorder)
225566008 Ischemic chest pain (finding)
232717009 Coronary artery bypass grafting (procedure)
233817007 Triple vessel disease of the heart (disorder)
233819005 Stable angina (disorder)
233823002 Silent myocardial ischemia (disorder)
233843008 Silent myocardial infarction (disorder)
233845001 Cardiac syndrome X (finding)
233846000 Post-infarction ventricular septal defect (disorder)
233847009 Cardiac rupture due to and following acute myocardial infarction (disorder)
266288001 Myocardial infarction (& [acute]) or coronary thrombosis (disorder)
266995000 History of cardiovascular disease (situation)
275544003 History of heart disorder (situation)
275905002 History of myocardial problem (situation)
279019008 Central crushing chest pain (finding)
300995000 Exercise-induced angina (disorder)
315026000 Transient myocardial ischemia (disorder)
315287002 Diabetes mellitus insulin-glucose infusion in acute myocardial infarction (procedure)
315614006 Coronary heart disease annual review (procedure)
371068009 Myocardial infarction with complication (disorder)
390799004 Coronary heart disease review (procedure)
398274000 Coronary artery thrombosis (disorder)
399211009 History of myocardial infarction (situation)
401314000 Acute non-ST segment elevation myocardial infarction (disorder)
413838009 Chronic ischemic heart disease (disorder)
413844008 Chronic myocardial ischemia (disorder)
414024009 Disorder of coronary artery (disorder)
414545008 Ischemic heart disease (disorder)
414795007 Myocardial ischemia (disorder)
443502000 Atherosclerosis of coronary artery (disorder)
699245006 Emergency hospital admission for ischemic heart disease (procedure)
471531000000105 [X]Other forms of angina pectoris (disorder)
302881000000102 Cardiovascular disease annual review declined (situation)
320351000000105 Admit ischaemic heart disease emergency (procedure)
43 changes: 43 additions & 0 deletions shared/clinical-code-sets/conditions/efi-ckd/1/efi-ckd.snomed.txt
@@ -0,0 +1,43 @@
29738008 Proteinuria (finding)
46177005 End-stage renal disease (disorder)
73211009 Diabetes mellitus (disorder)
90688005 Chronic renal failure syndrome (disorder)
127013003 Disorder of kidney due to diabetes mellitus (disorder)
167278006 Urine protein test = ++++ (finding)
190388001 Multiple complications due to type 2 diabetes mellitus (disorder)
197654000 Renal failure: [chronic] or [end stage] (disorder)
204962002 Multicystic kidney (disorder)
236425005 Chronic renal impairment (disorder)
236499007 Microalbuminuric nephropathy due to diabetes mellitus (disorder)
236500003 Proteinuric nephropathy due to diabetes mellitus (disorder)
401110002 Type 1 diabetes mellitus with persistent microalbuminuria (disorder)
420279001 Renal disorder due to type 2 diabetes mellitus (disorder)
420514000 Persistent proteinuria due to type 1 diabetes mellitus (disorder)
420715001 Persistent microalbuminuria due to type 2 diabetes mellitus (disorder)
421893009 Renal disorder due to type 1 diabetes mellitus (disorder)
421986006 Persistent proteinuria due to type 2 diabetes mellitus (disorder)
431857002 Chronic kidney disease stage 4 (disorder)
433144002 Chronic kidney disease stage 3 (disorder)
433146000 Chronic kidney disease stage 5 (disorder)
472953006 History of chronic renal impairment (situation)
700378005 Chronic kidney disease stage 3A (disorder)
700379002 Chronic kidney disease stage 3B (disorder)
709044004 Chronic kidney disease (disorder)
737562008 Multicystic renal dysplasia (disorder)
397201000000107 [X]Unspecified diabetes mellitus with renal complications (disorder)
309861000000100 Chronic kidney disease stage 3A (disorder)
309871000000107 Chronic kidney disease stage 3B (disorder)
324251000000105 Chronic kidney disease stage 3 with proteinuria (disorder)
324281000000104 Chronic kidney disease stage 3 without proteinuria (disorder)
324311000000101 Chronic kidney disease stage 3A with proteinuria (disorder)
324341000000100 Chronic kidney disease stage 3A without proteinuria (disorder)
324371000000106 Chronic kidney disease stage 3B with proteinuria (disorder)
324411000000105 Chronic kidney disease stage 3B without proteinuria (disorder)
324441000000106 Chronic kidney disease stage 4 with proteinuria (disorder)
324471000000100 Chronic kidney disease stage 4 without proteinuria (disorder)
324501000000107 Chronic kidney disease stage 5 with proteinuria (disorder)
324541000000105 Chronic kidney disease stage 5 without proteinuria (disorder)
499931000000106 [D]Proteinuria (situation)
249171000000102 Chronic kidney disease annual review (regime/therapy)
716891000000102 Excepted from chronic kidney disease quality indicators - patient unsuitable (finding)
716881000000104 Excepted from chronic kidney disease quality indicators - informed dissent (finding)

0 comments on commit 991e930

Please sign in to comment.