AcquisitionService.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. require_once("common/SQLServerManager.php");
  3. require_once('vo/com/imt/intimamedia/vo/DragAndDropVo.php');
  4. require_once('vo/com/imt/intimamedia/vo/MarkerVo.php');
  5. class AcquisitionService
  6. {
  7. public function getTypeFromLocation($location)
  8. {
  9. $query = "SELECT * FROM [intimamedia_physician].[dbo].[tr_type] WHERE fk_location = '". $location ."'";
  10. $results = SQLServerManager::queryOnDatabase( $query );
  11. $resultArray = array();
  12. foreach( $results as $value )
  13. {
  14. array_push( $resultArray, trim( $value->code ) );
  15. }
  16. return $resultArray;
  17. }
  18. public function createRandomName()
  19. {
  20. $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  21. srand((double)microtime()*1000000);
  22. $i = 0;
  23. $string = '' ;
  24. while ($i <= 7) {
  25. $num = rand() % 33;
  26. $tmp = substr($chars, $num, 1);
  27. $string = $string . $tmp;
  28. $i++;
  29. }
  30. return $string .".jpg";
  31. }
  32. // Sauvegarde des Images=========================
  33. public function saveImage( DragAndDropVo $dragAndDropVo, $appointmentId, $byteArrayHigh, $byteArrayLow )
  34. {
  35. $path = "../images/";
  36. $url = "/images/". $appointmentId ."/";
  37. /*$ff=fopen("d:/tmp.jd", "a+");
  38. fprintf($ff, "saveImages, url=%s\n", $url);
  39. fclose($ff);*/
  40. $folder = $path . $appointmentId;
  41. $keyType = $dragAndDropVo->type;
  42. $base64High = $this->createRandomName();
  43. $base64Small = $this->createRandomName();
  44. $width = $dragAndDropVo->width;
  45. $height = $dragAndDropVo->height;
  46. $collection = $dragAndDropVo->collection;
  47. $incidence = $dragAndDropVo->incidence;
  48. $dicom = ($dragAndDropVo->isDicom) ? 1 : 0;
  49. if( !is_dir ( $folder ) )
  50. {
  51. mkdir( $folder );
  52. }
  53. file_put_contents( $folder. "/". $base64High, $byteArrayHigh->data);
  54. file_put_contents( $folder. "/". $base64Small, $byteArrayLow->data);
  55. $transaction = SQLServerManager::startTransaction();
  56. $imageQuery = "INSERT INTO [intimamedia_physician].[dbo].[t_image] ( image, image_small, width, height, collection, fk_type, fk_appointment, incidence, dicom ) VALUES ( '". $url . $base64High ."', '". $url . $base64Small ."', ". $width .", ". $height .", '". $collection ."', '".$keyType ."', ". $appointmentId .", '". $incidence ."', " . $dicom . ")";
  57. $validImageQuery = SQLServerManager::executeQueryForTransaction( $imageQuery, $transaction );
  58. $imageId = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_image]", $transaction );
  59. if( $validImageQuery == "exception")
  60. Throw new Exception("E017");
  61. SQLServerManager::commitTransaction( $transaction );
  62. return $imageId;
  63. }
  64. public function saveMarker($list, $appointmentId)
  65. {
  66. $resultsMarkers = "";
  67. foreach( $list as $value )
  68. {
  69. $marker = "INSERT INTO [intimamedia_physician].[dbo].[list_marker] ( x, y, side, type, location, fk_appointment ) VALUES ( ". $value->xPosition .","
  70. ." ". $value->yPosition .", '". $value->side ."', '". $value->type ."', '". $value->location ."', ". $appointmentId .")";
  71. $resultsMarkers = SQLServerManager::queryOnDatabase( $marker );
  72. if($resultsMarkers== "exception")
  73. {
  74. Throw new Exception("E018");
  75. }
  76. }
  77. }
  78. public function getMarkers($appointmentId)
  79. {
  80. $query = "SELECT * FROM [intimamedia_physician].[dbo].[list_marker] WHERE fk_appointment = ". $appointmentId;
  81. $results = SQLServerManager::queryOnDatabase( $query );
  82. $resultArray = array();
  83. foreach( $results as $value )
  84. {
  85. $markerVo = new MarkerVo();
  86. $markerVo->type = trim( $value->type );
  87. $markerVo->location = trim( $value->location );
  88. $markerVo->side = trim( $value->side );
  89. $markerVo->xPosition = trim( $value->x );
  90. $markerVo->yPosition = trim( $value->y );
  91. array_push( $resultArray, $markerVo );
  92. }
  93. return $resultArray;
  94. }
  95. public function getImages($appointmentId)
  96. {
  97. $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_image] WHERE fk_appointment = ". $appointmentId;
  98. $results = SQLServerManager::queryOnDatabase( $query );
  99. /*$ff=fopen("d:/tmp.jd", "a+");
  100. fprintf($ff, "getImagesFromAppointmentEvent, query=%s\n", $query);
  101. fclose($ff);*/
  102. $resultArray = array();
  103. foreach( $results as $value )
  104. {
  105. $dragAndDropVo = new DragAndDropVo();
  106. $dragAndDropVo->id = $value->id;
  107. $dragAndDropVo->imageSmall = $value->image_small;
  108. $dragAndDropVo->imageHigh = $value->image;
  109. $dragAndDropVo->base64Small = $value->image_small;
  110. $dragAndDropVo->base64High = $value->image;
  111. $dragAndDropVo->width = $value->width;
  112. $dragAndDropVo->height = $value->height;
  113. $dragAndDropVo->type = trim( $value->fk_type );
  114. $dragAndDropVo->collection = trim( $value->collection );
  115. $dragAndDropVo->incidence = trim( $value->incidence );
  116. $dragAndDropVo->isDicom = ($value->dicom) ? true : false;
  117. array_push( $resultArray, $dragAndDropVo );
  118. }
  119. return $resultArray;
  120. }
  121. public function deleteImage( DragAndDropVo $dragAndDropVo, $appointmentId )
  122. {
  123. $image = "DELETE FROM [intimamedia_physician].[dbo].[t_image] WHERE id = ". $dragAndDropVo->id;
  124. $resultImages = SQLServerManager::queryOnDatabase( $image );
  125. if($resultImages== "exception")
  126. {
  127. Throw new Exception("E019");
  128. }
  129. }
  130. public function deleteMarkers($appointmentId)
  131. {
  132. $resultsmarker = "";
  133. $marker = "DELETE FROM [intimamedia_physician].[dbo].[list_marker] WHERE fk_appointment = ". $appointmentId;
  134. $resultsmarker = SQLServerManager::queryOnDatabase( $marker );
  135. if($resultsmarker== "exception")
  136. {
  137. Throw new Exception("E020");
  138. }
  139. }
  140. }
  141. ?>