Skip to content

Commit

Permalink
Merge pull request #32 from salimkanoun/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
salimkanoun authored Feb 25, 2020
2 parents 26fd0b8 + 49ec4fa commit c5f8b20
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 23 deletions.
7 changes: 6 additions & 1 deletion BackEnd/controllers/aets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ var echoAets = async function (req, res) {
res.json(answer)
}

module.exports = { getAets, changeAets, echoAets }
var deleteAet = async function (req, res) {
let answer = await orthancInstance.removeAet(req.params.name)
res.json(answer)
}

module.exports = { getAets, changeAets, echoAets, deleteAet }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
queryInterface.bulkInsert('Users', [{
username: 'salim',
password: hash,
admin: false,
admin: true,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString()
}], {})
Expand Down
10 changes: 10 additions & 0 deletions BackEnd/model/Orthanc.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ class Orthanc {
return requestPromise
}

removeAet(name){
let self = this
const requestPromise = request.delete(self._createOptions('DELETE', '/modalities/' + name)).then(function (body) {
return true
}).catch((error) => { console.log('Error put AET ' + error) })

return requestPromise

}

echoAet(name){
const self = this
const requestPromise = request.post(self._createOptions('POST', '/modalities/' + name + '/echo', JSON.stringify({}))).then(function (body) {
Expand Down
19 changes: 18 additions & 1 deletion BackEnd/model/RetrieveItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class RetrieveItem {

constructor (level, patientName, patientId, studyDate, modality, studyDescription, accessionNb, aet) {
this.level = level
this.patientName = patientName
Expand All @@ -8,6 +9,7 @@ class RetrieveItem {
this.studyDescription = studyDescription
this.accessionNb = accessionNb
this.aet = aet
this.status = RetrieveItem.STATUS_IDLE
}

setRetrievedOrthancId (orthancId) {
Expand All @@ -18,6 +20,15 @@ class RetrieveItem {
return this.retrievedOrthancId
}

setStatus(status){
this.status = status
}

getStatus(){
return this.status
}


toJSON () {
return {
level: this.level,
Expand All @@ -27,9 +38,15 @@ class RetrieveItem {
modality: this.modality,
studyDescription: this.studyDescription,
accessionNb: this.accessionNb,
aet: this.aet
aet: this.aet,
status : this.status
}
}
}

RetrieveItem.STATUS_IDLE = 'Idle';
RetrieveItem.STATUS_RETRIVING = 'Retrieving';
RetrieveItem.STATUS_RETRIEVED = 'Retrieved';
RetrieveItem.STATUS_FAILURE = 'Failure';

module.exports = RetrieveItem
25 changes: 17 additions & 8 deletions BackEnd/model/RetrieveRobot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const schedule = require('node-schedule')
const Options = require('./Options')
const RetrieveItem = require('./RetrieveItem')

class RetrieveRobot {
constructor (orthancObject) {
Expand Down Expand Up @@ -89,19 +90,27 @@ class RetrieveRobot {
const job = this.robotJobs[usersRobots[i]]

for (let i = 0; i < job.retrieveList.length; i++) {
const studyData = job.retrieveList[i]
console.log(studyData)
const retrieveItem = job.getRetriveItem(i)
console.log(retrieveItem)

robot.orthancObject.buildDicomQuery(studyData.level, studyData.patientName, studyData.patientId, studyData.studyDate + '-' + studyData.studyDate,
studyData.modality, studyData.studyDescription, studyData.accessionNb)
robot.orthancObject.buildDicomQuery(retrieveItem.level, retrieveItem.patientName, retrieveItem.patientId, retrieveItem.studyDate + '-' + retrieveItem.studyDate,
retrieveItem.modality, retrieveItem.studyDescription, retrieveItem.accessionNb)

const answerDetails = await robot.orthancObject.makeDicomQuery(studyData.aet)
job.getRetriveItem(i).setStatus(RetrieveItem.STATUS_RETRIVING)
const answerDetails = await robot.orthancObject.makeDicomQuery(retrieveItem.aet)

for (const answer of answerDetails) {
if (answerDetails.length === 1 ) {
let answer = answerDetails[0]
const retrieveAnswer = await robot.orthancObject.makeRetrieve(answer.answerId, answer.answerNumber, robot.aetDestination, true)
console.log(retrieveAnswer)
const orthancResults = await robot.orthancObject.findInOrthancByUid(retrieveAnswer.Query[0]['0020,000d'])
job.getRetriveItem(i).setRetrievedOrthancId(orthancResults[0])

if(orthancResults.length === 1){
job.getRetriveItem(i).setStatus(RetrieveItem.STATUS_RETRIEVED)
job.getRetriveItem(i).setRetrievedOrthancId(orthancResults[0])
}else{
job.getRetriveItem(i).setStatus(RetrieveItem.STATUS_FAILURE)
}

}
}
}
Expand Down
3 changes: 2 additions & 1 deletion BackEnd/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require('express-async-errors')

const { getRobotDetails, createRobot, deleteRobotJob, removeQueryFromJob } = require('../controllers/Robot')
const { changeSchedule , getSchedule } = require('../controllers/options')
const { getAets, changeAets, echoAets} = require('../controllers/aets')
const { getAets, changeAets, echoAets, deleteAet} = require('../controllers/aets')
const { getJobData } = require('../controllers/jobDetails')
const { authentication } = require('../controllers/authentication')
const { postQuery } = require('../controllers/queryAction')
Expand Down Expand Up @@ -38,5 +38,6 @@ router.put('/options', [userAuthMidelware, userAdminMidelware], changeSchedule)
router.put('/aets', [userAuthMidelware, userAdminMidelware] , changeAets)
router.get('/aets', userAuthMidelware , getAets)
router.get('/aets/:name/echo', [userAuthMidelware, userAdminMidelware] , echoAets)
router.delete('/aets/:name', [userAuthMidelware,userAdminMidelware], deleteAet)

module.exports = router
21 changes: 21 additions & 0 deletions BackEnd/spec/OrthancSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const Orthanc = require('../model/Orthanc')

describe('Test Orthanc', () =>{

var orthanc=null

beforeEach(function() {

orthanc = new Orthanc()

spyOn(orthanc, "removeAet").and.returnValue(true);

});

it('should Remove Orthanc AET', async () => {

expect(orthanc.removeAet()).toBe(true)

})

})
34 changes: 34 additions & 0 deletions BackEnd/spec/RetrieveItemSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const RetrieveItem = require('../model/RetrieveItem')

describe('Testing Retrieve Item', () =>{

let retrieveItem = new RetrieveItem('study', 'Name', 'id', '20180101', 'CT', 'Description', 'Accession', 'self')

it('should create Retrieve Item', async () => {
expect(retrieveItem).toBeInstanceOf(RetrieveItem)
})

it('should change retrieve status', () => {
retrieveItem.setStatus(RetrieveItem.STATUS_RETRIVING)
expect(retrieveItem.getStatus()).toBe(RetrieveItem.STATUS_RETRIVING)
})

it('should set Orthanc ID', () => {
retrieveItem.setRetrievedOrthancId('123456789');
expect(retrieveItem.getRetrievedOrthancId()).toBe('123456789')
})

it('should return correct JSON', () => {
expect(retrieveItem.toJSON()).toEqual({
level: 'study',
patientName: 'Name',
patientId: 'id',
studyDate: '20180101',
modality: 'CT',
studyDescription: 'Description',
accessionNb: 'Accession',
aet: 'self',
status : RetrieveItem.STATUS_RETRIVING
})
})
})
Loading

0 comments on commit c5f8b20

Please sign in to comment.