Skip to content

Commit

Permalink
feat: log processing of syncing DIOCM FHIR
Browse files Browse the repository at this point in the history
- Refactor process of storing the log of DICOM
to FHIR into function `storeSyncedFHIRLog`
- Add the log of successsful DICOM to FHIR process
  • Loading branch information
Chinlinlee committed May 9, 2022
1 parent 2190770 commit e549625
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 37 deletions.
80 changes: 49 additions & 31 deletions api/dicom-web/controller/STOW-RS/storeInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,50 +200,68 @@ async function dicomToFHIR(req, dicomJson, uidObj) {

dicomFHIRConverter.fhir.baseUrl = process.env.FHIRSERVER_BASE_URL;
await dicomFHIRConverter.postDicomFhir();
let logObj = {
studyUID: uidObj.studyUID,
seriesUID: uidObj.seriesUID,
instanceUID: uidObj.sopInstanceUID,
status: true,
message: "success"
};
await storeSyncedFHIRLog(uidObj, logObj);
io.emit("fhir_synced", {
...dicomFHIRConverter.dicomFHIR,
status: true
});
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
if (e.isAxiosError) {
let errorObj = {
studyUID: uidObj.studyUID,
seriesUID: uidObj.seriesUID,
instanceUID: uidObj.sopInstanceUID,
message: errorStr
};
await mongoose.model("syncFHIRErrorLog").findOneAndUpdate(
{
$and: [
{
studyUID: uidObj.studyUID
},
{
seriesUID: uidObj.seriesUID
},
{
instanceUID: uidObj.sopInstanceUID
}
]
},
errorObj,
{
upsert: true
}
);
} else {
fhirLogger.error(
`[FHIR] [DICOM sync to FHIR server error] [${errorStr}]`
);
}
fhirLogger.error(
`[FHIR] [DICOM sync to FHIR server error] [${errorStr}]`
);
let errorObj = {
studyUID: uidObj.studyUID,
seriesUID: uidObj.seriesUID,
instanceUID: uidObj.sopInstanceUID,
status: false,
message: errorStr
};
await storeSyncedFHIRLog(uidObj, errorObj);
io.emit("fhir_synced", {
message: errorStr,
status: false
});
}
}

/**
* Store the log of processing result of DICOM converting to FHIR Resources and syncing to FHIR server.
* @param {import("../../../../utils/typeDef/dicom").UIDObject} uidObj
*/
async function storeSyncedFHIRLog(uidObj, logObj) {
try {
await mongoose.model("syncFHIRLog").findOneAndUpdate(
{
$and: [
{
studyUID: uidObj.studyUID
},
{
seriesUID: uidObj.seriesUID
},
{
instanceUID: uidObj.sopInstanceUID
}
]
},
logObj,
{
upsert: true
}
);
} catch(e) {
throw e;
}
}

/**
*
* @param {import('http').IncomingMessage} req
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const mongoose = require("mongoose");
/**
* This schema is log error of syncing data to FHIR server.
*/
let syncFHIRErrorLogSchema = new mongoose.Schema(
let syncFHIRLogSchema = new mongoose.Schema(
{
studyUID: {
type: String,
Expand All @@ -27,10 +27,10 @@ let syncFHIRErrorLogSchema = new mongoose.Schema(
versionKey: false
}
);
let syncFHIRErrorLogModel = mongoose.model(
"syncFHIRErrorLog",
syncFHIRErrorLogSchema,
"syncFHIRErrorLog"
let syncFHIRErrorModel = mongoose.model(
"syncFHIRLog",
syncFHIRLogSchema,
"syncFHIRLog"
);

module.exports = syncFHIRErrorLogModel;
module.exports = syncFHIRErrorModel;

0 comments on commit e549625

Please sign in to comment.