/
flow.js
75 lines (69 loc) · 2.86 KB
/
flow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
angular.module(
'opal.services'
).factory(
'Flow',
function($q, $http, $modal, $cacheFactory, $injector){
"use strict";
var get_flow_service = function(){
var OPAL_FLOW_SERVICE = $injector.get('OPAL_FLOW_SERVICE');
if(OPAL_FLOW_SERVICE){
return $injector.get(OPAL_FLOW_SERVICE);
}else{
return {
enter: function(){
return {
'controller': 'HospitalNumberCtrl',
'template' : '/templates/hospital_number_modal.html'
};
},
exit: function(){
return {
'controller': 'DischargeEpisodeCtrl',
'template' : '/templates/discharge_episode_modal.html'
};
}
};
}
}
var Flow = {
enter: function(config, context){
var deferred = $q.defer();
var target = get_flow_service().enter();
var result = $modal.open({
backdrop: 'static',
templateUrl: target.template,
controller: target.controller,
resolve: {
referencedata: function(Referencedata){ return Referencedata.load() },
metadata: function(Metadata){ return Metadata.load(); },
tags: function(){ return config.current_tags},
hospital_number: function(){ return config.hospital_number; },
context: function(){ return context; }
}
}).result;
deferred.resolve(result);
return deferred.promise;
},
exit: function(episode, config, context){
var deferred = $q.defer();
var target = get_flow_service().exit(episode)
var result = $modal.open({
backdrop: 'static',
templateUrl: target.template,
controller: target.controller,
keyboard: false,
resolve: {
episode : function() { return episode; },
referencedata: function(Referencedata){ return Referencedata.load() },
metadata : function(Metadata){ return Metadata.load(); },
tags : function() { return config.current_tags; },
context : function(){ return context; }
}
}).result;
deferred.resolve(result);
return deferred.promise;
}
};
return Flow;
}
);