From 2fbfb234b08783a4c800751a543484635c429a6b Mon Sep 17 00:00:00 2001
From: Evans Girard <54366437+evans-g-crsj@users.noreply.github.com>
Date: Tue, 6 Aug 2024 14:18:57 -0400
Subject: [PATCH] :wrench: Update admin scripts to unify projects (#182)

---
 ...fInclude.json => arrangerProjectConf.json} |   0
 admin/checkConf.mjs                           |  13 -
 admin/confKfNext.json                         | 449 ------------------
 admin/findClinicalIndicesUsage.mjs            |  18 +-
 admin/mockStudies.mjs                         |  32 +-
 admin/poorsManEsMappingsInpector.mjs          |   2 +-
 admin/postReleaseIndicesToAliasesHelper.mjs   |   4 +-
 admin/projectConfig.mjs                       |  10 +
 admin/projectsConfig.mjs                      |  17 -
 admin/run.mjs                                 |  71 +--
 admin/sortConf.mjs                            |  20 +-
 11 files changed, 51 insertions(+), 585 deletions(-)
 rename admin/{confInclude.json => arrangerProjectConf.json} (100%)
 delete mode 100644 admin/checkConf.mjs
 delete mode 100644 admin/confKfNext.json
 create mode 100644 admin/projectConfig.mjs
 delete mode 100644 admin/projectsConfig.mjs

diff --git a/admin/confInclude.json b/admin/arrangerProjectConf.json
similarity index 100%
rename from admin/confInclude.json
rename to admin/arrangerProjectConf.json
diff --git a/admin/checkConf.mjs b/admin/checkConf.mjs
deleted file mode 100644
index 5e8dbc0..0000000
--- a/admin/checkConf.mjs
+++ /dev/null
@@ -1,13 +0,0 @@
-import includeConf from './confInclude.json' assert { type: "json" };
-import kfConf from './confKfNext.json' assert { type: "json" };
-
-const kfs = kfConf.extendedMappingMutations.map(m => [m.field, m.graphqlField]);
-const incs = includeConf.extendedMappingMutations.map(m => [m.field, m.graphqlField]);
-
-console.info('mutation in Kf only');
-const diffKfOnly = kfs.filter(kf => !incs.some(ins => kf[0] === ins[0] && kf[1] === ins[1])).map(x => ({ field: x[0], entity: x[1] }))
-diffKfOnly.length === 0 ? console.log('No diff') : console.table(diffKfOnly)
-
-console.info('mutation in Include only');
-const diffIncOnly = incs.filter(ins => !kfs.some(kf => kf[0] === ins[0] && kf[1] === ins[1])).map(x => ({ field: x[0], entity: x[1] }))
-diffIncOnly.length === 0 ? console.log('No diff') : console.table(diffIncOnly)
diff --git a/admin/confKfNext.json b/admin/confKfNext.json
deleted file mode 100644
index ec4d07d..0000000
--- a/admin/confKfNext.json
+++ /dev/null
@@ -1,449 +0,0 @@
-{
-  "indices": [
-    {
-      "graphqlField": "biospecimen",
-      "esIndex": "biospecimen_centric"
-    },
-    {
-      "graphqlField": "file",
-      "esIndex": "file_centric"
-    },
-    {
-      "graphqlField": "genes",
-      "esIndex": "gene_centric"
-    },
-    {
-      "graphqlField": "members",
-      "esIndex": "members-public"
-    },
-    {
-      "graphqlField": "participant",
-      "esIndex": "participant_centric"
-    },
-    {
-      "graphqlField": "study",
-      "esIndex": "study_centric"
-    },
-    {
-      "graphqlField": "variants",
-      "esIndex": "variant_centric"
-    }
-  ],
-  "extendedMappingMutations": [
-    {
-      "field": "diagnoses",
-      "graphqlField": "biospecimen",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "diagnoses.source_text_tumor_location",
-      "graphqlField": "biospecimen",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "acl",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "files",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "participants",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "participants.biospecimens",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "participants.biospecimens.diagnoses",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "participants.biospecimens.diagnoses.source_text_tumor_location",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "participants.down_syndrome_diagnosis",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "sequencing_experiment",
-      "graphqlField": "file",
-      "extendedFieldMappingInput": {
-        "isArray": true,
-        "type": "nested"
-      }
-    },
-    {
-      "field": "alias",
-      "graphqlField": "genes",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "interests",
-      "graphqlField": "members",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "roles",
-      "graphqlField": "members",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "searchableInterests",
-      "graphqlField": "members",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "down_syndrome_diagnosis",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "files.biospecimens.diagnoses",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "files.biospecimens.diagnoses.source_text_tumor_location",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "files.sequencing_experiment",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true,
-        "type": "nested"
-      }
-    },
-    {
-      "field": "mondo.parents",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "observed_phenotype.age_at_event_days",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "observed_phenotype.parents",
-      "graphqlField": "participant",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "contacts",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "controlled_access",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "data_category",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "data_sources",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "data_types",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset.access_limitations",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset.access_requirements",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset.data_types",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset.expected_data_categories",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "dataset.publications",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "domains",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "expected_data_categories",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "experimental_strategies",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "external_ids",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "institutions",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "investigator_names",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "part_lifespan_stages",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "publications",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "selection_criteria",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "study_designs",
-      "graphqlField": "study",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "clinvar.clin_sig",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "clinvar.conditions",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "clinvar.inheritance",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "clinvar.interpretations",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "gene_external_reference",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.alias",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.consequences.consequence",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.consequences.refseq_mrna_id",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.cosmic.tumour_types_germline",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.omim.inheritance",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.omim.inheritance_code",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.orphanet.inheritance",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "genes.spliceai.type",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "studies.participant_ids",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "studies.transmission",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    },
-    {
-      "field": "studies.zygosity",
-      "graphqlField": "variants",
-      "extendedFieldMappingInput": {
-        "isArray": true
-      }
-    }
-  ]
-}
\ No newline at end of file
diff --git a/admin/findClinicalIndicesUsage.mjs b/admin/findClinicalIndicesUsage.mjs
index 499ecbb..662178b 100644
--- a/admin/findClinicalIndicesUsage.mjs
+++ b/admin/findClinicalIndicesUsage.mjs
@@ -40,21 +40,27 @@ const makeReleaseToCreationDate = l =>
 const clinicalIndicesNotAliased = clinicalIndices.filter(x => clinicalAliases.every(a => a.index !== x.index));
 const unaliasedClinicalIndicesWithCreationDate = makeReleaseToCreationDate(clinicalIndicesNotAliased);
 
-// Make sure that no aliased index contains previously found unaliased releases.
-const unaliasedReleases = unaliasedClinicalIndicesWithCreationDate.map(x => x.release);
-assert(clinicalAliases.every(x => !unaliasedReleases.includes(`re_${x.index.split('re_')[1]}`)), 'more than one releases aliased was detected');
-
 console.log(`===== Not Aliased (pattern:re_*)`);
-
 unaliasedClinicalIndicesWithCreationDate.length
     ? console.table(unaliasedClinicalIndicesWithCreationDate)
     : console.log('None');
 
 console.log(`===== Aliased (pattern:re_*)`);
 const clinicalIndicesAliased = clinicalIndices.filter(x => clinicalAliases.some(a => a.index === x.index));
+
+//===== EDGE case
+const showIfOnlyCbtn = re => {
+    const isCbtnOnly = clinicalIndicesAliased
+        .filter(x => x.index.endsWith(re))
+        .every(x => x.index.includes('_sd_bhjxbdqk_'));
+    return isCbtnOnly ? `${re} (cbtn only)` : re
+};
+
+//======
+
 const aliasedClinicalIndicesWithCreationDate = makeReleaseToCreationDate(clinicalIndicesAliased);
 aliasedClinicalIndicesWithCreationDate.length
-    ? console.table(aliasedClinicalIndicesWithCreationDate)
+    ? console.table(aliasedClinicalIndicesWithCreationDate.map(x => ({ ...x, release: showIfOnlyCbtn(x.release) })))
     : console.log('None');
 
 console.log(`===== Others (Clinical)`);
diff --git a/admin/mockStudies.mjs b/admin/mockStudies.mjs
index 9dd96f9..deb3723 100644
--- a/admin/mockStudies.mjs
+++ b/admin/mockStudies.mjs
@@ -21,7 +21,7 @@ export const mockStudies = [
                 dbgap: '',
                 repository: 'Gene Expression Omnibus',
                 repository_url: 'https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE190125',
-                participant_count: 402,
+                participant_count: 400,
                 biospecimen_count: 402,
                 file_count: 3200,
             },
@@ -46,7 +46,7 @@ export const mockStudies = [
                     'http://dev.metabolomicsworkbench.org:22222/data/DRCCMetadata.php?Mode=Study&StudyID=ST002200&Access=UrlT3545',
                 participant_count: 418,
                 biospecimen_count: 3743,
-                file_count: 477,
+                file_count: 418,
             },
             {
                 dataset_id: 'HTP-UNHAR',
@@ -88,7 +88,7 @@ export const mockStudies = [
                 dbgap: '',
                 repository: 'Synapse',
                 repository_url: 'https://www.synapse.org/#!Synapse:syn31475487',
-                participant_count: 479,
+                participant_count: 477,
                 biospecimen_count: 4371,
                 file_count: 477,
             },
@@ -122,7 +122,7 @@ export const mockStudies = [
                 repository_url: '',
                 participant_count: 530,
                 biospecimen_count: 834,
-                file_count: 7211,
+                file_count: 7407,
             },
             {
                 dataset_id: 'DS-COG-ALL-UNHAR',
@@ -177,7 +177,7 @@ export const mockStudies = [
                 repository_url: '',
                 participant_count: 1327,
                 biospecimen_count: 1344,
-                file_count: 4922,
+                file_count: 4635,
             },
             {
                 dataset_id: 'DS360-CHD-UNHAR',
@@ -230,9 +230,9 @@ export const mockStudies = [
                 dbgap: 'phs001138',
                 repository: '',
                 repository_url: '',
-                participant_count: 369,
+                participant_count: 382,
                 biospecimen_count: 369,
-                file_count: 818,
+                file_count: 901,
             },
             {
                 dataset_id: 'DS-PCGC-UNHAR',
@@ -253,7 +253,7 @@ export const mockStudies = [
                 dbgap: 'phs001138',
                 repository: '',
                 repository_url: '',
-                participant_count: 369,
+                participant_count: 382,
                 biospecimen_count: 0,
                 file_count: 1,
             },
@@ -285,9 +285,9 @@ export const mockStudies = [
                 dbgap: 'phs002983',
                 repository: '',
                 repository_url: '',
-                participant_count: 1152,
+                participant_count: 1134,
                 biospecimen_count: 1908,
-                file_count: 2565,
+                file_count: 3255,
             },
             {
                 dataset_id: 'X01-Hakon-RNASeq',
@@ -298,7 +298,7 @@ export const mockStudies = [
                 data_category: 'Transcriptomics',
                 data_types: [],
                 expected_data_categories: [],
-                expected_number_participants: 1152,
+                expected_number_participants: 379,
                 experimental_strategy: 'Bulk RNA-Seq',
                 experimental_platform: 'Illumina',
                 is_harmonized: true,
@@ -308,9 +308,9 @@ export const mockStudies = [
                 dbgap: 'phs002983',
                 repository: '',
                 repository_url: '',
-                participant_count: 1152,
+                participant_count: 379,
                 biospecimen_count: 1908,
-                file_count: 2565,
+                file_count: 3410,
             },
             {
                 dataset_id: 'X01-Hakon-UNHAR',
@@ -331,7 +331,7 @@ export const mockStudies = [
                 dbgap: 'phs002983',
                 repository: '',
                 repository_url: '',
-                participant_count: 369,
+                participant_count: 1152,
                 biospecimen_count: 0,
                 file_count: 1,
             },
@@ -365,7 +365,7 @@ export const mockStudies = [
                 repository_url: '',
                 participant_count: 436,
                 biospecimen_count: 436,
-                file_count: 0,
+                file_count: 1308,
             },
             {
                 dataset_id: 'X01-deSmith-UNHAR',
@@ -442,7 +442,7 @@ export const mockStudies = [
                 dbgap: '',
                 repository: '',
                 repository_url: '',
-                participant_count: 3484,
+                participant_count: 3634,
                 biospecimen_count: 0,
                 file_count: 1,
             },
diff --git a/admin/poorsManEsMappingsInpector.mjs b/admin/poorsManEsMappingsInpector.mjs
index b5c04dc..fc02e54 100644
--- a/admin/poorsManEsMappingsInpector.mjs
+++ b/admin/poorsManEsMappingsInpector.mjs
@@ -26,7 +26,7 @@ const indicesWithMappingContainingIgnoreAbove = Object.entries(r.body)
 
 console.log(`==> Inspection for all centric mappings from: ${esHost}`);
 if (indicesWithMappingContainingIgnoreAbove.length === 0) {
-    console.log('No ignore_above found in any mappings for entity');
+    console.log('No "ignore_above" found in any mappings for any entity');
 } else {
     console.table(indicesWithMappingContainingIgnoreAbove);
 }
diff --git a/admin/postReleaseIndicesToAliasesHelper.mjs b/admin/postReleaseIndicesToAliasesHelper.mjs
index 69bedc4..7a4940d 100644
--- a/admin/postReleaseIndicesToAliasesHelper.mjs
+++ b/admin/postReleaseIndicesToAliasesHelper.mjs
@@ -2,9 +2,9 @@
  * This script is a helper that can be used to create
  * aliases for indices of a given release.
  *
- *  npm run post-re-alias-helper -- release:re_test_023 action:remove
+ *   npm run post-re-alias-helper -- release:re_test_023 #add
  *
- *   npm run post-re-alias-helper -- release:re_test_023 action:remove
+ *   npm run post-re-alias-helper -- release:re_test_023 action:remove #remove
  *
  * */
 import assert from 'node:assert/strict';
diff --git a/admin/projectConfig.mjs b/admin/projectConfig.mjs
new file mode 100644
index 0000000..23b57c9
--- /dev/null
+++ b/admin/projectConfig.mjs
@@ -0,0 +1,10 @@
+import arrangerProjectConf from './arrangerProjectConf.json' assert { type: "json" };
+
+export const projectConfig = (projectName) => {
+    const lambda = x => ({ ...x, projectId: projectName });
+    return  {
+        name: projectName,
+        indices: [...arrangerProjectConf.indices].map(lambda),
+        extendedMappingMutations: [...arrangerProjectConf.extendedMappingMutations].map(lambda),
+    }
+};
diff --git a/admin/projectsConfig.mjs b/admin/projectsConfig.mjs
deleted file mode 100644
index b1ad26a..0000000
--- a/admin/projectsConfig.mjs
+++ /dev/null
@@ -1,17 +0,0 @@
-import includeConf from './confInclude.json' assert { type: "json" };
-import kfConf from './confKfNext.json' assert { type: "json" };
-
-export const projectsConfig = (projectName, env) => {
-    const envToConf = {
-        kf: kfConf,
-        include: includeConf,
-    };
-    const lambda = x => ({ ...x, projectId: projectName });
-    return [
-        {
-            name: projectName,
-            indices: [...envToConf[env].indices].map(lambda),
-            extendedMappingMutations: [...envToConf[env].extendedMappingMutations].map(lambda),
-        }
-    ]
-};
diff --git a/admin/run.mjs b/admin/run.mjs
index dc86227..4363e5b 100644
--- a/admin/run.mjs
+++ b/admin/run.mjs
@@ -8,7 +8,7 @@ import EsInstance from '../dist/src/ElasticSearchClientInstance.js';
 import { countNOfDocs, createIndexIfNeeded } from '../dist/src/esUtils.js';
 
 import { ArrangerApi } from './arrangerApi.mjs';
-import { projectsConfig } from './projectsConfig.mjs';
+import { projectConfig } from './projectConfig.mjs';
 import { esHost } from '../dist/src/env.js';
 
 const hasProjectArrangerMetadataIndex = async (esClient, projectName) => {
@@ -72,68 +72,9 @@ console.info(`admin-project-script - Project value is=${envVal}`);
 console.debug(`admin-project-script - Reaching to ElasticSearch at ${esHost}`);
 const client = await EsInstance.default.getInstance();
 
-//values are hardcoded for now, but as soon as possible, we should use env var from env.ts
-const kf = [
-    'participant_centric',
-    'study_centric',
-    'biospecimen_centric',
-    'file_centric',
-    'variant_centric',
-    'gene_centric',
-    'members-public',
-];
-
-const include = [
-    'participant_centric',
-    'study_centric',
-    'biospecimen_centric',
-    'file_centric',
-    'variant_centric',
-    'gene_centric',
-];
-
-const envToIndicesPrefixes = {
-    kf: kf,
-    include: include,
-};
-
-const indicesPrefixes = envToIndicesPrefixes[envVal];
-
-const projectIndices = indicesPrefixes?.filter(p => !!p)?.map(p => p?.trim()) ?? [];
-
-if (projectIndices.length === 0) {
-    console.warn(
-        `admin-project-script - Terminating. No indices needed to build a project was found in the env var 'PROJECT_INDICES'.`,
-    );
-    process.exit(0);
-}
-
 const projectName = projectArg;
 
-//TODO: refactor to tolerate only 1 project per conf
-const allProjectsConf = projectsConfig(projectName, envVal);
-
-const projectsConf = allProjectsConf
-    .map(x => ({ ...x, indices: x.indices.map(i => ({ ...i, esIndex: i.esIndex })) }))
-    .filter(p => {
-        const indicesInConf = p.indices.map(i => i.esIndex);
-        // indices in conf are the same as target indices from env vars?
-        return sameIndices(indicesInConf, projectIndices);
-    });
-
-if (projectsConf.length === 0) {
-    console.info(
-        'admin-project-script - Terminating. Found no sane project configuration to process. Make sure it exists and that if matches with project indices.',
-    );
-    process.exit(0);
-} else if (projectsConf.length > 1) {
-    console.info(
-        'admin-project-script - Terminating. Found more than one candidates for project configurations. This is ambiguous.',
-    );
-    process.exit(0);
-}
-
-const projectConf = projectsConf[0];
+const arrangerProjectConf = projectConfig(projectName);
 
 const addArrangerProjectWithClient = ArrangerApi.addArrangerProject(client);
 
@@ -159,9 +100,9 @@ if (creationConditions.every(b => !b)) {
     console.debug(`admin-project-script - (Project addition) received this response from arranger api: `, addResp);
     console.debug(
         `admin-project-script - Creating these new graphql fields: `,
-        projectConf.indices.map(i => `${i.graphqlField}' from es index '${i.esIndex}`),
+        arrangerProjectConf.indices.map(i => `${i.graphqlField}' from es index '${i.esIndex}`),
     );
-    await ArrangerApi.createNewIndices(client, projectConf.indices);
+    await ArrangerApi.createNewIndices(client, arrangerProjectConf.indices);
 } else if (creationConditions.some(b => b !== creationConditions[0])) {
     console.warn(
         `admin-project-script - The project seems to be in a weird state for '${projectName}' does ${
@@ -178,10 +119,10 @@ if (updateConditions.every(b => b)) {
         client,
         ArrangerApi.getProjectMetadataEsLocation(projectName).index,
     );
-    if (nOfDocsInProjectMetadata === projectConf.indices.length) {
+    if (nOfDocsInProjectMetadata === arrangerProjectConf.indices.length) {
         console.debug(`admin-project-script - Applying extended mapping mutations.`);
         console.time('fixExtendedMapping');
-        await ArrangerApi.fixExtendedMapping(client, projectConf.extendedMappingMutations);
+        await ArrangerApi.fixExtendedMapping(client, arrangerProjectConf.extendedMappingMutations);
         console.timeEnd('fixExtendedMapping');
     }
 }
diff --git a/admin/sortConf.mjs b/admin/sortConf.mjs
index 811db56..c9b3a94 100644
--- a/admin/sortConf.mjs
+++ b/admin/sortConf.mjs
@@ -25,22 +25,13 @@ const sortConf = conf => {
     };
 };
 
-const processConf = path => {
-    const guessProject = (() => {
-        if (path.toLocaleLowerCase().includes('include')) {
-            return 'Include';
-        }
-        if (path.toLocaleLowerCase().includes('kfnext')) {
-            return 'Kids-First Next';
-        }
-        return '';
-    })();
+const processConf = path =>
     fs.readFile(path, 'utf8', (err, data) => {
         if (err) {
             console.error(err);
             return;
         }
-        console.info(`Reading ${guessProject} Conf...`);
+        console.info(`Reading Conf...`);
         const conf = { ...JSON.parse(data) };
         assert(Object.keys(conf).every(k => ['indices', 'extendedMappingMutations'].includes(k)));
         const sConf = { ...sortConf(conf) };
@@ -52,11 +43,8 @@ const processConf = path => {
             if (err) {
                 console.error(err);
             }
-            console.info(`Writing Sorted ${guessProject} Conf...`);
+            console.info(`Writing Sorted Conf...`);
         });
     });
-};
-
-processConf('admin/confKfNext.json');
-processConf('admin/confInclude.json');
 
+processConf('admin/arrangerProjectConf.json');