Skip to content

Commit

Permalink
docs: change config file location
Browse files Browse the repository at this point in the history
  • Loading branch information
JieuTang committed Jul 12, 2022
1 parent 77b3ee2 commit 3a7fed7
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Config/AllowProtocol.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"http": "http:",
"https": "https:"
}
29 changes: 3 additions & 26 deletions QIDOParameter.json → Config/QIDOParameter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@
"PatientName": "00100010",
"PatientID": "00100020",
"StudyInstanceUID": "0020000D",
"StudyID": "00200010",

"00080020": "StudyDate",
"00080030": "StudyTime",
"00080050": "AccessionNumber",
"00080061": "ModalitiesInStudy",
"00080090": "ReferringPhysicianName",
"00100010": "PatientName",
"00100020": "PatientID",
"0020000D": "StudyInstanceUID",
"00200010": "StudyID"
"StudyID": "00200010"
},
"Series": {
"Modality": "00080060",
Expand All @@ -35,25 +25,12 @@
"PerformedProcedureStepStartTime": "00400245",
"RequestAttributesSequence": "00400275",
"ScheduledProcedureStepID": "00400009",
"RequestedProcedureID": "00401001",

"00080060": "Modality",
"0020000E": "SeriesInstanceUID",
"00200011": "SeriesNumber",
"00400244": "PerformedProcedureStepStartDate",
"00400245": "PerformedProcedureStepStartTime",
"00400275": "RequestAttributesSequence",
"00400009": "ScheduledProcedureStepID",
"00401001": "RequestedProcedureID"
"RequestedProcedureID": "00401001"
},
"Instance": {
"SOPClassUID": "00080016",
"SOPInstanceUID": "00080018",
"InstanceNumber": "00200013",

"00080016": "SOPClassUID",
"00080018": "SOPInstanceUID",
"00200013": "InstanceNumber"
"InstanceNumber": "00200013"
}
}

5 changes: 5 additions & 0 deletions Config/QueryMode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"studies" : "studies",
"series" : "series",
"instances" : "instances"
}
117 changes: 106 additions & 11 deletions DICOMwebQIDORS.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import URL from "url-parse";
import _ from "lodash";
import QIDOParameter from "./QIDOParameter.json" assert {type: "json"};
import fetch from 'node-fetch';

import QIDOParameter from "./Config/QIDOParameter.json" assert {type: "json"};
import QueryMode from "./Config/QueryMode.json" assert {type: "json"};
import AllowProtocol from "./Config/AllowProtocol.json" assert {type: "json"};

class DICOMwebQIDORS {
constructor() {
//QIDOParameter.json
this.terminologyList = undefined;
this.parameterList = undefined;
this.studyParameterList = undefined;
this.seriesParameterList = undefined;
this.instanceParameterList = undefined;

//Token
this.isUseToken = false;
Expand All @@ -18,34 +24,123 @@ class DICOMwebQIDORS {
this.port = undefined;
this.protocol = undefined;
this.queryParameter = undefined

//Query Mode
this.queryMode = undefined;

//Response
this.response = undefined;
}

async _init() {
await _loadQIDOParameter();
async init() {
await this._loadQIDOParameter();
}

async _loadQIDOParameter() {
async query() {
await this._validateQueryMode();
await this._validateUrlComponent();

if (this.queryMode === QueryMode.studies) {
await this._queryStudies();
} else if (this.queryMode === QueryMode.series) {
await this._querySeries();
} else if (this.queryMode === QueryMode.instances) {
await this._queryInstances();
} else {
throw "queryMode Error";
}
}

async setUseToken(isUseToken = true, tokenValue) {
throw "This function is inactivate.";
}

async setParameter() {
async _loadQIDOParameter() {
let _terminoloy = _.get(QIDOParameter, "Terminology");
let _study = _.get(QIDOParameter, "Study");
let _series = _.get(QIDOParameter, "Series");
let _instance = _.get(QIDOParameter, "Instance");

this.terminologyList = _.cloneDeep(_terminoloy);
this.studyParameterList = _.cloneDeep(await this._getCombinedObjectWithInvertObject(_study));
this.seriesParameterList = _.cloneDeep(await this._getCombinedObjectWithInvertObject(_series));
this.instanceParameterList = _.cloneDeep(await this._getCombinedObjectWithInvertObject(_instance));
}

async _getCombinedObjectWithInvertObject(object1) {
return _.assign(object1, _.invert(object1));
}

async query() {
async _validateTokenCanUse() {
throw "This function is inactivate.";
}

async _validateUrlComponent() {
//falsy value: null、undefined、NaN、emptyString、0、false
//https://262.ecma-international.org/5.1/#sec-9.2
//如果 hostname、pathname、protocol 數值是 falsy 值,就代表是錯的。
if (!(this.hostname && this.pathname && this.protocol)) {
throw "hostname、pathname、protocol, three value can not be falsy.\n falsy value: null、undefined、NaN、emptyString、0、false";
}

//protocol 必須在清單內。
if (!(_.get(AllowProtocol, this.protocol))) {
throw "Protocol Error.\nProtocol ValueSet is [" + _.keys(AllowProtocol) + "]";
}

//port 必須是字串型態的數字
//不是字串 && 轉成數字後不是整數,跳出錯誤。
if (!(_.isString(this.port) && (_.isInteger((_.toNumber(this.port)))))) {
throw "port value has be String type and Integer value. Example '443' or '80'. ";
}

//queryParameter 必須在字典內
let legalKeySet = _.keys(_.assign(this.terminologyList, this.studyParameterList, this.seriesParameterList, this.instanceParameterList));
_.forEach(this.queryParameter, (value, key) => {
if (!(_.includes(legalKeySet, key))) {
throw "Key value: " + _.toString(key) + " is no allow.";
}
})

}

async setUseToken(isUseToken = true, tokenValue) {
async _validateQueryMode() {
//falsy value: null、undefined、NaN、emptyString、0、false
//https://262.ecma-international.org/5.1/#sec-9.2
//如果 queryMode 數值是 falsy 值,就代表是錯的。
if (!(_.get(QueryMode, this.queryMode))) {
throw "QueryMode Value Error! \nQueryMode ValueSet is [" + _.keys(QueryMode) + "]";
}
}

async _queryStudies() {
let url = new URL();
url.set('hostname', this.hostname);
url.set('pathname', this.pathname + "/" + QueryMode.studies);
url.set('port', this.port);
url.set('protocol', AllowProtocol[this.protocol]);
url.set('query', this.queryParameter);

console.log(url.toString());
this.response = await this._getRequestResponse(url.toString());
}

async _validateTokenCanUse() {

async _querySeries() {
throw "This function is inactivate.";
}

async _validateUrlComponent() {
async _queryInstances() {
throw "This function is inactivate.";
}

async _getRequestResponse(url) {
let result = undefined;

const response = await fetch(url);
const data = await response.json();
result = data;

return result;
}
}

Expand Down

0 comments on commit 3a7fed7

Please sign in to comment.