DicomPaser.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\common\library;
  8. // include 'Nanodicom/nanodicom.php';
  9. // use app\common\library\nanodicom\Nanodicom;
  10. require dirname(__FILE__).'/nanodicom/Nanodicom.php';
  11. use Nanodicom;
  12. use app\common\library\DicomPaserTag;
  13. use think\Exception;
  14. class DicomPaser {
  15. public static function paser($filePath = '') {
  16. if(empty($filePath)) {
  17. throw new Exception("The filePath $filePath is empty or null");
  18. }
  19. if(!file_exists($filePath)) {
  20. throw new Exception("The filePath $filePath not exist");
  21. }
  22. if(!is_file($filePath)) {
  23. throw new Exception("The filePath $filePath not file");
  24. }
  25. $dicom = Nanodicom::factory($filePath);
  26. if(! $dicom->is_dicom()) {
  27. throw new Exception("The filePath $filePath not dcm file");
  28. }
  29. $a = $dicom->get(0x0010, 0x0010, 'N/A');
  30. return self::formatDataSet($dicom);
  31. }
  32. public static function formatDataSet($dicom) {
  33. $DICOM_TAG = DicomPaserTag::DICOM_TAG;
  34. $dataSet = [];
  35. foreach ($DICOM_TAG as $Tag) {
  36. $dataSet[$Tag['field']] = $dicom->get($Tag['group'], $Tag['element'], $Tag['default']);
  37. }
  38. return $dataSet;
  39. }
  40. }