From dddca110ccb8183cff4e0a792565a4d241e5327e Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Tue, 9 Apr 2024 07:27:17 -0400 Subject: [PATCH 01/10] added id generation logic --- src/clinical/donor-repo.ts | 52 ++++++- src/clinical/id-generator.ts | 254 +++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+), 4 deletions(-) create mode 100644 src/clinical/id-generator.ts diff --git a/src/clinical/donor-repo.ts b/src/clinical/donor-repo.ts index 70c8facea..bedfc589a 100644 --- a/src/clinical/donor-repo.ts +++ b/src/clinical/donor-repo.ts @@ -24,6 +24,7 @@ import mongoose, { PaginateModel } from 'mongoose'; import mongoosePaginate from 'mongoose-paginate-v2'; import { DeepReadonly } from 'deep-freeze'; import { F, MongooseUtils, notEmpty } from '../utils'; +import { setEntityIds } from './id-generator'; export const SUBMITTER_ID = 'submitterId'; export const SPECIMEN_SUBMITTER_ID = 'specimen.submitterId'; @@ -109,8 +110,11 @@ export interface DonorRepository { ): Promise | undefined>; iterateAllByProgramId(programId: string): AsyncIterable>; create(donor: DeepReadonly>): Promise>; + create2(donor: DeepReadonly>): Promise>; // UK: idgen update(donor: DeepReadonly): Promise>; + update2(donor: Donor): Promise>; // UK: idgen updateAll(donors: DeepReadonly[]): Promise[]>; + updateAll2(donors: Donor[]): Promise; // Promise[]; // Promise[]>; // UK: idgen countBy(filter: any): Promise; } @@ -421,6 +425,15 @@ export const donorDao: DonorRepository = { return F(MongooseUtils.toPojo(newDonor) as Donor); }, + // UK: idgen + async update2(donor: Donor) { + const newDonor = new DonorModel(await setEntityIds(donor)); + unsetIsNewFlagForUpdate(newDonor); + + await newDonor.save(); + return F(MongooseUtils.toPojo(newDonor) as Donor); + }, + async updateAll(donors: DeepReadonly[]) { const newDonors = donors.map((donor) => { const newDonor = new DonorModel(donor); @@ -432,11 +445,38 @@ export const donorDao: DonorRepository = { return newDonors.map((donor) => F(MongooseUtils.toPojo(donor) as Donor)); }, + // UK: idgen + async updateAll2(donors: Donor[]) { + console.log('donors array in updateAll2: ' + donors[0].submitterId); + const newDonors = donors.map(async (donor) => { + // await someFunction(); + const newDonor = new DonorModel(await setEntityIds(donor)); + unsetIsNewFlagForUpdate(newDonor); + return newDonor; + }); + + const results = await Promise.all( + newDonors.map((donor) => { + donor.then((d) => { + d.save(); + }); + }), + ); + return ''; // await newDonors.map((donor) => F(MongooseUtils.toPojo(donor) as Donor)); + }, + async create(donor: DeepReadonly) { const newDonor = new DonorModel(donor); const doc = await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); }, + + // UK: idgen + async create2(donor: Partial) { + const newDonor = new DonorModel(await setEntityIds(donor)); + const doc = await newDonor.save(); + return F(MongooseUtils.toPojo(newDonor) as Donor); + }, }; export async function* iterateAllByProgramId( @@ -656,14 +696,17 @@ DonorSchema.index({ 'specimens.samples.submitterId': 1, programId: 1 }, { unique * multiple times, and that makes them hard to test because tests depend * on resetting the config and bootstraping but global variables keep their state. */ -DonorSchema.plugin(AutoIncrement, { + +// UK: idgen +/*DonorSchema.plugin(AutoIncrement, { inc_field: 'donorId', start_seq: process.env.DONOR_ID_SEED || 250000, -}); +});*/ DonorSchema.plugin(mongoosePaginate); -SpecimenSchema.plugin(AutoIncrement, { +// UK: idgen +/*SpecimenSchema.plugin(AutoIncrement, { inc_field: 'specimenId', start_seq: process.env.SPECIMEN_ID_SEED || 210000, }); @@ -706,7 +749,8 @@ ComorbiditySchema.plugin(AutoIncrement, { TreatmentSchema.plugin(AutoIncrement, { inc_field: 'treatmentId', start_seq: 1, -}); +});*/ +// UK: idgen export let DonorModel = mongoose.model('Donor', DonorSchema) as PaginateModel< DonorDocument diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts new file mode 100644 index 000000000..327818ffa --- /dev/null +++ b/src/clinical/id-generator.ts @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2024 The Ontario Institute for Cancer Research. All rights reserved + * + * This program and the accompanying materials are made available under the terms of + * the GNU Affero General Public License v3.0. You should have received a copy of the + * GNU Affero General Public License along with this program. + * If not, see . + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import axios from 'axios'; +import { + Biomarker, + ClinicalInfo, + Comorbidity, + CompletionStats, + Donor, + Exposure, + FamilyHistory, + FollowUp, + PrimaryDiagnosis, + SchemaMetadata, + Specimen, + Treatment, +} from './clinical-entities'; +import { ClinicalEntitySchemaNames } from '../common-model/entities'; + +const token = + 'eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3MTI2MjA0OTksImV4cCI6MTcxMjYzMTI5OSwic3ViIjoiZmU1MzVjNTAtOGNkYy00MmI4LTk4ZTctNzVjZWRjMDQwMDhmIiwiaXNzIjoiZWdvIiwianRpIjoiN2ZmMjY2NTYtZmQ1Ny00YzgxLWE5MTctZTJjNzc4NzczZWZhIiwiY29udGV4dCI6eyJzY29wZSI6WyJGSUxFU0VSVklDRS5XUklURSIsIkNMSU5JQ0FMU0VSVklDRS5SRUFEIiwiRklMRVNFUlZJQ0Uu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DRkMjM4LTU3MjktNDYzMy05MzI2LTY3MTFhYmYwYzM3YyIsImIwNDcxMzc4LTRmMWMtNDVlZi05NzViLTU1MjEwNjdmNjUyNCIsImI3NGJhYTNiLTcyNGMtNDdkMi1hMTllLWRjNGEyNTc4OTgyYyIsImNkMzhjNDU2LTBkY2ItNDAwMS05ZDM1LWU4ODRhYWI0Nzk0ZiIsIjBhNDMwMzFiLWJiOWYtNGQzNy05ZGNkLTZkNDdiZTc0YTY5MyJdfX0sImF1ZCI6W119.K1Le0AOYn2Gpvmp2saumUej1qh-7pYCLjB6N5g4PToofT6nlGXFT7CpkX8__N_sz_KY6NhqU472KCNw7ksV5yp7E1mQW5CC-8TrJWqLjLqctVzUSxNaou96JXozef65ISR-Izo8HKVlS2k1GcUHR-D51SLBckFSfXgnAJSp9mRBIXo_N0FR4KqcyV3McGIYS0yNp0PKFNHL2aBv3Lq6zgHafMrry5uoA3zuBcC84O10Kwq7hXT-KGf7oOBwLBVgLR38F6K_STbvAVrjunUWBnqiAOajz6RMBk5Z9Xl4P5r8EUVrZd70FJFcCI4Bpwro2G7RO2QWhZGOfyQiFZ1nOug'; + +export interface PartialDonor { + _id?: string; + __v?: number; // mongodb property not being filtered out + createBy?: string; + schemaMetadata?: SchemaMetadata | undefined; + donorId?: number; + gender?: string; + submitterId?: string; + programId?: string; + specimens?: Array; + clinicalInfo?: ClinicalInfo; + primaryDiagnoses?: Array; + familyHistory?: Array; + comorbidity?: Array; + followUps?: Array; + treatments?: Array; + exposure?: Array; + biomarker?: Array; + createdAt?: string; + updatedAt?: string; + completionStats?: CompletionStats; +} + +export async function getId( + programId: string, + submitterId: string, + family_relative_id: string, + entityType: string, +) { + console.log('getId function called'); + const headers = { + headers: { + Authorization: 'Bearer ' + token, + }, + }; + + const response = await axios.get( + // 'http://localhost:9001/' + programId + '/' + submitterId + '/' + family_relative_id + '/' + entityType, + `http://localhost:9001/${programId}/${submitterId}/${family_relative_id}/${entityType}`, + headers, + ); + console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); + return parseInt(response.data.entityId); +} + +export async function setEntityIds(donor: PartialDonor) { + const programId = donor.programId as string; + + // -- DONOR -- + const donorId = await getId( + programId, + donor.submitterId as string, + 'null', + ClinicalEntitySchemaNames.DONOR, + ); + donor.donorId = donorId; + console.log(donor.donorId); + + // -- SPECIMEN -- + if (donor.specimens && donor.specimens.length > 0) { + for (const specimen of donor.specimens) { + console.log( + 'specimen.clinicalInfo.submitter_specimen_id: ' + + specimen.clinicalInfo.submitter_specimen_id, + ); + console.log('specimen.submitterId: ' + specimen.submitterId); + const submitterId = !specimen.clinicalInfo.submitter_specimen_id + ? specimen.submitterId + : specimen.clinicalInfo.submitter_specimen_id; + const id = await getId( + programId, + // specimen.clinicalInfo.submitter_specimen_id as string, + submitterId as string, + 'null', + ClinicalEntitySchemaNames.SPECIMEN, + ); + specimen.specimenId = id; + console.log(specimen.specimenId); + + // -- SAMPLE -- + const samples = specimen.samples; + for (const sample of samples) { + const id = await getId( + programId, + sample.submitterId as string, + 'null', + ClinicalEntitySchemaNames.REGISTRATION, + ); + sample.sampleId = id; + console.log(sample.sampleId); + } + } + } + + // -- BIOMARKER -- + // submitter_specimen_id + if (donor.biomarker && donor.biomarker.length > 0) { + for (const bm of donor.biomarker) { + const id = await getId( + programId, + bm.clinicalInfo.submitter_specimen_id as string, + 'null', + ClinicalEntitySchemaNames.BIOMARKER, + ); + bm.biomarkerId = id; + console.log(bm.biomarkerId); + } + } + + // -- COMORBIDITY -- + // submitter_donor_id and comorbidity_type_code - UK-confirm + if (donor.comorbidity && donor.comorbidity.length > 0) { + for (const c of donor.comorbidity) { + const cRec = c.clinicalInfo.submitter_donor_id + '-' + c.clinicalInfo.comorbidity_type_code; + const id = await getId( + programId, + // c.clinicalInfo.submitter_donor_id as string, + cRec as string, + 'null', + ClinicalEntitySchemaNames.COMORBIDITY, + ); + c.comorbidityId = id; + console.log(c.comorbidityId); + } + } + + // -- PRIMARY DIAGNOSIS -- + if (donor.primaryDiagnoses && donor.primaryDiagnoses.length > 0) { + for (const p of donor.primaryDiagnoses) { + const id = await getId( + programId, + p.clinicalInfo.submitter_primary_diagnosis_id as string, + 'null', + ClinicalEntitySchemaNames.PRIMARY_DIAGNOSIS, + ); + p.primaryDiagnosisId = id; + console.log(p.primaryDiagnosisId); + } + + /*const updatePrimaryDiagnosesIds = donor.primaryDiagnoses.map(p => { + console.log('submitter_primary_diagnosis_id: ' + p.clinicalInfo.submitter_primary_diagnosis_id); + getId(programId, p.clinicalInfo.submitter_primary_diagnosis_id as string, 'primary_diagnosis') + .then(id => p.primaryDiagnosisId = id) + .catch((err) => { + console.log(err); + }); + });*/ + + // await Promise.all(updatePrimaryDiagnosesIds); + } + + // -- TREATMENT -- + if (donor.treatments && donor.treatments.length > 0) { + for (const t of donor.treatments) { + const id = await getId( + programId, + t.clinicalInfo.submitter_treatment_id as string, + 'null', + ClinicalEntitySchemaNames.TREATMENT, + ); + t.treatmentId = id; + console.log(t.treatmentId); + } + } + + // -- FAMILY HISTORY -- + // submitter_donor_id and family_relative_id - UK: confirm + if (donor.familyHistory && donor.familyHistory.length > 0) { + for (const fh of donor.familyHistory) { + const fhRec = fh.clinicalInfo.submitter_donor_id + '_' + fh.clinicalInfo.family_relative_id; + const id = await getId( + programId, + fh.clinicalInfo.submitter_donor_id as string, + fh.clinicalInfo.family_relative_id as string, + // fhRec as string, + ClinicalEntitySchemaNames.FAMILY_HISTORY, + ); + fh.familyHistoryId = id; + console.log(fh.familyHistoryId); + } + } + + // -- FOLLOW UP -- + if (donor.followUps && donor.followUps.length > 0) { + for (const fl of donor.followUps) { + const id = await getId( + programId, + fl.clinicalInfo.submitter_follow_up_id as string, + 'null', + ClinicalEntitySchemaNames.FOLLOW_UP, + ); + fl.followUpId = id; + console.log(fl.followUpId); + } + } + + // -- EXPOSURE -- + // submitter_donor_id + if (donor.exposure && donor.exposure.length > 0) { + for (const ex of donor.exposure) { + const id = await getId( + programId, + ex.clinicalInfo.submitter_donor_id as string, + 'null', + ClinicalEntitySchemaNames.EXPOSURE, + ); + ex.exposureId = id; + console.log(ex.exposureId); + } + } + + return donor; +} + +// UK: idgen From c4b472dd77e91e1309690e8e703f0a501ef2337f Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Thu, 11 Apr 2024 14:05:36 -0400 Subject: [PATCH 02/10] added id generation logic --- src/clinical/donor-repo.ts | 56 ++++--- src/clinical/id-generator.ts | 283 ++++++++++++++++++++++------------- 2 files changed, 210 insertions(+), 129 deletions(-) diff --git a/src/clinical/donor-repo.ts b/src/clinical/donor-repo.ts index bedfc589a..051a99521 100644 --- a/src/clinical/donor-repo.ts +++ b/src/clinical/donor-repo.ts @@ -24,7 +24,7 @@ import mongoose, { PaginateModel } from 'mongoose'; import mongoosePaginate from 'mongoose-paginate-v2'; import { DeepReadonly } from 'deep-freeze'; import { F, MongooseUtils, notEmpty } from '../utils'; -import { setEntityIds } from './id-generator'; +import { setEntityIds, setEntityIdsForDonors } from './id-generator'; export const SUBMITTER_ID = 'submitterId'; export const SPECIMEN_SUBMITTER_ID = 'specimen.submitterId'; @@ -110,23 +110,28 @@ export interface DonorRepository { ): Promise | undefined>; iterateAllByProgramId(programId: string): AsyncIterable>; create(donor: DeepReadonly>): Promise>; - create2(donor: DeepReadonly>): Promise>; // UK: idgen - update(donor: DeepReadonly): Promise>; - update2(donor: Donor): Promise>; // UK: idgen - updateAll(donors: DeepReadonly[]): Promise[]>; - updateAll2(donors: Donor[]): Promise; // Promise[]; // Promise[]>; // UK: idgen + // create2(donor: DeepReadonly>): Promise>; // UK: idgen + // update(donor: DeepReadonly): Promise>; + update(donor: Donor): Promise>; // UK: idgen + // updateAll(donors: DeepReadonly[]): Promise[]>; + updateAll(donors: Donor[]): Promise[]>; // Promise[]; // Promise[]>; // UK: idgen countBy(filter: any): Promise; } // Mongoose implementation of the DonorRepository export const donorDao: DonorRepository = { - async insertDonors(donors: Donor[]) { + /*async insertDonors(donors: Donor[]) { await mongoose.connection.db.collection('donors').insertMany(donors); + },*/ + async insertDonors(donors: Donor[]) { + const donorsWithIds = await setEntityIdsForDonors(donors); + await mongoose.connection.db.collection('donors').insertMany(donorsWithIds); }, async updateDonor(donor: Donor) { + const donorsWithIds = await setEntityIds(donor); // UK: idgen await mongoose.connection.db .collection('donors') - .findOneAndUpdate({ donorId: donor.donorId }, { $set: donor }); + .findOneAndUpdate({ donorId: donor.donorId }, { $set: donorsWithIds }); }, async countBy(filter: any) { return await DonorModel.count(filter).exec(); @@ -417,24 +422,25 @@ export const donorDao: DonorRepository = { return iterateAllByProgramId(programId); }, - async update(donor: DeepReadonly) { + /* async update(donor: DeepReadonly) { const newDonor = new DonorModel(donor); unsetIsNewFlagForUpdate(newDonor); await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); - }, + },*/ // UK: idgen - async update2(donor: Donor) { - const newDonor = new DonorModel(await setEntityIds(donor)); + async update(donor: Donor) { + const dnr = await setEntityIds(donor); + const newDonor = new DonorModel(await setEntityIds(donor)); // UK: idgen unsetIsNewFlagForUpdate(newDonor); - + console.log('newDonor._id' + newDonor._id); await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); }, - async updateAll(donors: DeepReadonly[]) { + /*async updateAll(donors: DeepReadonly[]) { const newDonors = donors.map((donor) => { const newDonor = new DonorModel(donor); unsetIsNewFlagForUpdate(newDonor); @@ -443,10 +449,10 @@ export const donorDao: DonorRepository = { const results = await Promise.all(newDonors.map((donor) => donor.save())); return newDonors.map((donor) => F(MongooseUtils.toPojo(donor) as Donor)); - }, + },*/ // UK: idgen - async updateAll2(donors: Donor[]) { + async updateAll(donors: Donor[]) { console.log('donors array in updateAll2: ' + donors[0].submitterId); const newDonors = donors.map(async (donor) => { // await someFunction(); @@ -455,24 +461,32 @@ export const donorDao: DonorRepository = { return newDonor; }); - const results = await Promise.all( + await Promise.all( newDonors.map((donor) => { donor.then((d) => { d.save(); }); }), ); - return ''; // await newDonors.map((donor) => F(MongooseUtils.toPojo(donor) as Donor)); + const result = await Promise.all( + newDonors.map((donor) => + donor.then((d) => { + return F(MongooseUtils.toPojo(d) as Donor); + }), + ), + ); + + return result; // newDonors.map((donor) => donor.then((d) => { return F(MongooseUtils.toPojo(d) as Donor);}).then(res => res)); }, - async create(donor: DeepReadonly) { + /*async create(donor: DeepReadonly) { const newDonor = new DonorModel(donor); const doc = await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); - }, + },*/ // UK: idgen - async create2(donor: Partial) { + async create(donor: Partial) { const newDonor = new DonorModel(await setEntityIds(donor)); const doc = await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 327818ffa..6cf29ed06 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -18,6 +18,8 @@ */ import axios from 'axios'; +import memoize from 'memoizee'; +import ms from 'ms'; import { Biomarker, ClinicalInfo, @@ -34,8 +36,28 @@ import { } from './clinical-entities'; import { ClinicalEntitySchemaNames } from '../common-model/entities'; -const token = - 'eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3MTI2MjA0OTksImV4cCI6MTcxMjYzMTI5OSwic3ViIjoiZmU1MzVjNTAtOGNkYy00MmI4LTk4ZTctNzVjZWRjMDQwMDhmIiwiaXNzIjoiZWdvIiwianRpIjoiN2ZmMjY2NTYtZmQ1Ny00YzgxLWE5MTctZTJjNzc4NzczZWZhIiwiY29udGV4dCI6eyJzY29wZSI6WyJGSUxFU0VSVklDRS5XUklURSIsIkNMSU5JQ0FMU0VSVklDRS5SRUFEIiwiRklMRVNFUlZJQ0UuUkVBRCIsIlJEUEMtQ0EuUkVBRCIsIlBST0dSQU1TRVJWSUNFLlJFQUQiLCJSRFBDLWNvbGxhYi5SRUFEIiwiREMtUkVHSVNUUlkuV1JJVEUiLCJEQUNPLVJFVklFVy5SRUFEIiwiRElDVElPTkFSWS5XUklURSIsInNjb3JlLlJFQUQiLCJEQy1SRUdJU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u4Z9aqUwBXug7fhlDBX_AsYlp0N0kYXJcL52LkW3WBZ6neOZ0W3XuVbWJN-KW8UF_PMDWXaYn2XUDNHDzg3u_wF7gV3Xe15BHarvxhU1Ulvli2WxxAumWGAJgunfWpdsFI0tK4M6N1e1r2xGd5Xgu3OtSxHZ41h4GLACxafyImySu9_wysNfdRr_j-FANYUNNWNO6U6UHPdFkqBfXOjF_aN7NfiYWNE44wd0dG7fbOGipsIuPR-KXuPDhiPMMp-kNffFZgPLOwKlLm8Nm1yKElweRe7bfaIPyqUK1Kg'; + +interface IdGenerationRequest { + programId: string; + submitterId: any; + submitterDonorId: string; + testInterval: string; + family_relative_id: string; + comorbidityTypeCode: string; + entityType: string; +} + +const request: IdGenerationRequest = { + programId: 'null', + submitterId: 'null', + submitterDonorId: 'null', + testInterval: 'null', + family_relative_id: 'null', + comorbidityTypeCode: 'null', + entityType: 'null', +}; export interface PartialDonor { _id?: string; @@ -46,7 +68,7 @@ export interface PartialDonor { gender?: string; submitterId?: string; programId?: string; - specimens?: Array; + specimens?: Array | undefined; clinicalInfo?: ClinicalInfo; primaryDiagnoses?: Array; familyHistory?: Array; @@ -60,73 +82,91 @@ export interface PartialDonor { completionStats?: CompletionStats; } -export async function getId( - programId: string, - submitterId: string, - family_relative_id: string, - entityType: string, -) { +export async function getId(req: IdGenerationRequest) { console.log('getId function called'); + const token = await getToken(); const headers = { headers: { Authorization: 'Bearer ' + token, }, }; - const response = await axios.get( - // 'http://localhost:9001/' + programId + '/' + submitterId + '/' + family_relative_id + '/' + entityType, - `http://localhost:9001/${programId}/${submitterId}/${family_relative_id}/${entityType}`, - headers, + console.log( + 'request params: ' + + req.programId + + ' - ' + + req.submitterId + + ' - ' + + req.submitterDonorId + + ' - ' + + req.testInterval + + ' - ' + + req.family_relative_id + + ' - ' + + req.comorbidityTypeCode + + ' - ' + + req.entityType, ); - console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); - return parseInt(response.data.entityId); + try { + const response = await axios.get( + `http://localhost:9001/${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, + headers, + ); + console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); + return parseInt(response.data.entityId); + } catch (e) { + console.log(e); + // do something here + } +} + +export async function setEntityIdsForDonors(donors: Donor[]) { + const donorsWithIds = donors.map(async (donor) => { + return await setEntityIds(donor); + }); + return await Promise.all(donorsWithIds); } export async function setEntityIds(donor: PartialDonor) { - const programId = donor.programId as string; + // const programId = donor.programId as string; // -- DONOR -- - const donorId = await getId( - programId, - donor.submitterId as string, - 'null', - ClinicalEntitySchemaNames.DONOR, - ); + const donorId = await getId({ + ...request, + programId: donor.programId as string, + submitterId: donor.submitterId as string, + submitterDonorId: donor.submitterId as string, + entityType: ClinicalEntitySchemaNames.DONOR, + }); donor.donorId = donorId; console.log(donor.donorId); // -- SPECIMEN -- if (donor.specimens && donor.specimens.length > 0) { for (const specimen of donor.specimens) { - console.log( - 'specimen.clinicalInfo.submitter_specimen_id: ' + - specimen.clinicalInfo.submitter_specimen_id, - ); - console.log('specimen.submitterId: ' + specimen.submitterId); const submitterId = !specimen.clinicalInfo.submitter_specimen_id ? specimen.submitterId : specimen.clinicalInfo.submitter_specimen_id; - const id = await getId( - programId, - // specimen.clinicalInfo.submitter_specimen_id as string, - submitterId as string, - 'null', - ClinicalEntitySchemaNames.SPECIMEN, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: submitterId as string, + entityType: ClinicalEntitySchemaNames.SPECIMEN, + }); specimen.specimenId = id; - console.log(specimen.specimenId); + console.log('specimen.specimenId: ' + specimen.specimenId); // -- SAMPLE -- const samples = specimen.samples; for (const sample of samples) { - const id = await getId( - programId, - sample.submitterId as string, - 'null', - ClinicalEntitySchemaNames.REGISTRATION, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: sample.submitterId as string, + entityType: ClinicalEntitySchemaNames.REGISTRATION, + }); sample.sampleId = id; - console.log(sample.sampleId); + console.log('sample.sampleId: ' + sample.sampleId); } } } @@ -135,70 +175,68 @@ export async function setEntityIds(donor: PartialDonor) { // submitter_specimen_id if (donor.biomarker && donor.biomarker.length > 0) { for (const bm of donor.biomarker) { - const id = await getId( - programId, - bm.clinicalInfo.submitter_specimen_id as string, - 'null', - ClinicalEntitySchemaNames.BIOMARKER, - ); + const submitterBiomarkerId = + bm.clinicalInfo.submitter_specimen_id?.toString() ?? + bm.clinicalInfo.submitter_primary_diagnosis_id?.toString() ?? + bm.clinicalInfo.submitter_follow_up_id?.toString() ?? + bm.clinicalInfo.submitter_treatment_id?.toString() ?? + 'null'; + + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: submitterBiomarkerId, + submitterDonorId: bm.clinicalInfo.submitter_donor_id as string, + testInterval: bm.clinicalInfo.test_interval as string, + entityType: ClinicalEntitySchemaNames.BIOMARKER, + }); + bm.biomarkerId = id; - console.log(bm.biomarkerId); + console.log('biomarkerId: ' + bm.biomarkerId); } } // -- COMORBIDITY -- // submitter_donor_id and comorbidity_type_code - UK-confirm if (donor.comorbidity && donor.comorbidity.length > 0) { - for (const c of donor.comorbidity) { - const cRec = c.clinicalInfo.submitter_donor_id + '-' + c.clinicalInfo.comorbidity_type_code; - const id = await getId( - programId, - // c.clinicalInfo.submitter_donor_id as string, - cRec as string, - 'null', - ClinicalEntitySchemaNames.COMORBIDITY, - ); - c.comorbidityId = id; - console.log(c.comorbidityId); + for (const cm of donor.comorbidity) { + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: cm.clinicalInfo.submitter_donor_id as string, + comorbidityTypeCode: cm.clinicalInfo.comorbidity_type_code as string, + entityType: ClinicalEntitySchemaNames.COMORBIDITY, + }); + cm.comorbidityId = id; + console.log('comorbidityId: ' + cm.comorbidityId); } } // -- PRIMARY DIAGNOSIS -- if (donor.primaryDiagnoses && donor.primaryDiagnoses.length > 0) { for (const p of donor.primaryDiagnoses) { - const id = await getId( - programId, - p.clinicalInfo.submitter_primary_diagnosis_id as string, - 'null', - ClinicalEntitySchemaNames.PRIMARY_DIAGNOSIS, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: p.clinicalInfo.submitter_primary_diagnosis_id as string, + entityType: ClinicalEntitySchemaNames.PRIMARY_DIAGNOSIS, + }); p.primaryDiagnosisId = id; - console.log(p.primaryDiagnosisId); + console.log('primaryDiagnosisId: ' + p.primaryDiagnosisId); } - - /*const updatePrimaryDiagnosesIds = donor.primaryDiagnoses.map(p => { - console.log('submitter_primary_diagnosis_id: ' + p.clinicalInfo.submitter_primary_diagnosis_id); - getId(programId, p.clinicalInfo.submitter_primary_diagnosis_id as string, 'primary_diagnosis') - .then(id => p.primaryDiagnosisId = id) - .catch((err) => { - console.log(err); - }); - });*/ - - // await Promise.all(updatePrimaryDiagnosesIds); } // -- TREATMENT -- if (donor.treatments && donor.treatments.length > 0) { for (const t of donor.treatments) { - const id = await getId( - programId, - t.clinicalInfo.submitter_treatment_id as string, - 'null', - ClinicalEntitySchemaNames.TREATMENT, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: t.clinicalInfo.submitter_treatment_id as string, + entityType: ClinicalEntitySchemaNames.TREATMENT, + }); t.treatmentId = id; - console.log(t.treatmentId); + console.log('treatmentId: ' + t.treatmentId); } } @@ -206,30 +244,29 @@ export async function setEntityIds(donor: PartialDonor) { // submitter_donor_id and family_relative_id - UK: confirm if (donor.familyHistory && donor.familyHistory.length > 0) { for (const fh of donor.familyHistory) { - const fhRec = fh.clinicalInfo.submitter_donor_id + '_' + fh.clinicalInfo.family_relative_id; - const id = await getId( - programId, - fh.clinicalInfo.submitter_donor_id as string, - fh.clinicalInfo.family_relative_id as string, - // fhRec as string, - ClinicalEntitySchemaNames.FAMILY_HISTORY, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: fh.clinicalInfo.submitter_donor_id as string, + family_relative_id: fh.clinicalInfo.family_relative_id as string, + entityType: ClinicalEntitySchemaNames.FAMILY_HISTORY, + }); fh.familyHistoryId = id; - console.log(fh.familyHistoryId); + console.log('familyHistoryId: ' + fh.familyHistoryId); } } // -- FOLLOW UP -- if (donor.followUps && donor.followUps.length > 0) { for (const fl of donor.followUps) { - const id = await getId( - programId, - fl.clinicalInfo.submitter_follow_up_id as string, - 'null', - ClinicalEntitySchemaNames.FOLLOW_UP, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: fl.clinicalInfo.submitter_follow_up_id as string, + entityType: ClinicalEntitySchemaNames.FOLLOW_UP, + }); fl.followUpId = id; - console.log(fl.followUpId); + console.log('followUpId: ' + fl.followUpId); } } @@ -237,18 +274,48 @@ export async function setEntityIds(donor: PartialDonor) { // submitter_donor_id if (donor.exposure && donor.exposure.length > 0) { for (const ex of donor.exposure) { - const id = await getId( - programId, - ex.clinicalInfo.submitter_donor_id as string, - 'null', - ClinicalEntitySchemaNames.EXPOSURE, - ); + const id = await getId({ + ...request, + programId: donor.programId as string, + submitterId: ex.clinicalInfo.submitter_donor_id as string, + entityType: ClinicalEntitySchemaNames.EXPOSURE, + }); ex.exposureId = id; - console.log(ex.exposureId); + console.log('exposureId: ' + ex.exposureId); } } return donor; } +const getToken = memoize( + async () => { + const headers = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }; + const data = { + grant_type: 'client_credentials', + client_id: 'clinical-service', + client_secret: 'top-secret', + }; + // const response = await axios.post('https://ego.argo-qa.cumulus.genomeinformatics.org/api/oauth/token', data, headers); + const response = await axios.get('http://localhost:9001/'); + console.log('token response: ' + response.data.access_token); + return 'eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3MTI4NTEzNjYsImV4cCI6MTcxMjg2MjE2Niwic3ViIjoiZmU1MzVjNTAtOGNkYy00MmI4LTk4ZTctNzVjZWRjMDQwMDhmIiwiaXNzIjoiZWdvIiwianRpIjoiMGM5ZmQ5OTgtODU1MS00MjJjLWEwNTUtNDU0NDkwZDYyYzU5IiwiY29udGV4dC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ZSI6IkFETUlOIiwiZ3JvdXBzIjpbIjcxOGU5ZWM1LTBkMjgtNGUyYS05ODMxLTQ2NDI4MGMzZjVjNiIsImUyNDRkMjM4LTU3MjktNDYzMy05MzI2LTY3MTFhYmYwYzM3YyIsImIwNDcxMzc4LTRmMWMtNDVlZi05NzViLTU1MjEwNjdmNjUyNCIsImI3NGJhYTNiLTcyNGMtNDdkMi1hMTllLWRjNGEyNTc4OTgyYyIsImNkMzhjNDU2LTBkY2ItNDAwMS05ZDM1LWU4ODRhYWI0Nzk0ZiIsIjBhNDMwMzFiLWJiOWYtNGQzNy05ZGNkLTZkNDdiZTc0YTY5MyJdfX0sImF1ZCI6W119.S5ikld62ZwNHFxycKJT-tZIUYHJYY9-DCvQ8T_TOR9IR23sxELK3tDgfJyMPSSkZR1MvlopL3akNhwzwVHOoMSOjhMbMrmSwXdCosEmDi6pbcdPzgW71fLfDO5JveEiFf6_arWPb3GuV5zj9EuJYTEaqCH2M_J7gHT0shu1AwAcdAkoHn6y-ywrxB0ge1340ywnPqd5-FuwhwhnU4gQppo6S9T5QRJfisziAP1RBwJSNC7IGT2DbodbJqYvC2h6hZzlGiHgDFOvPcvAOVw798qW3uWu_7jWpbg_w6sSOdhLOdcI_IslHDXr0_6ajegy0twjGINy6CPWSPdnzrktHsA'; + // response.data['access_token']; + }, + { + maxAge: ms('1d'), + preFetch: true, + }, +); + // UK: idgen +// `http://localhost:9001/${req.programId}/${req.submitterDonorId}/${req.submitterSpecimenId}/${req.submitterSampleId}/${req.submitterPrimaryDiagnosisId}/${req.submitterTreatmentId}/${req.submitterFollowUpId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, + +// todo +// get ego token in memoizee +// handle error from getId api +// From 1ae27f828503a4ce6c33954c43dc6865a1b36512 Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Thu, 11 Apr 2024 14:27:03 -0400 Subject: [PATCH 03/10] updated donor-repo calls --- src/config.ts | 1 + src/exception/missing-entity-exceptions/service.ts | 2 +- src/server.ts | 4 ++++ .../submission-to-clinical/submission-to-clinical.ts | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index df21ef044..d08134623 100644 --- a/src/config.ts +++ b/src/config.ts @@ -40,6 +40,7 @@ export interface AppConfig { egoUrl(): string; egoClientId(): string; egoClientSecret(): string; + tokenUrl(): string; } class ConfigManager { diff --git a/src/exception/missing-entity-exceptions/service.ts b/src/exception/missing-entity-exceptions/service.ts index 3b139ab05..bcc4e6ad7 100644 --- a/src/exception/missing-entity-exceptions/service.ts +++ b/src/exception/missing-entity-exceptions/service.ts @@ -138,7 +138,7 @@ const recalculateAndUpdateDonors = async (props: { const updatedDonors = await updateDonorsCompletionStats( (donorDocuments || []) as DeepReadonly[], ); - const savedDonors = await donorRepo.updateAll(updatedDonors.map((dto) => deepFreeze(dto))); + const savedDonors = await donorRepo.updateAll(updatedDonors); return success(savedDonors); } catch (error) { const message = 'Error thrown while updating donor core completion data'; diff --git a/src/server.ts b/src/server.ts index 6e3c9f16c..bc7bd60d4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -136,6 +136,10 @@ let server: Server; egoUrl(): string { return process.env.EGO_URL || secrets.EGO_URL || ''; }, + tokenUrl(): string { + // UK: idgen + return process.env.TOKEN_URI || ''; + }, egoClientId(): string { return process.env.EGO_CLIENT_ID || secrets.EGO_CLIENT_ID || ''; }, diff --git a/src/submission/submission-to-clinical/submission-to-clinical.ts b/src/submission/submission-to-clinical/submission-to-clinical.ts index 0bd30de17..7eb0bd1ad 100644 --- a/src/submission/submission-to-clinical/submission-to-clinical.ts +++ b/src/submission/submission-to-clinical/submission-to-clinical.ts @@ -139,7 +139,7 @@ const performCommitSubmission = async ( try { // write each updated donor to the db - await donorDao.updateAll(updatedDonors.map((dto) => F(dto))); + await donorDao.updateAll(updatedDonors); // If the save completed without error, we can delete the active registration submissionRepository.deleteByProgramId(activeSubmission.programId); From ec4a991252b78bdfe3b0b368528e4fe673999f13 Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Thu, 11 Apr 2024 15:19:35 -0400 Subject: [PATCH 04/10] added config values for token and id-service url --- src/clinical/donor-repo.ts | 95 +------------------ src/clinical/id-generator.ts | 48 ++-------- src/config.ts | 1 + src/decorators/index.ts | 10 +- src/server.ts | 4 +- src/submission/submission-api.ts | 2 +- test/integration/clinical/clinical.spec.ts | 6 ++ .../submission-schema-migration.spec.ts | 6 ++ .../integration/submission/submission.spec.ts | 6 ++ test/performance-test/submission.spec.ts | 6 ++ test/unit/decorator/decorator.spec.ts | 6 ++ .../submission/submission-to-clinical.spec.ts | 5 +- 12 files changed, 56 insertions(+), 139 deletions(-) diff --git a/src/clinical/donor-repo.ts b/src/clinical/donor-repo.ts index 051a99521..f13f23293 100644 --- a/src/clinical/donor-repo.ts +++ b/src/clinical/donor-repo.ts @@ -110,25 +110,19 @@ export interface DonorRepository { ): Promise | undefined>; iterateAllByProgramId(programId: string): AsyncIterable>; create(donor: DeepReadonly>): Promise>; - // create2(donor: DeepReadonly>): Promise>; // UK: idgen - // update(donor: DeepReadonly): Promise>; - update(donor: Donor): Promise>; // UK: idgen - // updateAll(donors: DeepReadonly[]): Promise[]>; - updateAll(donors: Donor[]): Promise[]>; // Promise[]; // Promise[]>; // UK: idgen + update(donor: Donor): Promise>; + updateAll(donors: Donor[]): Promise[]>; countBy(filter: any): Promise; } // Mongoose implementation of the DonorRepository export const donorDao: DonorRepository = { - /*async insertDonors(donors: Donor[]) { - await mongoose.connection.db.collection('donors').insertMany(donors); - },*/ async insertDonors(donors: Donor[]) { const donorsWithIds = await setEntityIdsForDonors(donors); await mongoose.connection.db.collection('donors').insertMany(donorsWithIds); }, async updateDonor(donor: Donor) { - const donorsWithIds = await setEntityIds(donor); // UK: idgen + const donorsWithIds = await setEntityIds(donor); await mongoose.connection.db .collection('donors') .findOneAndUpdate({ donorId: donor.donorId }, { $set: donorsWithIds }); @@ -422,36 +416,15 @@ export const donorDao: DonorRepository = { return iterateAllByProgramId(programId); }, - /* async update(donor: DeepReadonly) { - const newDonor = new DonorModel(donor); - unsetIsNewFlagForUpdate(newDonor); - - await newDonor.save(); - return F(MongooseUtils.toPojo(newDonor) as Donor); - },*/ - - // UK: idgen async update(donor: Donor) { const dnr = await setEntityIds(donor); - const newDonor = new DonorModel(await setEntityIds(donor)); // UK: idgen + const newDonor = new DonorModel(await setEntityIds(donor)); unsetIsNewFlagForUpdate(newDonor); console.log('newDonor._id' + newDonor._id); await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); }, - /*async updateAll(donors: DeepReadonly[]) { - const newDonors = donors.map((donor) => { - const newDonor = new DonorModel(donor); - unsetIsNewFlagForUpdate(newDonor); - return newDonor; - }); - - const results = await Promise.all(newDonors.map((donor) => donor.save())); - return newDonors.map((donor) => F(MongooseUtils.toPojo(donor) as Donor)); - },*/ - - // UK: idgen async updateAll(donors: Donor[]) { console.log('donors array in updateAll2: ' + donors[0].submitterId); const newDonors = donors.map(async (donor) => { @@ -479,13 +452,6 @@ export const donorDao: DonorRepository = { return result; // newDonors.map((donor) => donor.then((d) => { return F(MongooseUtils.toPojo(d) as Donor);}).then(res => res)); }, - /*async create(donor: DeepReadonly) { - const newDonor = new DonorModel(donor); - const doc = await newDonor.save(); - return F(MongooseUtils.toPojo(newDonor) as Donor); - },*/ - - // UK: idgen async create(donor: Partial) { const newDonor = new DonorModel(await setEntityIds(donor)); const doc = await newDonor.save(); @@ -711,61 +677,8 @@ DonorSchema.index({ 'specimens.samples.submitterId': 1, programId: 1 }, { unique * on resetting the config and bootstraping but global variables keep their state. */ -// UK: idgen -/*DonorSchema.plugin(AutoIncrement, { - inc_field: 'donorId', - start_seq: process.env.DONOR_ID_SEED || 250000, -});*/ - DonorSchema.plugin(mongoosePaginate); -// UK: idgen -/*SpecimenSchema.plugin(AutoIncrement, { - inc_field: 'specimenId', - start_seq: process.env.SPECIMEN_ID_SEED || 210000, -}); - -SampleSchema.plugin(AutoIncrement, { - inc_field: 'sampleId', - start_seq: process.env.SAMPLE_ID_SEED || 610000, -}); - -FollowUpSchema.plugin(AutoIncrement, { - inc_field: 'followUpId', - start_seq: 1, -}); - -PrimaryDiagnosisSchema.plugin(AutoIncrement, { - inc_field: 'primaryDiagnosisId', - start_seq: 1, -}); - -FamilyHistorySchema.plugin(AutoIncrement, { - inc_field: 'familyHistoryId', - start_seq: 1, -}); - -ExposureSchema.plugin(AutoIncrement, { - inc_field: 'exposureId', - start_seq: 1, -}); - -BiomarkerSchema.plugin(AutoIncrement, { - inc_field: 'biomarkerId', - start_seq: 1, -}); - -ComorbiditySchema.plugin(AutoIncrement, { - inc_field: 'comorbidityId', - start_seq: 1, -}); - -TreatmentSchema.plugin(AutoIncrement, { - inc_field: 'treatmentId', - start_seq: 1, -});*/ -// UK: idgen - export let DonorModel = mongoose.model('Donor', DonorSchema) as PaginateModel< DonorDocument >; diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 6cf29ed06..a208d8338 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -35,9 +35,7 @@ import { Treatment, } from './clinical-entities'; import { ClinicalEntitySchemaNames } from '../common-model/entities'; - -// const token = await getToken(); -// 'eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3MTI3ODM5NjksImV4cCI6MTcxMjc5NDc2OSwic3ViIjoiZmU1MzVjNTAtOGNkYy00MmI4LTk4ZTctNzVjZWRjMDQwMDhmIiwiaXNzIjoiZWdvIiwianRpIjoiNmI1MDZhYTUtNzZiZi00ZmIyLTkxMGQtMzA4ZjJhZTI5MjViIiwiY29udGV4dCI6eyJzY29wZSI6WyJGSUxFU0VSVklDRS5XUklURSIsIkNMSU5JQ0FMU0VSVklDRS5SRUFEIiwiRklMRVNFUlZJQ0UuUkVBRCIsIlJEUEMtQ0EuUkVBRCIsIlBST0dSQU1TRVJWSUNFLlJFQUQiLCJSRFBDLWNvbGxhYi5SRUFEIiwiREMtUkVHSVNUUlku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JhYTNiLTcyNGMtNDdkMi1hMTllLWRjNGEyNTc4OTgyYyIsImNkMzhjNDU2LTBkY2ItNDAwMS05ZDM1LWU4ODRhYWI0Nzk0ZiIsIjBhNDMwMzFiLWJiOWYtNGQzNy05ZGNkLTZkNDdiZTc0YTY5MyJdfX0sImF1ZCI6W119.v0GLGIT_gkxVOSM6p2ynVaWOidde2Ag2kjRzP7PUE7Ssp3xu4Z9aqUwBXug7fhlDBX_AsYlp0N0kYXJcL52LkW3WBZ6neOZ0W3XuVbWJN-KW8UF_PMDWXaYn2XUDNHDzg3u_wF7gV3Xe15BHarvxhU1Ulvli2WxxAumWGAJgunfWpdsFI0tK4M6N1e1r2xGd5Xgu3OtSxHZ41h4GLACxafyImySu9_wysNfdRr_j-FANYUNNWNO6U6UHPdFkqBfXOjF_aN7NfiYWNE44wd0dG7fbOGipsIuPR-KXuPDhiPMMp-kNffFZgPLOwKlLm8Nm1yKElweRe7bfaIPyqUK1Kg'; +import { config } from '../config'; interface IdGenerationRequest { programId: string; @@ -49,7 +47,7 @@ interface IdGenerationRequest { entityType: string; } -const request: IdGenerationRequest = { +const request = { programId: 'null', submitterId: 'null', submitterDonorId: 'null', @@ -91,32 +89,18 @@ export async function getId(req: IdGenerationRequest) { }, }; - console.log( - 'request params: ' + - req.programId + - ' - ' + - req.submitterId + - ' - ' + - req.submitterDonorId + - ' - ' + - req.testInterval + - ' - ' + - req.family_relative_id + - ' - ' + - req.comorbidityTypeCode + - ' - ' + - req.entityType, - ); try { const response = await axios.get( - `http://localhost:9001/${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, + // `http://localhost:9001/${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, + config.getConfig().tokenUrl() + + `${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, headers, ); console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); return parseInt(response.data.entityId); } catch (e) { console.log(e); - // do something here + throw Error('Error fetching ids'); } } @@ -128,8 +112,6 @@ export async function setEntityIdsForDonors(donors: Donor[]) { } export async function setEntityIds(donor: PartialDonor) { - // const programId = donor.programId as string; - // -- DONOR -- const donorId = await getId({ ...request, @@ -297,25 +279,15 @@ const getToken = memoize( }; const data = { grant_type: 'client_credentials', - client_id: 'clinical-service', - client_secret: 'top-secret', + client_id: config.getConfig().egoClientId(), + client_secret: config.getConfig().egoClientSecret(), }; - // const response = await axios.post('https://ego.argo-qa.cumulus.genomeinformatics.org/api/oauth/token', data, headers); - const response = await axios.get('http://localhost:9001/'); + const response = await axios.post(config.getConfig().tokenUrl(), data, headers); console.log('token response: ' + response.data.access_token); - return 'eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3MTI4NTEzNjYsImV4cCI6MTcxMjg2MjE2Niwic3ViIjoiZmU1MzVjNTAtOGNkYy00MmI4LTk4ZTctNzVjZWRjMDQwMDhmIiwiaXNzIjoiZWdvIiwianRpIjoiMGM5ZmQ5OTgtODU1MS00MjJjLWEwNTUtNDU0NDkwZDYyYzU5IiwiY29udGV4dCI6eyJzY29wZSI6WyJGSUxFU0VSVklDRS5XUklURSIsIkNMSU5JQ0FMU0VSVklDRS5SRUFEIiwiRklMRVNFUlZJQ0UuUkVBRCIsIlJEUEMtQ0EuUkVBRCIsIlBST0dSQU1TRVJWSUNFLlJFQUQiLCJSRFBDLWNvbGxhYi5SRUFEIiwiREMtUkVHSVNUUlkuV1JJVEUiLCJEQUNPLVJFVklFVy5SRUFEIiwiRElDVElPTkFSWS5XUklURSIsInNjb3JlLlJFQUQiLCJEQy1SRUdJU1RSWS5SRUFEIiwic29uZy5XUklURSIsInJvYi5SRUFEIiwiUFJPR1JBTURBVEEtRlVMTC1DQS5SRUFEIiwiRElDVElPTkFSWS5SRUFEIiwiREFDTy5SRUF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-DCvQ8T_TOR9IR23sxELK3tDgfJyMPSSkZR1MvlopL3akNhwzwVHOoMSOjhMbMrmSwXdCosEmDi6pbcdPzgW71fLfDO5JveEiFf6_arWPb3GuV5zj9EuJYTEaqCH2M_J7gHT0shu1AwAcdAkoHn6y-ywrxB0ge1340ywnPqd5-FuwhwhnU4gQppo6S9T5QRJfisziAP1RBwJSNC7IGT2DbodbJqYvC2h6hZzlGiHgDFOvPcvAOVw798qW3uWu_7jWpbg_w6sSOdhLOdcI_IslHDXr0_6ajegy0twjGINy6CPWSPdnzrktHsA'; - // response.data['access_token']; + response.data.access_token; }, { maxAge: ms('1d'), preFetch: true, }, ); - -// UK: idgen -// `http://localhost:9001/${req.programId}/${req.submitterDonorId}/${req.submitterSpecimenId}/${req.submitterSampleId}/${req.submitterPrimaryDiagnosisId}/${req.submitterTreatmentId}/${req.submitterFollowUpId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, - -// todo -// get ego token in memoizee -// handle error from getId api -// diff --git a/src/config.ts b/src/config.ts index d08134623..5ad93f87a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -41,6 +41,7 @@ export interface AppConfig { egoClientId(): string; egoClientSecret(): string; tokenUrl(): string; + idServiceUrl(): string; } class ConfigManager { diff --git a/src/decorators/index.ts b/src/decorators/index.ts index 6a37b307e..8e08d2efc 100644 --- a/src/decorators/index.ts +++ b/src/decorators/index.ts @@ -123,11 +123,13 @@ const scopeCheckGenerator = ( scopesGenerator(programId), request, response, - ); - if (unauthorizedResponse !== undefined) { + ); // REMOVE THIS + /*if (unauthorizedResponse !== undefined) { return unauthorizedResponse; - } - const result = originalMethod.apply(this, [request, response, next]); + }*/ const result = originalMethod.apply( + this, + [request, response, next], + ); return result; }; return descriptor; diff --git a/src/server.ts b/src/server.ts index bc7bd60d4..7a05da91e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -137,9 +137,11 @@ let server: Server; return process.env.EGO_URL || secrets.EGO_URL || ''; }, tokenUrl(): string { - // UK: idgen return process.env.TOKEN_URI || ''; }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, egoClientId(): string { return process.env.EGO_CLIENT_ID || secrets.EGO_CLIENT_ID || ''; }, diff --git a/src/submission/submission-api.ts b/src/submission/submission-api.ts index d9fd81056..a7ad514c4 100644 --- a/src/submission/submission-api.ts +++ b/src/submission/submission-api.ts @@ -313,7 +313,7 @@ class SubmissionController { // GQL Query Methods async commitActiveSubmissionData(programId: string, egoToken: string, versionId: string) { - queryHasProgramWriteAccess(programId, egoToken); + // queryHasProgramWriteAccess(programId, egoToken); // REMOVE THIS const submissionSystemDisabled = await persistedConfig.getSubmissionDisabledState(); if (submissionSystemDisabled) return; diff --git a/test/integration/clinical/clinical.spec.ts b/test/integration/clinical/clinical.spec.ts index 6a6fded2c..3482b6bae 100644 --- a/test/integration/clinical/clinical.spec.ts +++ b/test/integration/clinical/clinical.spec.ts @@ -169,6 +169,12 @@ describe('clinical Api', () => { egoUrl() { return ''; }, + tokenUrl(): string { + return process.env.TOKEN_URI || ''; + }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, egoClientId() { return ''; }, diff --git a/test/integration/submission/submission-schema-migration.spec.ts b/test/integration/submission/submission-schema-migration.spec.ts index 357a61cd4..48ed6631a 100644 --- a/test/integration/submission/submission-schema-migration.spec.ts +++ b/test/integration/submission/submission-schema-migration.spec.ts @@ -215,6 +215,12 @@ describe('schema migration api', () => { egoUrl() { return ''; }, + tokenUrl(): string { + return process.env.TOKEN_URI || ''; + }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, egoClientId() { return ''; }, diff --git a/test/integration/submission/submission.spec.ts b/test/integration/submission/submission.spec.ts index 499a8cf36..90d8c02f1 100644 --- a/test/integration/submission/submission.spec.ts +++ b/test/integration/submission/submission.spec.ts @@ -169,6 +169,12 @@ describe('Submission Api', () => { egoUrl() { return ''; }, + tokenUrl(): string { + return process.env.TOKEN_URI || ''; + }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, egoClientId() { return ''; }, diff --git a/test/performance-test/submission.spec.ts b/test/performance-test/submission.spec.ts index 6d9da9280..05b9b7a9e 100644 --- a/test/performance-test/submission.spec.ts +++ b/test/performance-test/submission.spec.ts @@ -157,6 +157,12 @@ describe('Submission Api', () => { egoUrl() { return ''; }, + tokenUrl(): string { + return process.env.TOKEN_URI || ''; + }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, egoClientId() { return ''; }, diff --git a/test/unit/decorator/decorator.spec.ts b/test/unit/decorator/decorator.spec.ts index 3b5942933..9a08f9d81 100644 --- a/test/unit/decorator/decorator.spec.ts +++ b/test/unit/decorator/decorator.spec.ts @@ -86,6 +86,12 @@ describe('decorator', () => { egoUrl() { return ''; }, + idServiceUrl(): string { + return process.env.ID_SERVICE_URL || ''; + }, + tokenUrl(): string { + return process.env.TOKEN_URI || ''; + }, egoClientId() { return ''; }, diff --git a/test/unit/submission/submission-to-clinical.spec.ts b/test/unit/submission/submission-to-clinical.spec.ts index 6c22e5544..b8d9272b5 100644 --- a/test/unit/submission/submission-to-clinical.spec.ts +++ b/test/unit/submission/submission-to-clinical.spec.ts @@ -133,10 +133,7 @@ describe('submission-to-clinical', () => { [deepFreeze.DeepReadonly>], Promise> >; - let updateDonorStub: sinon.SinonStub< - [deepFreeze.DeepReadonly], - Promise> - >; + let updateDonorStub: sinon.SinonStub<[Donor], Promise>>; let missingEntityRepoGetByProgramStub: sinon.SinonStub< [string], Promise> From f893255c27e21633fd5be468a21bd74a003330fd Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Mon, 29 Apr 2024 16:42:07 -0400 Subject: [PATCH 05/10] made changes to incorporate review feedback --- src/clinical/donor-repo.ts | 9 +- src/clinical/id-generator.ts | 180 ++++++++---------- src/decorators/index.ts | 10 +- src/server.ts | 2 +- src/submission/submission-api.ts | 2 +- src/utils.ts | 10 + test/integration/clinical/clinical.spec.ts | 2 +- .../submission-schema-migration.spec.ts | 2 +- .../integration/submission/submission.spec.ts | 2 +- test/performance-test/submission.spec.ts | 2 +- test/unit/decorator/decorator.spec.ts | 2 +- 11 files changed, 99 insertions(+), 124 deletions(-) diff --git a/src/clinical/donor-repo.ts b/src/clinical/donor-repo.ts index f13f23293..447930488 100644 --- a/src/clinical/donor-repo.ts +++ b/src/clinical/donor-repo.ts @@ -420,15 +420,12 @@ export const donorDao: DonorRepository = { const dnr = await setEntityIds(donor); const newDonor = new DonorModel(await setEntityIds(donor)); unsetIsNewFlagForUpdate(newDonor); - console.log('newDonor._id' + newDonor._id); await newDonor.save(); return F(MongooseUtils.toPojo(newDonor) as Donor); }, async updateAll(donors: Donor[]) { - console.log('donors array in updateAll2: ' + donors[0].submitterId); const newDonors = donors.map(async (donor) => { - // await someFunction(); const newDonor = new DonorModel(await setEntityIds(donor)); unsetIsNewFlagForUpdate(newDonor); return newDonor; @@ -436,8 +433,8 @@ export const donorDao: DonorRepository = { await Promise.all( newDonors.map((donor) => { - donor.then((d) => { - d.save(); + donor.then(async (d) => { + await d.save(); }); }), ); @@ -449,7 +446,7 @@ export const donorDao: DonorRepository = { ), ); - return result; // newDonors.map((donor) => donor.then((d) => { return F(MongooseUtils.toPojo(d) as Donor);}).then(res => res)); + return result; }, async create(donor: Partial) { diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index a208d8338..6e289318d 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -20,26 +20,18 @@ import axios from 'axios'; import memoize from 'memoizee'; import ms from 'ms'; -import { - Biomarker, - ClinicalInfo, - Comorbidity, - CompletionStats, - Donor, - Exposure, - FamilyHistory, - FollowUp, - PrimaryDiagnosis, - SchemaMetadata, - Specimen, - Treatment, -} from './clinical-entities'; +import { Donor } from './clinical-entities'; import { ClinicalEntitySchemaNames } from '../common-model/entities'; import { config } from '../config'; +import { Errors } from '../utils'; interface IdGenerationRequest { programId: string; - submitterId: any; + submitterSpecimenId: string; + submitterSampleId: string; + submitterPrimaryDiagnosisId: string; + submitterFollowUpId: string; + submitterTreatmentId: string; submitterDonorId: string; testInterval: string; family_relative_id: string; @@ -48,40 +40,23 @@ interface IdGenerationRequest { } const request = { - programId: 'null', - submitterId: 'null', - submitterDonorId: 'null', - testInterval: 'null', - family_relative_id: 'null', - comorbidityTypeCode: 'null', - entityType: 'null', + programId: '-', + submitterSpecimenId: '-', + submitterSampleId: '-', + submitterPrimaryDiagnosisId: '-', + submitterFollowUpId: '-', + submitterTreatmentId: '-', + submitterDonorId: '-', + testInterval: '-', + family_relative_id: '-', + comorbidityTypeCode: '-', + entityType: '-', }; -export interface PartialDonor { - _id?: string; - __v?: number; // mongodb property not being filtered out - createBy?: string; - schemaMetadata?: SchemaMetadata | undefined; - donorId?: number; - gender?: string; - submitterId?: string; - programId?: string; - specimens?: Array | undefined; - clinicalInfo?: ClinicalInfo; - primaryDiagnoses?: Array; - familyHistory?: Array; - comorbidity?: Array; - followUps?: Array; - treatments?: Array; - exposure?: Array; - biomarker?: Array; - createdAt?: string; - updatedAt?: string; - completionStats?: CompletionStats; -} +export interface PartialDonor extends Partial {} export async function getId(req: IdGenerationRequest) { - console.log('getId function called'); + console.log('getId function called: ' + req.submitterDonorId); const token = await getToken(); const headers = { headers: { @@ -90,17 +65,14 @@ export async function getId(req: IdGenerationRequest) { }; try { - const response = await axios.get( - // `http://localhost:9001/${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, - config.getConfig().tokenUrl() + - `${req.programId}/${req.submitterId}/${req.submitterDonorId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`, - headers, - ); + const url = + config.getConfig().idServiceUrl() + + `${req.programId}/${req.submitterDonorId}/${req.submitterSpecimenId}/${req.submitterSampleId}/${req.submitterPrimaryDiagnosisId}/${req.submitterFollowUpId}/${req.submitterTreatmentId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`; + const response = await axios.get(url, headers); console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); return parseInt(response.data.entityId); } catch (e) { - console.log(e); - throw Error('Error fetching ids'); + throw new Errors.IdGenerationError('Error sending request to ID service. Caused by: ' + e); } } @@ -112,11 +84,11 @@ export async function setEntityIdsForDonors(donors: Donor[]) { } export async function setEntityIds(donor: PartialDonor) { + const submitterDonorId = donor.submitterId as string; // -- DONOR -- const donorId = await getId({ ...request, programId: donor.programId as string, - submitterId: donor.submitterId as string, submitterDonorId: donor.submitterId as string, entityType: ClinicalEntitySchemaNames.DONOR, }); @@ -132,11 +104,11 @@ export async function setEntityIds(donor: PartialDonor) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: submitterId as string, + submitterSpecimenId: submitterId as string, + submitterDonorId, entityType: ClinicalEntitySchemaNames.SPECIMEN, }); specimen.specimenId = id; - console.log('specimen.specimenId: ' + specimen.specimenId); // -- SAMPLE -- const samples = specimen.samples; @@ -144,126 +116,120 @@ export async function setEntityIds(donor: PartialDonor) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: sample.submitterId as string, + submitterSampleId: sample.submitterId as string, + submitterSpecimenId: specimen.submitterId, + submitterDonorId, entityType: ClinicalEntitySchemaNames.REGISTRATION, }); sample.sampleId = id; - console.log('sample.sampleId: ' + sample.sampleId); } } } // -- BIOMARKER -- - // submitter_specimen_id if (donor.biomarker && donor.biomarker.length > 0) { - for (const bm of donor.biomarker) { - const submitterBiomarkerId = - bm.clinicalInfo.submitter_specimen_id?.toString() ?? - bm.clinicalInfo.submitter_primary_diagnosis_id?.toString() ?? - bm.clinicalInfo.submitter_follow_up_id?.toString() ?? - bm.clinicalInfo.submitter_treatment_id?.toString() ?? - 'null'; - + for (const biomarker of donor.biomarker) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: submitterBiomarkerId, - submitterDonorId: bm.clinicalInfo.submitter_donor_id as string, - testInterval: bm.clinicalInfo.test_interval as string, + submitterSpecimenId: biomarker.clinicalInfo.submitter_specimen_id?.toString() || '-', + submitterPrimaryDiagnosisId: + biomarker.clinicalInfo.submitter_primary_diagnosis_id?.toString() || '-', + submitterFollowUpId: biomarker.clinicalInfo.submitter_follow_up_id?.toString() || '-', + submitterTreatmentId: biomarker.clinicalInfo.submitter_treatment_id?.toString() || '-', + submitterDonorId, + testInterval: biomarker.clinicalInfo.test_interval?.toString() || '-', entityType: ClinicalEntitySchemaNames.BIOMARKER, }); - - bm.biomarkerId = id; - console.log('biomarkerId: ' + bm.biomarkerId); + biomarker.biomarkerId = id; } } // -- COMORBIDITY -- - // submitter_donor_id and comorbidity_type_code - UK-confirm if (donor.comorbidity && donor.comorbidity.length > 0) { - for (const cm of donor.comorbidity) { + for (const comorbidity of donor.comorbidity) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: cm.clinicalInfo.submitter_donor_id as string, - comorbidityTypeCode: cm.clinicalInfo.comorbidity_type_code as string, + submitterDonorId, + comorbidityTypeCode: comorbidity.clinicalInfo.comorbidity_type_code as string, entityType: ClinicalEntitySchemaNames.COMORBIDITY, }); - cm.comorbidityId = id; - console.log('comorbidityId: ' + cm.comorbidityId); + comorbidity.comorbidityId = id; } } // -- PRIMARY DIAGNOSIS -- if (donor.primaryDiagnoses && donor.primaryDiagnoses.length > 0) { - for (const p of donor.primaryDiagnoses) { + for (const primaryDiagnosis of donor.primaryDiagnoses) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: p.clinicalInfo.submitter_primary_diagnosis_id as string, + submitterPrimaryDiagnosisId: primaryDiagnosis.clinicalInfo + .submitter_primary_diagnosis_id as string, + submitterDonorId, entityType: ClinicalEntitySchemaNames.PRIMARY_DIAGNOSIS, }); - p.primaryDiagnosisId = id; - console.log('primaryDiagnosisId: ' + p.primaryDiagnosisId); + primaryDiagnosis.primaryDiagnosisId = id; } } // -- TREATMENT -- if (donor.treatments && donor.treatments.length > 0) { - for (const t of donor.treatments) { + for (const treatment of donor.treatments) { + const submitter_treatment_id = treatment.clinicalInfo?.submitter_treatment_id?.toString(); + const therapy_submitter_treatment_id = treatment.therapies[0]?.clinicalInfo?.submitter_treatment_id?.toString(); const id = await getId({ ...request, programId: donor.programId as string, - submitterId: t.clinicalInfo.submitter_treatment_id as string, + submitterTreatmentId: (!submitter_treatment_id + ? therapy_submitter_treatment_id + : submitter_treatment_id) as string, + submitterDonorId, entityType: ClinicalEntitySchemaNames.TREATMENT, }); - t.treatmentId = id; - console.log('treatmentId: ' + t.treatmentId); + treatment.treatmentId = id; } } // -- FAMILY HISTORY -- - // submitter_donor_id and family_relative_id - UK: confirm if (donor.familyHistory && donor.familyHistory.length > 0) { - for (const fh of donor.familyHistory) { + for (const familyHistory of donor.familyHistory) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: fh.clinicalInfo.submitter_donor_id as string, - family_relative_id: fh.clinicalInfo.family_relative_id as string, + submitterDonorId, + family_relative_id: familyHistory.clinicalInfo.family_relative_id as string, entityType: ClinicalEntitySchemaNames.FAMILY_HISTORY, }); - fh.familyHistoryId = id; - console.log('familyHistoryId: ' + fh.familyHistoryId); + familyHistory.familyHistoryId = id; } } // -- FOLLOW UP -- if (donor.followUps && donor.followUps.length > 0) { - for (const fl of donor.followUps) { + for (const followUp of donor.followUps) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: fl.clinicalInfo.submitter_follow_up_id as string, + submitterFollowUpId: followUp.clinicalInfo.submitter_follow_up_id as string, + submitterDonorId, entityType: ClinicalEntitySchemaNames.FOLLOW_UP, }); - fl.followUpId = id; - console.log('followUpId: ' + fl.followUpId); + followUp.followUpId = id; } } // -- EXPOSURE -- - // submitter_donor_id if (donor.exposure && donor.exposure.length > 0) { - for (const ex of donor.exposure) { + for (const exposure of donor.exposure) { const id = await getId({ ...request, programId: donor.programId as string, - submitterId: ex.clinicalInfo.submitter_donor_id as string, + submitterDonorId, entityType: ClinicalEntitySchemaNames.EXPOSURE, }); - ex.exposureId = id; - console.log('exposureId: ' + ex.exposureId); + exposure.exposureId = id; } } @@ -282,9 +248,13 @@ const getToken = memoize( client_id: config.getConfig().egoClientId(), client_secret: config.getConfig().egoClientSecret(), }; - const response = await axios.post(config.getConfig().tokenUrl(), data, headers); - console.log('token response: ' + response.data.access_token); - response.data.access_token; + try { + const url = config.getConfig().tokenUrl(); + const response = await axios.post(config.getConfig().tokenUrl(), data, headers); + response.data.access_token; + } catch (e) { + throw new Errors.IdGenerationError('Error fetching ego token. Caused by: ' + e); + } }, { maxAge: ms('1d'), diff --git a/src/decorators/index.ts b/src/decorators/index.ts index 8e08d2efc..6a37b307e 100644 --- a/src/decorators/index.ts +++ b/src/decorators/index.ts @@ -123,13 +123,11 @@ const scopeCheckGenerator = ( scopesGenerator(programId), request, response, - ); // REMOVE THIS - /*if (unauthorizedResponse !== undefined) { - return unauthorizedResponse; - }*/ const result = originalMethod.apply( - this, - [request, response, next], ); + if (unauthorizedResponse !== undefined) { + return unauthorizedResponse; + } + const result = originalMethod.apply(this, [request, response, next]); return result; }; return descriptor; diff --git a/src/server.ts b/src/server.ts index 7a05da91e..16d78292a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -137,7 +137,7 @@ let server: Server; return process.env.EGO_URL || secrets.EGO_URL || ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, idServiceUrl(): string { return process.env.ID_SERVICE_URL || ''; diff --git a/src/submission/submission-api.ts b/src/submission/submission-api.ts index a7ad514c4..d9fd81056 100644 --- a/src/submission/submission-api.ts +++ b/src/submission/submission-api.ts @@ -313,7 +313,7 @@ class SubmissionController { // GQL Query Methods async commitActiveSubmissionData(programId: string, egoToken: string, versionId: string) { - // queryHasProgramWriteAccess(programId, egoToken); // REMOVE THIS + queryHasProgramWriteAccess(programId, egoToken); const submissionSystemDisabled = await persistedConfig.getSubmissionDisabledState(); if (submissionSystemDisabled) return; diff --git a/src/utils.ts b/src/utils.ts index 99dbbcd5a..d601c3c7a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -125,6 +125,10 @@ export namespace ControllerUtils { return res.status(422).send({ message }); }; + export const unableToGenerateId = (res: Response, message: string): any => { + return res.status(500).send({ message }); + }; + export const invalidBatch = ( res: Response, batchErrors: SubmissionBatchError | SubmissionBatchError[], @@ -203,6 +207,12 @@ export namespace Errors { super(msg || `TSV file is formatted incorrectly`); } } + + export class IdGenerationError extends Error { + constructor(msg: string) { + super(msg); + } + } } export namespace MongooseUtils { diff --git a/test/integration/clinical/clinical.spec.ts b/test/integration/clinical/clinical.spec.ts index 3482b6bae..91fe13085 100644 --- a/test/integration/clinical/clinical.spec.ts +++ b/test/integration/clinical/clinical.spec.ts @@ -170,7 +170,7 @@ describe('clinical Api', () => { return ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, idServiceUrl(): string { return process.env.ID_SERVICE_URL || ''; diff --git a/test/integration/submission/submission-schema-migration.spec.ts b/test/integration/submission/submission-schema-migration.spec.ts index 48ed6631a..48b39e0f8 100644 --- a/test/integration/submission/submission-schema-migration.spec.ts +++ b/test/integration/submission/submission-schema-migration.spec.ts @@ -216,7 +216,7 @@ describe('schema migration api', () => { return ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, idServiceUrl(): string { return process.env.ID_SERVICE_URL || ''; diff --git a/test/integration/submission/submission.spec.ts b/test/integration/submission/submission.spec.ts index 90d8c02f1..9ee553177 100644 --- a/test/integration/submission/submission.spec.ts +++ b/test/integration/submission/submission.spec.ts @@ -170,7 +170,7 @@ describe('Submission Api', () => { return ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, idServiceUrl(): string { return process.env.ID_SERVICE_URL || ''; diff --git a/test/performance-test/submission.spec.ts b/test/performance-test/submission.spec.ts index 05b9b7a9e..69fa657cb 100644 --- a/test/performance-test/submission.spec.ts +++ b/test/performance-test/submission.spec.ts @@ -158,7 +158,7 @@ describe('Submission Api', () => { return ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, idServiceUrl(): string { return process.env.ID_SERVICE_URL || ''; diff --git a/test/unit/decorator/decorator.spec.ts b/test/unit/decorator/decorator.spec.ts index 9a08f9d81..4e646cd9d 100644 --- a/test/unit/decorator/decorator.spec.ts +++ b/test/unit/decorator/decorator.spec.ts @@ -90,7 +90,7 @@ describe('decorator', () => { return process.env.ID_SERVICE_URL || ''; }, tokenUrl(): string { - return process.env.TOKEN_URI || ''; + return process.env.TOKEN_URL || ''; }, egoClientId() { return ''; From 1a7ff2917e8d88f390b904130ac1ae79aeee2e7d Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Tue, 11 Jun 2024 12:54:01 -0400 Subject: [PATCH 06/10] pkg json update --- package-lock.json | 268 ++++++++++++++++++++++++++++++++++++++-------- package.json | 5 + 2 files changed, 226 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 87cbfa3e2..3683ac101 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "adm-zip": "^0.4.16", "apollo-server-core": "^3.12.0", "async": "^3.0.1", + "axios": "^1.6.7", "bcrypt-nodejs": "^0.0.3", "bluebird": "^3.5.5", "body-parser": "^1.19.0", @@ -36,6 +37,7 @@ "kafkajs": "^1.12.0", "kind-of": "^6.0.3", "lodash": "^4.17.21", + "memoizee": "^0.4.17", "migrate-mongo": "^8.2.3", "mock-http-server": "^1.4.1", "mongoose": "^5.13.14", @@ -43,6 +45,7 @@ "mongoose-sequence": "^5.2.2", "morgan": "^1.10.0", "mquery": ">=3.2.3", + "ms": "^2.1.3", "multer": "^1.4.2", "mysql": "^2.18.1", "node-fetch": "^2.6.7", @@ -77,12 +80,14 @@ "@types/express-serve-static-core": "4.16.7", "@types/jsonwebtoken": "^8.3.2", "@types/lodash": "^4.14.134", + "@types/memoizee": "^0.4.11", "@types/migrate-mongo": "^7.0.0", "@types/mocha": "^9.1.1", "@types/mongodb": "^3.1.28", "@types/mongoose": "^5.11.97", "@types/mongoose-sequence": "^3.0.3", "@types/morgan": "^1.7.35", + "@types/ms": "^0.7.34", "@types/multer": "^1.3.7", "@types/mysql": "^2.15.9", "@types/node": "^12.0.10", @@ -542,11 +547,6 @@ "node": ">=12" } }, - "node_modules/@apollo/server/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - }, "node_modules/@apollo/server/node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -1072,11 +1072,6 @@ "triple-beam": "^1.3.0" } }, - "node_modules/@overturebio-stack/lectern-client/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - }, "node_modules/@overturebio-stack/lectern-client/node_modules/node-worker-threads-pool": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/node-worker-threads-pool/-/node-worker-threads-pool-1.5.1.tgz", @@ -1570,6 +1565,12 @@ "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==" }, + "node_modules/@types/memoizee": { + "version": "0.4.11", + "resolved": "https://registry.npmjs.org/@types/memoizee/-/memoizee-0.4.11.tgz", + "integrity": "sha512-2gyorIBZu8GoDr9pYjROkxWWcFtHCquF7TVbN2I+/OvgZhnIGQS0vX5KJz4lXNKb8XOSfxFOSG5OLru1ESqLUg==", + "dev": true + }, "node_modules/@types/migrate-mongo": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@types/migrate-mongo/-/migrate-mongo-7.0.0.tgz", @@ -1650,6 +1651,12 @@ "@types/express": "*" } }, + "node_modules/@types/ms": { + "version": "0.7.34", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", + "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==", + "dev": true + }, "node_modules/@types/multer": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.3.7.tgz", @@ -2370,6 +2377,29 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, + "node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -3731,6 +3761,18 @@ "resolved": "https://registry.npmjs.org/cssfilter/-/cssfilter-0.0.10.tgz", "integrity": "sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw==" }, + "node_modules/d": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", + "dependencies": { + "es5-ext": "^0.10.64", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -3763,6 +3805,11 @@ "ms": "2.0.0" } }, + "node_modules/debug/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, "node_modules/decamelize": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", @@ -3943,12 +3990,6 @@ "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", "dev": true }, - "node_modules/docker-modem/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/docker-modem/node_modules/readable-stream": { "version": "1.0.34", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", @@ -4102,6 +4143,54 @@ "node": ">= 0.8" } }, + "node_modules/es5-ext": { + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", + "hasInstallScript": true, + "dependencies": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", + "next-tick": "^1.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "node_modules/es6-symbol": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", + "dependencies": { + "d": "^1.0.2", + "ext": "^1.7.0" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/es6-weak-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -4134,6 +4223,20 @@ "node": ">=0.8.0" } }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -4164,6 +4267,15 @@ "node": ">= 0.6" } }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "node_modules/execa": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", @@ -4279,6 +4391,14 @@ "node": ">= 8.0.0" } }, + "node_modules/ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "dependencies": { + "type": "^2.7.2" + } + }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -4402,6 +4522,25 @@ "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -5133,6 +5272,11 @@ "node": ">=8" } }, + "node_modules/is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "node_modules/is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -5291,11 +5435,6 @@ "npm": ">=1.4.28" } }, - "node_modules/jsonwebtoken/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, "node_modules/jsprim": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", @@ -5557,11 +5696,6 @@ "triple-beam": "^1.3.0" } }, - "node_modules/logform/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, "node_modules/loglevel": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", @@ -5604,6 +5738,14 @@ "yallist": "^2.1.2" } }, + "node_modules/lru-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", + "integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==", + "dependencies": { + "es5-ext": "~0.10.2" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -5641,6 +5783,24 @@ "node": ">= 0.6" } }, + "node_modules/memoizee": { + "version": "0.4.17", + "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.17.tgz", + "integrity": "sha512-DGqD7Hjpi/1or4F/aYAspXKNm5Yili0QDAFAY4QYvpqpgiY6+1jOfqpmByzjxbWd/T9mChbCArXAbDAsTm5oXA==", + "dependencies": { + "d": "^1.0.2", + "es5-ext": "^0.10.64", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/memory-pager": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", @@ -5926,12 +6086,6 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/mocha/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/mocha/node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -6275,9 +6429,9 @@ } }, "node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/multer": { "version": "1.4.2", @@ -6386,6 +6540,11 @@ "node": ">= 0.6" } }, + "node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -6470,6 +6629,11 @@ "ms": "2.0.0" } }, + "node_modules/node-vault/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, "node_modules/node-worker-threads-pool": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/node-worker-threads-pool/-/node-worker-threads-pool-1.2.2.tgz", @@ -6521,12 +6685,6 @@ "ms": "^2.1.1" } }, - "node_modules/nodemon/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/nodemon/node_modules/semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -7131,6 +7289,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -7958,12 +8121,6 @@ "ms": "^2.1.1" } }, - "node_modules/superagent/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -8143,6 +8300,18 @@ "xtend": "~4.0.1" } }, + "node_modules/timers-ext": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.8.tgz", + "integrity": "sha512-wFH7+SEAcKfJpfLPkrgMPvvwnEtj8W4IurvEyrKsDleXnKLCDw71w8jltvfLa8Rm4qQxxT4jmDBYbJG/z7qoww==", + "dependencies": { + "es5-ext": "^0.10.64", + "next-tick": "^1.1.0" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/to-buffer": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", @@ -8341,6 +8510,11 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, + "node_modules/type": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", + "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==" + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", diff --git a/package.json b/package.json index 33d736e77..80a8b99f9 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "@types/express-serve-static-core": "4.16.7", "@types/jsonwebtoken": "^8.3.2", "@types/lodash": "^4.14.134", + "@types/memoizee": "^0.4.11", "@types/migrate-mongo": "^7.0.0", "@types/mocha": "^9.1.1", "@types/mongodb": "^3.1.28", @@ -66,6 +67,7 @@ "@types/morgan": "^1.7.35", "@types/multer": "^1.3.7", "@types/mysql": "^2.15.9", + "@types/ms": "^0.7.34", "@types/node": "^12.0.10", "@types/node-fetch": "^2.5.0", "@types/node-vault": "^0.9.0", @@ -105,6 +107,7 @@ "adm-zip": "^0.4.16", "apollo-server-core": "^3.12.0", "async": "^3.0.1", + "axios": "^1.6.7", "bcrypt-nodejs": "^0.0.3", "bluebird": "^3.5.5", "body-parser": "^1.19.0", @@ -124,6 +127,7 @@ "kafkajs": "^1.12.0", "kind-of": "^6.0.3", "lodash": "^4.17.21", + "memoizee": "^0.4.17", "migrate-mongo": "^8.2.3", "mock-http-server": "^1.4.1", "mongoose": "^5.13.14", @@ -132,6 +136,7 @@ "morgan": "^1.10.0", "mquery": ">=3.2.3", "multer": "^1.4.2", + "ms": "^2.1.3", "mysql": "^2.18.1", "node-fetch": "^2.6.7", "node-vault": "^0.9.11", From 7221bbcf2e2a726de52164eceff3ddf001fe3063 Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Sun, 23 Jun 2024 19:45:14 -0400 Subject: [PATCH 07/10] missing return statement --- src/clinical/id-generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 6e289318d..7fad1f112 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -251,7 +251,7 @@ const getToken = memoize( try { const url = config.getConfig().tokenUrl(); const response = await axios.post(config.getConfig().tokenUrl(), data, headers); - response.data.access_token; + return response.data.access_token; } catch (e) { throw new Errors.IdGenerationError('Error fetching ego token. Caused by: ' + e); } From cb48085a8dce2ce9fc9487fb5852f7a480de33f6 Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Sun, 23 Jun 2024 23:25:28 -0400 Subject: [PATCH 08/10] changed some error handling during id generation --- src/clinical/id-generator.ts | 12 ++++++++---- src/utils.ts | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 7fad1f112..412663bc9 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -64,16 +64,20 @@ export async function getId(req: IdGenerationRequest) { }, }; + let response; try { const url = config.getConfig().idServiceUrl() + `${req.programId}/${req.submitterDonorId}/${req.submitterSpecimenId}/${req.submitterSampleId}/${req.submitterPrimaryDiagnosisId}/${req.submitterFollowUpId}/${req.submitterTreatmentId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`; - const response = await axios.get(url, headers); + response = await axios.get(url, headers); console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); - return parseInt(response.data.entityId); } catch (e) { - throw new Errors.IdGenerationError('Error sending request to ID service. Caused by: ' + e); + throw new Errors.NetworkError('Error sending request to ID service. Caused by: ' + e); } + if (!response.data.entityId) { + throw new Errors.IdGenerationError('Error generating entity ids.'); + } + return parseInt(response.data.entityId); } export async function setEntityIdsForDonors(donors: Donor[]) { @@ -253,7 +257,7 @@ const getToken = memoize( const response = await axios.post(config.getConfig().tokenUrl(), data, headers); return response.data.access_token; } catch (e) { - throw new Errors.IdGenerationError('Error fetching ego token. Caused by: ' + e); + throw new Errors.NetworkError('Error fetching ego token. Caused by: ' + e); } }, { diff --git a/src/utils.ts b/src/utils.ts index d601c3c7a..c75d972cb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -213,6 +213,11 @@ export namespace Errors { super(msg); } } + export class NetworkError extends Error { + constructor(msg: string) { + super(msg); + } + } } export namespace MongooseUtils { From 79d9f6be0e7e5595ee19b95010ef56d67152e318 Mon Sep 17 00:00:00 2001 From: UmmulkiramR Date: Mon, 12 Aug 2024 09:06:45 -0400 Subject: [PATCH 09/10] review updates --- package-lock.json | 10 +++++ package.json | 5 ++- src/clinical/id-generator.ts | 76 ++++++++++++++++++++---------------- src/utils.ts | 2 +- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3683ac101..6e04d8ae0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "promise-tools": "^2.1.0", "response-time": "^2.3.2", "swagger-ui-express": "^4.3.0", + "url-join": "^5.0.0", "winston": "^3.2.1", "yamljs": "^0.3.0", "zod": "^3.21.4" @@ -8769,6 +8770,15 @@ "punycode": "^2.1.0" } }, + "node_modules/url-join": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-5.0.0.tgz", + "integrity": "sha512-n2huDr9h9yzd6exQVnH/jU5mr+Pfx08LRXXZhkLLetAMESRj+anQsTAh940iMrIetKAmry9coFuZQ2jY8/p3WA==", + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/url-parse-lax": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", diff --git a/package.json b/package.json index 80a8b99f9..12b7880f3 100644 --- a/package.json +++ b/package.json @@ -65,9 +65,9 @@ "@types/mongoose": "^5.11.97", "@types/mongoose-sequence": "^3.0.3", "@types/morgan": "^1.7.35", + "@types/ms": "^0.7.34", "@types/multer": "^1.3.7", "@types/mysql": "^2.15.9", - "@types/ms": "^0.7.34", "@types/node": "^12.0.10", "@types/node-fetch": "^2.5.0", "@types/node-vault": "^0.9.0", @@ -135,8 +135,8 @@ "mongoose-sequence": "^5.2.2", "morgan": "^1.10.0", "mquery": ">=3.2.3", - "multer": "^1.4.2", "ms": "^2.1.3", + "multer": "^1.4.2", "mysql": "^2.18.1", "node-fetch": "^2.6.7", "node-vault": "^0.9.11", @@ -145,6 +145,7 @@ "promise-tools": "^2.1.0", "response-time": "^2.3.2", "swagger-ui-express": "^4.3.0", + "url-join": "^5.0.0", "winston": "^3.2.1", "yamljs": "^0.3.0", "zod": "^3.21.4" diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 412663bc9..3bf539a29 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -24,19 +24,27 @@ import { Donor } from './clinical-entities'; import { ClinicalEntitySchemaNames } from '../common-model/entities'; import { config } from '../config'; import { Errors } from '../utils'; +import urlJoin from 'url-join'; interface IdGenerationRequest { - programId: string; - submitterSpecimenId: string; - submitterSampleId: string; - submitterPrimaryDiagnosisId: string; - submitterFollowUpId: string; - submitterTreatmentId: string; - submitterDonorId: string; - testInterval: string; - family_relative_id: string; - comorbidityTypeCode: string; - entityType: string; + programId: string | undefined; + submitterSpecimenId: string | number | boolean | string[] | number[] | boolean[] | undefined; + submitterSampleId: string | undefined; + submitterPrimaryDiagnosisId: + | string + | number + | boolean + | string[] + | number[] + | boolean[] + | undefined; + submitterFollowUpId: string | number | boolean | string[] | number[] | boolean[] | undefined; + submitterTreatmentId: string | undefined; + submitterDonorId: string | undefined; + testInterval: string | undefined; + family_relative_id: string | number | boolean | string[] | number[] | boolean[] | undefined; + comorbidityTypeCode: string | number | boolean | string[] | number[] | boolean[] | undefined; + entityType: string | undefined; } const request = { @@ -53,7 +61,7 @@ const request = { entityType: '-', }; -export interface PartialDonor extends Partial {} +// export interface PartialDonor extends Partial {} export async function getId(req: IdGenerationRequest) { console.log('getId function called: ' + req.submitterDonorId); @@ -69,6 +77,7 @@ export async function getId(req: IdGenerationRequest) { const url = config.getConfig().idServiceUrl() + `${req.programId}/${req.submitterDonorId}/${req.submitterSpecimenId}/${req.submitterSampleId}/${req.submitterPrimaryDiagnosisId}/${req.submitterFollowUpId}/${req.submitterTreatmentId}/${req.testInterval}/${req.family_relative_id}/${req.comorbidityTypeCode}/${req.entityType}`; + response = await axios.get(url, headers); console.log('getId response: ' + response.data.entityId + ' - ' + response.data.entityType); } catch (e) { @@ -87,13 +96,13 @@ export async function setEntityIdsForDonors(donors: Donor[]) { return await Promise.all(donorsWithIds); } -export async function setEntityIds(donor: PartialDonor) { - const submitterDonorId = donor.submitterId as string; +export async function setEntityIds(donor: Partial) { + const submitterDonorId = donor.submitterId; // -- DONOR -- const donorId = await getId({ ...request, - programId: donor.programId as string, - submitterDonorId: donor.submitterId as string, + programId: donor.programId, + submitterDonorId: donor.submitterId, entityType: ClinicalEntitySchemaNames.DONOR, }); donor.donorId = donorId; @@ -107,8 +116,8 @@ export async function setEntityIds(donor: PartialDonor) { : specimen.clinicalInfo.submitter_specimen_id; const id = await getId({ ...request, - programId: donor.programId as string, - submitterSpecimenId: submitterId as string, + programId: donor.programId, + submitterSpecimenId: submitterId, submitterDonorId, entityType: ClinicalEntitySchemaNames.SPECIMEN, }); @@ -119,8 +128,8 @@ export async function setEntityIds(donor: PartialDonor) { for (const sample of samples) { const id = await getId({ ...request, - programId: donor.programId as string, - submitterSampleId: sample.submitterId as string, + programId: donor.programId, + submitterSampleId: sample.submitterId, submitterSpecimenId: specimen.submitterId, submitterDonorId, entityType: ClinicalEntitySchemaNames.REGISTRATION, @@ -135,7 +144,7 @@ export async function setEntityIds(donor: PartialDonor) { for (const biomarker of donor.biomarker) { const id = await getId({ ...request, - programId: donor.programId as string, + programId: donor.programId, submitterSpecimenId: biomarker.clinicalInfo.submitter_specimen_id?.toString() || '-', submitterPrimaryDiagnosisId: biomarker.clinicalInfo.submitter_primary_diagnosis_id?.toString() || '-', @@ -154,9 +163,9 @@ export async function setEntityIds(donor: PartialDonor) { for (const comorbidity of donor.comorbidity) { const id = await getId({ ...request, - programId: donor.programId as string, + programId: donor.programId, submitterDonorId, - comorbidityTypeCode: comorbidity.clinicalInfo.comorbidity_type_code as string, + comorbidityTypeCode: comorbidity.clinicalInfo.comorbidity_type_code, entityType: ClinicalEntitySchemaNames.COMORBIDITY, }); comorbidity.comorbidityId = id; @@ -168,9 +177,8 @@ export async function setEntityIds(donor: PartialDonor) { for (const primaryDiagnosis of donor.primaryDiagnoses) { const id = await getId({ ...request, - programId: donor.programId as string, - submitterPrimaryDiagnosisId: primaryDiagnosis.clinicalInfo - .submitter_primary_diagnosis_id as string, + programId: donor.programId, + submitterPrimaryDiagnosisId: primaryDiagnosis.clinicalInfo.submitter_primary_diagnosis_id, submitterDonorId, entityType: ClinicalEntitySchemaNames.PRIMARY_DIAGNOSIS, }); @@ -185,10 +193,10 @@ export async function setEntityIds(donor: PartialDonor) { const therapy_submitter_treatment_id = treatment.therapies[0]?.clinicalInfo?.submitter_treatment_id?.toString(); const id = await getId({ ...request, - programId: donor.programId as string, - submitterTreatmentId: (!submitter_treatment_id + programId: donor.programId, + submitterTreatmentId: !submitter_treatment_id ? therapy_submitter_treatment_id - : submitter_treatment_id) as string, + : submitter_treatment_id, submitterDonorId, entityType: ClinicalEntitySchemaNames.TREATMENT, }); @@ -201,9 +209,9 @@ export async function setEntityIds(donor: PartialDonor) { for (const familyHistory of donor.familyHistory) { const id = await getId({ ...request, - programId: donor.programId as string, + programId: donor.programId, submitterDonorId, - family_relative_id: familyHistory.clinicalInfo.family_relative_id as string, + family_relative_id: familyHistory.clinicalInfo.family_relative_id, entityType: ClinicalEntitySchemaNames.FAMILY_HISTORY, }); familyHistory.familyHistoryId = id; @@ -215,8 +223,8 @@ export async function setEntityIds(donor: PartialDonor) { for (const followUp of donor.followUps) { const id = await getId({ ...request, - programId: donor.programId as string, - submitterFollowUpId: followUp.clinicalInfo.submitter_follow_up_id as string, + programId: donor.programId, + submitterFollowUpId: followUp.clinicalInfo.submitter_follow_up_id, submitterDonorId, entityType: ClinicalEntitySchemaNames.FOLLOW_UP, }); @@ -229,7 +237,7 @@ export async function setEntityIds(donor: PartialDonor) { for (const exposure of donor.exposure) { const id = await getId({ ...request, - programId: donor.programId as string, + programId: donor.programId, submitterDonorId, entityType: ClinicalEntitySchemaNames.EXPOSURE, }); diff --git a/src/utils.ts b/src/utils.ts index c75d972cb..6219feee2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -125,7 +125,7 @@ export namespace ControllerUtils { return res.status(422).send({ message }); }; - export const unableToGenerateId = (res: Response, message: string): any => { + export const unableToGenerateId = (res: Response, message: string) => { return res.status(500).send({ message }); }; From 40e926ed6ab3bc13ccac40c0448e272068a23386 Mon Sep 17 00:00:00 2001 From: Ummulkiram <57347898+UmmulkiramR@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:48:11 -0400 Subject: [PATCH 10/10] Update src/clinical/id-generator.ts Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com> --- src/clinical/id-generator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clinical/id-generator.ts b/src/clinical/id-generator.ts index 3bf539a29..2680de2db 100644 --- a/src/clinical/id-generator.ts +++ b/src/clinical/id-generator.ts @@ -61,7 +61,6 @@ const request = { entityType: '-', }; -// export interface PartialDonor extends Partial {} export async function getId(req: IdGenerationRequest) { console.log('getId function called: ' + req.submitterDonorId);