Created
July 27, 2021 15:56
-
-
Save angshu/9afdf2e1635cb6c9610025750e5582c4 to your computer and use it in GitHub Desktop.
Custom Display Control for Radiology Studies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.directive('radiologyStudies', ['$http', '$q', 'appService', 'orderService', 'orderTypeService', 'spinner', 'messagingService','$window', function ($http, $q, appService, orderService, orderTypeService, spinner, messagingService, $window) { | |
var link = function ($scope) { | |
$scope.contentUrl = appService.configBaseUrl() + "/customDisplayControl/views/radiologyStudies.html"; | |
var orderTypeUuid = orderTypeService.getOrderTypeUuid("Radiology Order"); | |
var radiologyImageUrl = $scope.section.oviyamImageUrl || "/oviyam2/viewer.html?patientID={{patientID}}&studyUID={{studyUID}}"; | |
var getOrders = function () { | |
var params = { | |
patientUuid: $scope.patient.uuid, | |
orderTypeUuid: orderTypeUuid, | |
includeObs: true | |
}; | |
return orderService.getOrders(params); | |
}; | |
var queryPacsStudies = function () { | |
var params = { | |
patientId: $scope.patient.identifier | |
}; | |
return $http.get('/openmrs/ws/rest/v1/pacs/studies', { | |
method: "GET", | |
params: params, | |
withCredentials: true | |
}); | |
}; | |
$scope.getLabel = function (radiologyOrder) { | |
return radiologyOrder.concept.shortName || radiologyOrder.concept.name; | |
}; | |
$scope.openImage = function (radiologyOrder) { | |
var url = radiologyOrder.oviyamUrl; | |
if (url == undefined) { | |
messagingService.showMessage("info", "No study available yet for order: " + $scope.getLabel(radiologyOrder)); | |
return; | |
} | |
spinner.forAjaxPromise($.ajax({type: 'HEAD', url: url, async: false}).then( | |
function () { | |
$window.open(url, "_blank"); | |
}, function () { | |
messagingService.showMessage("info", "No image available yet for order: " + $scope.getLabel(radiologyOrder)); | |
})); | |
}; | |
$q.all([getOrders(), queryPacsStudies()]).then(function (response) { | |
var radiologyOrders = response[0].data; | |
var radiologyStudies = response[1].data; | |
if (radiologyOrders) { | |
radiologyOrders.forEach(function (ro) { | |
if (radiologyStudies) { | |
var matching = radiologyStudies.filter(function(rs) { return rs.accessionNumber == ro.orderNumber; }); | |
if (matching && matching.length > 0) { | |
ro.studyInstanceUID = matching[0].studyInstanceUID; | |
ro.oviyamUrl = radiologyImageUrl | |
.replace('{{patientID}}', $scope.patient.identifier) | |
.replace('{{studyUID}}', matching[0].studyInstanceUID) | |
.replace('{{accessionNumber}}', ro.orderNumber); | |
} | |
} | |
}); | |
} else { | |
if (_.isEmpty($scope.radiologyOrders)) { | |
$scope.noOrdersMessage = $scope.orderType; | |
$scope.$emit("no-data-present-event"); | |
} | |
} | |
$scope.radiologyOrders = radiologyOrders || []; | |
}); | |
}; | |
return { | |
restrict: 'E', | |
link: link, | |
scope: { | |
patient: "=", | |
section: "=", | |
config: "=" | |
}, | |
template: '<ng-include src="contentUrl"/>' | |
}; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment