Skip to content

Commit

Permalink
docs(type): add types for MwlItemModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 25, 2024
1 parent 2e4795a commit 7ab1e0b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
42 changes: 34 additions & 8 deletions models/mongodb/models/mwlitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ let mwlItemSchema = new mongoose.Schema(
getters: true
},
statics: {
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["getDimseResultCursor"] }
*/
getDimseResultCursor: async function (query, keys) {
return mongoose.model("mwlItems").find(query, keys).setOptions({
strictQuery: false
})
.cursor();
},
/**
*
* @param {import("@root/utils/typeDef/dicom").DicomJsonQueryOptions} queryOptions
* @returns
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["getDicomJson"] }
*/
getDicomJson: async function (queryOptions) {
let projection = mongoose.model("mwlItems").getDicomJsonProjection(queryOptions.includeFields);
Expand All @@ -60,10 +61,16 @@ let mwlItemSchema = new mongoose.Schema(
let includeFieldsFactory = new IncludeFieldsFactory(includeFields);
return includeFieldsFactory.getMwlLevelFields();
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["getCount"] }
*/
getCount: async function (query) {
let mongoQuery = await convertRequestQueryToMongoQuery(query);
return await mongoose.model("mwlItems").countDocuments(mongoQuery);
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["deleteByStudyInstanceUIDAndSpsID"] }
*/
deleteByStudyInstanceUIDAndSpsID: async function (studyUID, spsID) {
return await mongoose.model("mwlItems").deleteMany({
$and: [
Expand All @@ -77,9 +84,7 @@ let mwlItemSchema = new mongoose.Schema(
});
},
/**
*
* @param {string} studyUID
* @param {string} spsID
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["findOneByStudyInstanceUIDAndSpsID"] }
*/
findOneByStudyInstanceUIDAndSpsID: async function (studyUID, spsID) {
return await mongoose.model("mwlItems").findOne({
Expand All @@ -93,16 +98,25 @@ let mwlItemSchema = new mongoose.Schema(
]
});
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["createWithGeneralDicomJson"] }
*/
createWithGeneralDicomJson: async function (generalDicomJson) {
let mwlItemModelObj = new mongoose.model("mwlItems")(generalDicomJson);
return await mwlItemModelObj.save();
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["updateOneWithGeneralDicomJson"] }
*/
updateOneWithGeneralDicomJson: async function (mwlItem, generalDicomJson) {
mwlItem.$set({
...generalDicomJson
});
return await mwlItem.save();
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["updateStatusByQuery"] }
*/
updateStatusByQuery: async function (query, status) {
let mongoQuery = (await convertRequestQueryToMongoQuery(query)).$match;
let updateResult = await mongoose.model("mwlItems").updateMany(mongoQuery, {
Expand All @@ -112,28 +126,39 @@ let mwlItemSchema = new mongoose.Schema(
}).exec();
return updateResult.modifiedCount;
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor["findMwlItems"] }
*/
findMwlItems: async function (query) {
let mongoQuery = await convertRequestQueryToMongoQuery(query);
return await mongoose.model("mwlItems").find(mongoQuery);
}
},
methods: {
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModel["toGeneralDicomJson"] }
*/
toGeneralDicomJson: async function () {
let obj = this.toObject();
delete obj._id;
delete obj.id;
return obj;
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModel["toDicomJson"] }
*/
toDicomJson: async function () {
return new BaseDicomJson(await this.toGeneralDicomJson());
},
/**
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModel["getAttributes"] }
*/
getAttributes: async function () {
let jsonStr = JSON.stringify(this.toDicomJson());
return await Common.getAttributesFromJsonString(jsonStr);
},
/**
*
* @param {"SCHEDULED" | "ARRIVED" | "READY" | "STARTED" | "DEPARTED" | "CANCELED" | "DISCONTINUED" | "COMPLETED"} status
* @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModel["updateStatus"] }
*/
updateStatus: async function (status) {
this.$set(`${dictionary.keyword.ScheduledProcedureStepSequence}.Value.0.${dictionary.keyword.ScheduledProcedureStepStatus}.Value.0`, status);
Expand Down Expand Up @@ -166,4 +191,5 @@ let mwlItemModel = mongoose.model(
);

module.exports = mwlItemModel;
/** @type { import("@root/utils/typeDef/models/mwlitem").MwlItemModelConstructor } */
module.exports.MwlItemModel = mwlItemModel;
58 changes: 58 additions & 0 deletions utils/typeDef/models/mwlitem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { BaseDicomJson } from "@models/DICOM/dicom-json-model";
import type { GeneralDicomJson } from "../dicom";

export type MwlItemStatus =
| "SCHEDULED"
| "ARRIVED"
| "READY"
| "STARTED"
| "DEPARTED"
| "CANCELED"
| "DISCONTINUED"
| "COMPLETED";

export interface MwlItemModelConstructor {
new (): MwlItemModel;
public static getDimseResultCursor(query: any, keys: any): Promise<any>;
public static getDicomJson(
queryOptions: DicomJsonQueryOptions
): Promise<GeneralDicomJson[]>;
/**
*
* @param query the query structure example { "00100010.Value": "foo" } or { "00100010.Value.00100010.Value": "bar" }
*/
public static getCount(query: any): Promise<number>;
public static createWithGeneralDicomJson(
generalDicomJson: GeneralDicomJson
): Promise<MwlItemModel>;
public static updateOneWithGeneralDicomJson(
mwlItem: MwlItemModel,
generalDicomJson: GeneralDicomJson
): Promise<MwlItemModel>;
/**
*
* @param query the query structure example { "00100010.Value": "foo" } or { "00100010.Value.00100010.Value": "bar" }
* @param status
*/
public static updateStatusByQuery(query: any, status: MwlItemStatus);
public static deleteByStudyInstanceUIDAndSpsID(
studyUID: string,
spsID: string
): Promise<number>;
public static findOneByStudyInstanceUIDAndSpsID(
studyUID: string,
spsID: string
): Promise<MwlItemModel>;
/**
*
* @param query the query structure example { "00100010.Value": "foo" } or { "00100010.Value.00100010.Value": "bar" }
*/
public static findMwlItems(query: any): Promise<MwlItemModel[]>;
}

export interface MwlItemModel {
toGeneralDicomJson(): Promise<GeneralDicomJson>;
toDicomJson(): Promise<BaseDicomJson>;
getAttributes(): Promise<any>;
updateStatus(status: MwlItemStatus): Promise<void>;
}

0 comments on commit 7ab1e0b

Please sign in to comment.