Skip to content

Commit

Permalink
feat: support build date time query
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 11, 2023
1 parent 4663e11 commit 21750b6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,49 @@ class BaseQueryBuilder {
}
}

/**
*
* @param {string} tag
* @param {string} value
*/
getDateTimeQuery(tag, value) {
let dashIndex = value.indexOf("-");
if (dashIndex === 0) { // -YYYYMMDD
return {
[`x${tag}`]: {
[Op.lte]: this.dateTimeStringToSqlDateTime(value.substring(1))
}
};
} else if (dashIndex === value.length - 1) { // YYYYMMDD-
return {
[`x${tag}`]: {
[Op.gte]: this.dateTimeStringToSqlDateTime(value.substring(0, dashIndex))
}
};
} else if (dashIndex > 0) { // YYYYMMDD-YYYYMMDD
return {
[`x${tag}`]: {
[Op.and]: [
{ [Op.gte]: this.dateTimeStringToSqlDateTime(value.substring(0, dashIndex)) },
{ [Op.lte]: this.dateTimeStringToSqlDateTime(value.substring(dashIndex + 1)) }
]
}
};
} else { // YYYYMMDD
return {
[`x${tag}`]: this.dateTimeStringToSqlDateTime(value)
};
}
}

dateStringToSqlDateOnly(value) {
return moment(value, "YYYYMMDD").format("YYYY-MM-DD");
}

dateTimeStringToSqlDateTime(value) {
return moment(value, "YYYYMMDDhhmmss.SSSSSSZZ").toISOString();
}

/**
*
* @param {string} timeStr
Expand Down

0 comments on commit 21750b6

Please sign in to comment.