Skip to content

Commit

Permalink
fix: incorrect date value store in DB
Browse files Browse the repository at this point in the history
- The date value of DICOM is YYYYMMDD format,
need to cast to Date type and store to DB
- Add setter in `DA` schema to cast to Date of YYYYMMDD string value
- Add moment timezone to default timezone to GMT
> Avoid the system timezone store in DB
  • Loading branch information
Chinlinlee committed May 21, 2022
1 parent 87c10fb commit 365592f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
16 changes: 14 additions & 2 deletions models/mongodb/models/dicom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ let dicomModelSchema = new mongoose.Schema(
index: true,
required: true
},
"00080020": dicomJsonAttributeDASchema,
"00080020": new mongoose.Schema(dicomJsonAttributeDASchema, {
_id: false,
id: false,
toObject: {
getters: true
}
}),
"00080030": {
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.Number]
Expand Down Expand Up @@ -66,7 +72,13 @@ let dicomModelSchema = new mongoose.Schema(
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.String]
},
"00400244": dicomJsonAttributeDASchema,
"00400244": new mongoose.Schema(dicomJsonAttributeDASchema, {
_id: false,
id: false,
toObject: {
getters: true
}
}),
"00400275": dicomJsonAttributeSchema,
"00080016": {
...dicomJsonAttributeSchema,
Expand Down
8 changes: 7 additions & 1 deletion models/mongodb/schema/dicomJsonAttribute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require("mongoose");
const moment = require("moment");
const moment = require("moment-timezone");
const _ = require("lodash");

let dicomJsonAttributeSchema = {
Expand Down Expand Up @@ -33,6 +33,12 @@ let dicomJsonAttributeDASchema = {
Value: {
type: [Date],
default: void 0,
set: function(v) {
let length = _.get(v, "length");
if (length > 0) {
return v.map((date) => moment(date, "YYYYMMDD").toDate());
}
},
get: function (v) {
let length = _.get(v, "length");
if (length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions models/mongodb/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const moment = require("moment");

const moment = require("moment-timezone");
moment.tz.setDefault("GMT");
/**
*
* @param {Object} iQuery
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"log4js": "^6.4.5",
"mkdirp": "^1.0.4",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"mongoose": "^5.13.14",
"passport": "^0.5.2",
"passport-local": "^1.0.0",
Expand Down

0 comments on commit 365592f

Please sign in to comment.