-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clinical id service integration #1176
base: develop
Are you sure you want to change the base?
Changes from 4 commits
dddca11
c4b472d
1ae27f8
ec4a991
f893255
5bcf37b
1a7ff29
7221bbc
cb48085
79d9f6b
40e926e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, setEntityIdsForDonors } from './id-generator'; | ||
|
||
export const SUBMITTER_ID = 'submitterId'; | ||
export const SPECIMEN_SUBMITTER_ID = 'specimen.submitterId'; | ||
|
@@ -109,20 +110,22 @@ export interface DonorRepository { | |
): Promise<DeepReadonly<Donor> | undefined>; | ||
iterateAllByProgramId(programId: string): AsyncIterable<DeepReadonly<Donor>>; | ||
create(donor: DeepReadonly<Partial<Donor>>): Promise<DeepReadonly<Donor>>; | ||
update(donor: DeepReadonly<Donor>): Promise<DeepReadonly<Donor>>; | ||
updateAll(donors: DeepReadonly<Donor>[]): Promise<DeepReadonly<Donor>[]>; | ||
update(donor: Donor): Promise<DeepReadonly<Donor>>; | ||
updateAll(donors: Donor[]): Promise<DeepReadonly<Donor>[]>; | ||
countBy(filter: any): Promise<number>; | ||
} | ||
|
||
// Mongoose implementation of the DonorRepository | ||
export const donorDao: DonorRepository = { | ||
async insertDonors(donors: Donor[]) { | ||
await mongoose.connection.db.collection('donors').insertMany(donors); | ||
const donorsWithIds = await setEntityIdsForDonors(donors); | ||
await mongoose.connection.db.collection('donors').insertMany(donorsWithIds); | ||
}, | ||
async updateDonor(donor: Donor) { | ||
const donorsWithIds = await setEntityIds(donor); | ||
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(); | ||
|
@@ -413,27 +416,44 @@ export const donorDao: DonorRepository = { | |
return iterateAllByProgramId(programId); | ||
}, | ||
|
||
async update(donor: DeepReadonly<Donor>) { | ||
const newDonor = new DonorModel(donor); | ||
async update(donor: Donor) { | ||
const dnr = await setEntityIds(donor); | ||
const newDonor = new DonorModel(await setEntityIds(donor)); | ||
unsetIsNewFlagForUpdate(newDonor); | ||
|
||
console.log('newDonor._id' + newDonor._id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a lot of console.logs added and I'm not sure which are intentional and which are left over from testing It would be good to replace those you want to keep with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed all console logs. |
||
await newDonor.save(); | ||
return F(MongooseUtils.toPojo(newDonor) as Donor); | ||
}, | ||
|
||
async updateAll(donors: DeepReadonly<Donor>[]) { | ||
const newDonors = donors.map((donor) => { | ||
const newDonor = new DonorModel(donor); | ||
async updateAll(donors: Donor[]) { | ||
console.log('donors array in updateAll2: ' + donors[0].submitterId); | ||
const newDonors = donors.map(async (donor) => { | ||
// await someFunction(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused commented code to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. removed. |
||
const newDonor = new DonorModel(await setEntityIds(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)); | ||
await Promise.all( | ||
newDonors.map((donor) => { | ||
donor.then((d) => { | ||
d.save(); | ||
}); | ||
}), | ||
); | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well |
||
}, | ||
|
||
async create(donor: DeepReadonly<Donor>) { | ||
const newDonor = new DonorModel(donor); | ||
async create(donor: Partial<Donor>) { | ||
const newDonor = new DonorModel(await setEntityIds(donor)); | ||
const doc = await newDonor.save(); | ||
return F(MongooseUtils.toPojo(newDonor) as Donor); | ||
}, | ||
|
@@ -656,58 +676,9 @@ 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, { | ||
inc_field: 'donorId', | ||
start_seq: process.env.DONOR_ID_SEED || 250000, | ||
}); | ||
|
||
DonorSchema.plugin(mongoosePaginate); | ||
|
||
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, | ||
}); | ||
|
||
export let DonorModel = mongoose.model<DonorDocument>('Donor', DonorSchema) as PaginateModel< | ||
DonorDocument | ||
>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both
setEntityIds
functions throw errors when network errors occur, should there be some sort of error handling here to handle failures or is this now expected to be handled by the caller ofupdateDonor
andinsertDonors
?