Skip to content

Commit

Permalink
refactor: extract logic for
Browse files Browse the repository at this point in the history
cleaning data before storing to the database

- Extracted the logic for cleaning data before storing to the database
into a separate method called getCleanDataBeforeStoringToDb.
- Updated storeToDb method to call getCleanDataBeforeStoringToDb to get
the cleaned data.
- Refactored the code to use the cleaned data for storing in the
database.
  • Loading branch information
Chinlinlee committed Nov 18, 2023
1 parent 9504545 commit 6ce5918
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions models/DICOM/dicom-json-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,35 @@ class DicomJsonModel {
}

async storeToDb(dicomFileSaveInfo) {
let dicomJsonClone = _.cloneDeep(this.dicomJson);
let dbJson = this.getCleanDataBeforeStoringToDb(dicomFileSaveInfo);
try {
let mediaStorage = this.getMediaStorageInfo();
_.merge(dicomJsonClone, this.uidObj);
_.merge(dicomJsonClone, {
studyPath: dicomFileSaveInfo.studyPath,
seriesPath: dicomFileSaveInfo.seriesPath,
instancePath: dicomFileSaveInfo.relativePath
});
_.merge(dicomJsonClone, mediaStorage);
_.set(dicomJsonClone, "deleteStatus", 0);

delete dicomJsonClone.sopClass;
delete dicomJsonClone.sopInstanceUID;

await Promise.all([
this.storeInstanceCollection(dicomJsonClone),
this.storeStudyCollection(dicomJsonClone),
this.storeSeriesCollection(dicomJsonClone),
this.storePatientCollection(dicomJsonClone)
this.storeInstanceCollection(dbJson),
this.storeStudyCollection(dbJson),
this.storeSeriesCollection(dbJson),
this.storePatientCollection(dbJson)
]);
} catch(e) {
throw e;
}
}

getCleanDataBeforeStoringToDb(dicomFileSaveInfo) {
let dicomJsonClone = _.cloneDeep(this.dicomJson);
let mediaStorage = this.getMediaStorageInfo();
_.merge(dicomJsonClone, this.uidObj);
_.merge(dicomJsonClone, {
studyPath: dicomFileSaveInfo.studyPath,
seriesPath: dicomFileSaveInfo.seriesPath,
instancePath: dicomFileSaveInfo.relativePath
});
_.merge(dicomJsonClone, mediaStorage);

delete dicomJsonClone.sopClass;
delete dicomJsonClone.sopInstanceUID;
return dicomJsonClone;
}

async storeInstanceCollection(dicomJson) {
let query = {
$and: [
Expand Down

0 comments on commit 6ce5918

Please sign in to comment.