Skip to content

Commit

Permalink
feat: add updateStatusByQuery for MwlItemModel instead findAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 22, 2024
1 parent 46031c9 commit db9e488
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ class ChangeFilteredMwlItemStatusService extends BaseQueryService {

async changeMwlItemsStatus() {
let { status } = this.request.params;
let mwlItems = await this.getMwlItems();
if (mwlItems.length === 0) {
throw new DicomWebServiceError(DicomWebStatusCodes.NoSuchObjectInstance, "Can not found any MWL item from query", 404);
}

for (let mwlItem of mwlItems) {
_.set(mwlItem, `${dictionary.keyword.ScheduledProcedureStepSequence}.Value.0.${dictionary.keyword.ScheduledProcedureStepStatus}.Value.0`, status);
await mwlItem.save();
}
let updatedCount = await MwlItemModel.updateStatusByQuery(this.query, status);

return mwlItems.length;
}

async getMwlItems() {
return await MwlItemModel.findMwlItems(this.query);
return updatedCount;
}
}

Expand Down
11 changes: 10 additions & 1 deletion models/mongodb/models/mwlitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ let mwlItemSchema = new mongoose.Schema(
});
return await mwlItem.save();
},
findMwlItems: async function(query) {
updateStatusByQuery: async function (query, status) {
let mongoQuery = (await convertRequestQueryToMongoQuery(query)).$match;
let updateResult = await mongoose.model("mwlItems").updateMany(mongoQuery, {
$set: {
[`${dictionary.keyword.ScheduledProcedureStepSequence.tag}.Value.0.${dictionary.keyword.ScheduledProcedureStepStatus.tag}.Value.0`]: status
}
}).exec();
return updateResult.modifiedCount;
},
findMwlItems: async function (query) {
let mongoQuery = await convertRequestQueryToMongoQuery(query);
return await mongoose.model("mwlItems").find(mongoQuery);
}
Expand Down

0 comments on commit db9e488

Please sign in to comment.