Skip to content

Commit

Permalink
refactor: duplicate codes for bulkdata api
Browse files Browse the repository at this point in the history
- response Bulk Data Array and response single bulk data
  • Loading branch information
Chinlinlee committed Nov 11, 2023
1 parent 9392d66 commit e889b0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
43 changes: 28 additions & 15 deletions api/dicom-web/controller/WADO-RS/bulkdata/base.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BaseBulkDataController extends Controller {
this.apiLogger.addTokenValue();
this.bulkDataFactoryType = StudyBulkDataFactory;
this.imagePathFactoryType = StudyImagePathFactory;
this.bulkDataService = new BulkDataService(this.request, this.response, this.bulkDataFactoryType);
}

logAction() {
Expand All @@ -20,30 +21,42 @@ class BaseBulkDataController extends Controller {
async mainProcess() {
this.logAction();

let bulkDataService = new BulkDataService(this.request, this.response, this.bulkDataFactoryType);

try {
let bulkDataArray = await bulkDataService.getBulkData();
for(let bulkData of bulkDataArray) {
await bulkDataService.writeBulkData(bulkData);
}
this.logAction();

let imagePathFactory = new this.imagePathFactoryType({
...this.request.params
});
await imagePathFactory.getImagePaths();

for(let imagePathObj of imagePathFactory.imagePaths) {
await bulkDataService.writeBulkData(imagePathObj);
let bulkData = await this.bulkDataService.getBulkData();
if (Array.isArray(bulkData)) {
await this.responseBulkDataArray(bulkData);
} else {
await this.responseBulkData(bulkData);
}

bulkDataService.multipartWriter.writeFinalBoundary();
this.bulkDataService.multipartWriter.writeFinalBoundary();
return this.response.end();
} catch(e) {
} catch (e) {
let apiErrorArrayHandler = new ApiErrorArrayHandler(this.response, this.apiLogger, e);
return apiErrorArrayHandler.doErrorResponse();
}
}

async responseBulkDataArray(bulkDataArray) {
for (let bulkData of bulkDataArray) {
await this.bulkDataService.writeBulkData(bulkData);
}

let imagePathFactory = new this.imagePathFactoryType({
...this.request.params
});
await imagePathFactory.getImagePaths();

for (let imagePathObj of imagePathFactory.imagePaths) {
await this.bulkDataService.writeBulkData(imagePathObj);
}
}

async responseBulkData(bulkData) {
await this.bulkDataService.writeBulkData(bulkData);
}
}

module.exports.BaseBulkDataController = BaseBulkDataController;
16 changes: 0 additions & 16 deletions api/dicom-web/controller/WADO-RS/bulkdata/bulkdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ class BulkDataController extends BaseBulkDataController {
, SOPInstanceUID: ${this.request.params.instanceUID}`);
}

async mainProcess() {
this.logAction();

let bulkDataService = new BulkDataService(this.request, this.response, this.bulkDataFactoryType);

try {
let bulkData = await bulkDataService.getBulkData();
await bulkDataService.writeBulkData(bulkData);
bulkDataService.multipartWriter.writeFinalBoundary();
return this.response.end();
} catch(e) {
let apiErrorArrayHandler = new ApiErrorArrayHandler(this.response, this.apiLogger, e);
return apiErrorArrayHandler.doErrorResponse();
}

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BulkDataService {
async getBulkData() {
return await this.bulkDataFactory.getBulkData();
}

}

class BulkDataFactory {
Expand Down

0 comments on commit e889b0c

Please sign in to comment.