GetImagesCommand.as 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. package com.imt.intimamedia.commands.acquire
  2. {
  3. import com.adobe.cairngorm.control.CairngormEvent;
  4. import com.imt.flex.cairngormExtended.command.SuperCommand;
  5. import com.imt.intimamedia.business.AcquisitionDelegate;
  6. import com.imt.intimamedia.events.acquire.GetImagesEvent;
  7. import com.imt.intimamedia.helpers.FlashHelper;
  8. import com.imt.intimamedia.model.ApplicationModelLocator;
  9. import com.imt.intimamedia.views.common.ImtToaster;
  10. import com.imt.intimamedia.views.physician.acquire.AcquireView;
  11. import com.imt.intimamedia.vo.DragAndDropVo;
  12. import flash.display.Bitmap;
  13. import flash.display.Loader;
  14. import flash.display.LoaderInfo;
  15. import flash.events.Event;
  16. import flash.events.HTTPStatusEvent;
  17. import flash.events.IOErrorEvent;
  18. import flash.events.ProgressEvent;
  19. import flash.events.SecurityErrorEvent;
  20. import flash.events.StatusEvent;
  21. import flash.events.TimerEvent;
  22. import flash.net.LocalConnection;
  23. import flash.net.URLRequest;
  24. import flash.utils.Timer;
  25. import mx.collections.ArrayCollection;
  26. import mx.controls.Alert;
  27. import mx.controls.List;
  28. import mx.core.Application;
  29. import mx.resources.ResourceManager;
  30. import mx.rpc.events.FaultEvent;
  31. import mx.rpc.events.ResultEvent;
  32. import mx.utils.ObjectUtil;
  33. /**
  34. * Commande de récupération des images pour un RDV
  35. */
  36. public class GetImagesCommand extends SuperCommand
  37. {
  38. [Bindable]
  39. private var _model : ApplicationModelLocator = ApplicationModelLocator.getInstance();
  40. private var _resultArray : Array;
  41. private var _dispatcher : *;
  42. private var _reportTimer : Timer = new Timer( 100, 1 );
  43. private var _swfTimer : Timer = new Timer(200, 1);
  44. private var _swfResetTimer : Timer = new Timer(200, 1);
  45. private var _segmentResetTimer : Timer = new Timer (500, 1);
  46. private var _leftImgType : ArrayCollection = new ArrayCollection();
  47. private var _rightImgType : ArrayCollection = new ArrayCollection();
  48. public var list : Array;
  49. public var currentDragAndDropVo : DragAndDropVo;
  50. /**
  51. * Excecution de la commande
  52. *
  53. * @param event Evénement de type CairngormEvent
  54. * @return void
  55. */
  56. override public function execute( event : CairngormEvent ) : void
  57. {
  58. super.execute( event );
  59. var delegate : AcquisitionDelegate = new AcquisitionDelegate( this );
  60. var getImagesEvent : GetImagesEvent = GetImagesEvent( event );
  61. delegate.getImages( getImagesEvent.appointmentId );
  62. }
  63. /**
  64. * Résultat de la commande
  65. *
  66. * @param result Un objet
  67. * @return void
  68. */
  69. override public function result( result : Object ) : void
  70. {
  71. _dispatcher = this.getDispatcher(this);
  72. var resultEvent : ResultEvent = ResultEvent( result );
  73. list = resultEvent.result as Array;
  74. if (list.length > 0)
  75. {
  76. _dispatcher.loadingPopUp.message = ResourceManager.getInstance().getString('labels', 'acquire.popUp.get.images');
  77. if (_dispatcher.name == 'report')
  78. {
  79. if (_model.viewPatient)
  80. _model.measuresList.removeAll();
  81. _model.snapshotReportRightSegment.removeAll();
  82. _model.snapshotReportLeftSegment.removeAll();
  83. switch( ( list[ 0 ] as DragAndDropVo ).collection )
  84. {
  85. case "CR":
  86. case "CL":
  87. FlashHelper.resetCarotids();
  88. break;
  89. case "AR":
  90. case "AL":
  91. FlashHelper.resetArms();
  92. break;
  93. case "LR":
  94. case "LL":
  95. FlashHelper.resetLegs();
  96. break;
  97. case "BO":
  98. FlashHelper.resetBody();
  99. break;
  100. }
  101. _dispatcher.loadingPopUp.progress.setProgress( 15, 100 );
  102. _segmentResetTimer.start();
  103. _segmentResetTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startDownloadImages);
  104. }
  105. else
  106. _dispatcher.loadingPopUp.progress.setProgress( 60, 100 );
  107. // empty data if measure View
  108. if (_dispatcher.name == 'generalMeasure' && _model.viewPatient)
  109. _model.measuresList.removeAll();
  110. if (_dispatcher.name != 'report')
  111. downloadImages( list[ 0 ] as DragAndDropVo );
  112. }
  113. else
  114. _dispatcher.loadingPopUp.closeHandler();
  115. super.result( result );
  116. }
  117. private function startDownloadImages(event : TimerEvent) : void
  118. {
  119. _segmentResetTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, startDownloadImages);
  120. _segmentResetTimer.stop();
  121. _dispatcher.loadingPopUp.progress.setProgress( 25, 100 );
  122. downloadImages( list[ 0 ] as DragAndDropVo );
  123. }
  124. private function downloadImages( dragAndDropVo : DragAndDropVo ) : void
  125. {
  126. // comment by J. Deppe : no more copy
  127. //currentDragAndDropVo = ObjectUtil.copy( dragAndDropVo ) as DragAndDropVo;
  128. currentDragAndDropVo = dragAndDropVo as DragAndDropVo;
  129. if (_dispatcher.name == 'report')
  130. {
  131. switch (list.length)
  132. {
  133. case 6:
  134. _dispatcher.loadingPopUp.progress.setProgress( 35, 100 );
  135. break;
  136. case 5:
  137. _dispatcher.loadingPopUp.progress.setProgress( 45, 100 );
  138. break;
  139. case 4:
  140. _dispatcher.loadingPopUp.progress.setProgress( 55, 100 );
  141. break;
  142. case 3:
  143. _dispatcher.loadingPopUp.progress.setProgress( 65, 100 );
  144. break;
  145. case 2:
  146. _dispatcher.loadingPopUp.progress.setProgress( 75, 100 );
  147. break;
  148. case 1:
  149. _dispatcher.loadingPopUp.progress.setProgress( 85, 100 );
  150. break;
  151. }
  152. }
  153. var loaderSmall : Loader = new Loader();
  154. var requestSmall : URLRequest = new URLRequest( currentDragAndDropVo.base64Small );
  155. loaderSmall.load( requestSmall );
  156. loaderSmall.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandlerSmall);
  157. }
  158. private function completeHandlerSmall( event : Event ) : void
  159. {
  160. var loaderInfo : LoaderInfo = LoaderInfo(event.target);
  161. currentDragAndDropVo.imageSmall = loaderInfo.content as Bitmap;
  162. var request : URLRequest = new URLRequest( currentDragAndDropVo.base64High );
  163. var loader : Loader = new Loader();
  164. loader.load( request );
  165. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
  166. loader.contentLoaderInfo.addEventListener(Event.OPEN, openHandler);
  167. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  168. loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  169. loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
  170. loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  171. }
  172. private function completeHandler( event : Event ) : void
  173. {
  174. var loaderInfo : LoaderInfo = LoaderInfo(event.target);
  175. _dispatcher.loadingPopUp.message = ResourceManager.getInstance().getString('labels', 'acquire.popUp.get.image.done');
  176. startImageConversion( loaderInfo.content as Bitmap );
  177. }
  178. private function startImageConversion( data : Bitmap ) : void
  179. {
  180. currentDragAndDropVo.imageHigh = data;
  181. switch( currentDragAndDropVo.collection )
  182. {
  183. case "CR":
  184. _dispatcher.collectionImagesCarotidRight.addItem( currentDragAndDropVo );
  185. if (_dispatcher.name == 'report')
  186. {
  187. FlashHelper.restoreSelectionForRightCarotid( currentDragAndDropVo.type );
  188. startSwfSelectionSnapshotTimer();
  189. }
  190. else
  191. FlashHelper.restoreSelectionForRightCarotid( currentDragAndDropVo.type );
  192. break;
  193. case "CL":
  194. _dispatcher.collectionImagesCarotidLeft.addItem( currentDragAndDropVo );
  195. if (_dispatcher.name == 'report')
  196. {
  197. FlashHelper.restoreSelectionForLeftCarotid( currentDragAndDropVo.type );
  198. startSwfSelectionSnapshotTimer();
  199. }
  200. else
  201. FlashHelper.restoreSelectionForLeftCarotid( currentDragAndDropVo.type );
  202. break;
  203. case "AR":
  204. _dispatcher.collectionImagesArmRight.addItem( currentDragAndDropVo );
  205. if (_dispatcher.name == 'report')
  206. {
  207. FlashHelper.restoreSelectionForRightArm( currentDragAndDropVo.type );
  208. startSwfSelectionSnapshotTimer();
  209. }
  210. else
  211. FlashHelper.restoreSelectionForRightArm( currentDragAndDropVo.type );
  212. break;
  213. case "AL":
  214. _dispatcher.collectionImagesArmLeft.addItem( currentDragAndDropVo );
  215. if (_dispatcher.name == 'report')
  216. {
  217. FlashHelper.restoreSelectionForLeftArm( currentDragAndDropVo.type );
  218. startSwfSelectionSnapshotTimer();
  219. }
  220. else
  221. FlashHelper.restoreSelectionForLeftArm( currentDragAndDropVo.type );
  222. break;
  223. case "LR":
  224. _dispatcher.collectionImagesLegRight.addItem( currentDragAndDropVo );
  225. if (_dispatcher.name == 'report')
  226. {
  227. FlashHelper.restoreSelectionForRightLeg( currentDragAndDropVo.type );
  228. startSwfSelectionSnapshotTimer();
  229. }
  230. else
  231. FlashHelper.restoreSelectionForRightLeg( currentDragAndDropVo.type );
  232. break;
  233. case "LL":
  234. _dispatcher.collectionImagesLegLeft.addItem( currentDragAndDropVo );
  235. if (_dispatcher.name == 'report')
  236. {
  237. FlashHelper.restoreSelectionForLeftLeg( currentDragAndDropVo.type );
  238. startSwfSelectionSnapshotTimer();
  239. }
  240. else
  241. FlashHelper.restoreSelectionForLeftLeg( currentDragAndDropVo.type );
  242. break;
  243. case "BO":
  244. _dispatcher.collectionImagesBody.addItem( currentDragAndDropVo );
  245. if (_dispatcher.name == 'report')
  246. {
  247. FlashHelper.restoreSelectionForBody( currentDragAndDropVo.type );
  248. startSwfSelectionSnapshotTimer();
  249. }
  250. else
  251. FlashHelper.restoreSelectionForBody( currentDragAndDropVo.type );
  252. break;
  253. }
  254. if (_dispatcher.name != 'report')
  255. // acquire or generalMeasure dispatcher
  256. endImageConversion();
  257. }
  258. private function startSwfSelectionSnapshotTimer() : void
  259. {
  260. _swfTimer.start();
  261. _swfTimer.addEventListener(TimerEvent.TIMER_COMPLETE, swfSelectionSnapshot);
  262. }
  263. private function swfSelectionSnapshot(event : TimerEvent) : void
  264. {
  265. _swfTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, swfSelectionSnapshot);
  266. _swfTimer.stop();
  267. switch( currentDragAndDropVo.collection )
  268. {
  269. case "CR":
  270. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomCarotidRight, "CR");
  271. _model.snapshotReportRightSegment.addItem(_model.carotidRight);
  272. _rightImgType.addItem(currentDragAndDropVo.type);
  273. FlashHelper.removeSelectionForRightCarotid(currentDragAndDropVo.type);
  274. break;
  275. case "CL":
  276. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomCarotidLeft, "CL");
  277. _model.snapshotReportLeftSegment.addItem(_model.carotidLeft);
  278. _leftImgType.addItem(currentDragAndDropVo.type);
  279. FlashHelper.removeSelectionForLeftCarotid(currentDragAndDropVo.type);
  280. break;
  281. case "AR":
  282. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomArmRight, "AR");
  283. _model.snapshotReportRightSegment.addItem(_model.armRight);
  284. _rightImgType.addItem(currentDragAndDropVo.type);
  285. FlashHelper.removeSelectionForRightArm(currentDragAndDropVo.type);
  286. break;
  287. case "AL":
  288. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomArmLeft, "AL");
  289. _model.snapshotReportLeftSegment.addItem(_model.armLeft);
  290. _leftImgType.addItem(currentDragAndDropVo.type);
  291. FlashHelper.removeSelectionForLeftArm(currentDragAndDropVo.type);
  292. break;
  293. case "LR":
  294. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomLegRight, "LR");
  295. _model.snapshotReportRightSegment.addItem(_model.legRight);
  296. _rightImgType.addItem(currentDragAndDropVo.type);
  297. FlashHelper.removeSelectionForRightLeg(currentDragAndDropVo.type);
  298. break;
  299. case "LL":
  300. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomLegLeft, "LL");
  301. _model.snapshotReportLeftSegment.addItem(_model.legLeft);
  302. _leftImgType.addItem(currentDragAndDropVo.type);
  303. FlashHelper.removeSelectionForLeftLeg(currentDragAndDropVo.type);
  304. break;
  305. case "BO":
  306. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomBody, "BO");
  307. _model.snapshotReportRightSegment.addItem(_model.body);
  308. _rightImgType.addItem(currentDragAndDropVo.type);
  309. FlashHelper.removeSelectionForBody(currentDragAndDropVo.type);
  310. break;
  311. }
  312. _swfResetTimer.start();
  313. _swfResetTimer.addEventListener(TimerEvent.TIMER_COMPLETE, waitForSelectionRemoving);
  314. }
  315. private function waitForSelectionRemoving(event : TimerEvent) : void
  316. {
  317. _swfResetTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, waitForSelectionRemoving);
  318. _swfResetTimer.stop();
  319. endImageConversion();
  320. }
  321. private function endImageConversion() : void
  322. {
  323. if (_model.viewPatient)
  324. {
  325. _model.measuresList.addItem( currentDragAndDropVo );
  326. }
  327. if( list.length == 1 )
  328. {
  329. if (_dispatcher.name == "report")
  330. {
  331. var type : String;
  332. _dispatcher.loadingPopUp.progress.setProgress( 95, 100 );
  333. switch( currentDragAndDropVo.collection )
  334. {
  335. case "CR":
  336. case "CL":
  337. for each( type in _rightImgType )
  338. FlashHelper.restoreSelectionForRightCarotid( type );
  339. for each( type in _leftImgType )
  340. FlashHelper.restoreSelectionForLeftCarotid( type );
  341. break;
  342. case "AR":
  343. case "AL":
  344. for each( type in _rightImgType )
  345. FlashHelper.restoreSelectionForRightArm( type );
  346. for each( type in _leftImgType )
  347. FlashHelper.restoreSelectionForLeftArm( type );
  348. break;
  349. case "LR":
  350. case "LL":
  351. for each( type in _rightImgType )
  352. FlashHelper.restoreSelectionForRightLeg( type );
  353. for each( type in _leftImgType )
  354. FlashHelper.restoreSelectionForLeftLeg( type );
  355. break;
  356. case "BO":
  357. for each( type in _rightImgType )
  358. FlashHelper.restoreSelectionForBody( type );
  359. break;
  360. }
  361. startReportTimer();
  362. }
  363. else
  364. {
  365. // images processing ended, start markers processing
  366. _dispatcher.setImagesLoaded( (list[ 0 ] as DragAndDropVo).collection );
  367. _dispatcher.getMarkers();
  368. }
  369. }
  370. else
  371. {
  372. // images processing continue
  373. list.shift();
  374. downloadImages( list[ 0 ] as DragAndDropVo );
  375. }
  376. }
  377. private function startReportTimer() : void
  378. {
  379. _reportTimer = new Timer( 300, 1 );
  380. _reportTimer.start();
  381. _reportTimer.addEventListener(TimerEvent.TIMER_COMPLETE, stopReportTimer);
  382. }
  383. private function stopReportTimer(event : TimerEvent) : void
  384. {
  385. _reportTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, stopReportTimer);
  386. _reportTimer.stop();
  387. // J. Deppe : uncomment later
  388. //if (_model.viewPatient)
  389. //{
  390. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomCarotidRight, "CR");
  391. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomCarotidLeft, "CL");
  392. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomArmRight, "AR");
  393. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomArmLeft, "AL");
  394. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomLegRight, "LR");
  395. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomLegLeft, "LL");
  396. FlashHelper.buildSegmentSelected(Application.application.menuPhysician.acquire.panzoomBody, "BO");
  397. //}
  398. _dispatcher.setImagesLoaded( (list[ 0 ] as DragAndDropVo).collection );
  399. _dispatcher.getMarkers();
  400. }
  401. private function openHandler( event : Event ) : void
  402. {
  403. _dispatcher.loadingPopUp.message = ResourceManager.getInstance().getString('labels', 'acquire.open.image');
  404. }
  405. private function progressHandler( event : ProgressEvent ) : void
  406. {
  407. _dispatcher.loadingPopUp.message = ResourceManager.getInstance().getString('labels', 'acquire.popUp.get.images.progress') + " : " + event.bytesLoaded / 1000 + ResourceManager.getInstance().getString('labels', 'acquire.popUp.images.unit') + " / " + event.bytesTotal / 1000 + " " + ResourceManager.getInstance().getString('labels', 'acquire.popUp.images.unit');
  408. }
  409. private function httpStatusHandler( event : HTTPStatusEvent ) : void
  410. {
  411. _dispatcher.loadingPopUp.message = ResourceManager.getInstance().getString('labels', 'acquire.popUp.get.images.complete');
  412. }
  413. private function ioErrorHandler( event : IOErrorEvent ) : void { }
  414. private function securityErrorHandler( event : SecurityErrorEvent ) : void { }
  415. override public function fault( fault : Object ) : void
  416. {
  417. super.fault( fault );
  418. if (( fault as FaultEvent ).fault.faultString == ApplicationModelLocator.getInstance().ERROR_SESSION )
  419. {
  420. ApplicationModelLocator.displaySessionExpired( fault as FaultEvent );
  421. }
  422. else
  423. {
  424. var toastMessage : ImtToaster = new ImtToaster();
  425. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.title');
  426. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.type') + " (" + ResourceManager.getInstance().getString('errors', ( fault as FaultEvent ).fault.faultString) +")";
  427. toastMessage.timeToLive = 7;
  428. toastMessage.level = ImtToaster.ERROR;
  429. _model.toaster.toast( toastMessage );
  430. }
  431. }
  432. }
  433. }