DicomPaser.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. class DicomPaser {
  14. public static function paser($filePath = '') {
  15. if(empty($filePath)) {
  16. throw new Error("The filePath $filePath is empty or null");
  17. }
  18. if(!file_exists($filePath)) {
  19. throw new Error("The filePath $filePath not exist");
  20. }
  21. if(!is_file($filePath)) {
  22. throw new Error("The filePath $filePath not file");
  23. }
  24. $dicom = Nanodicom::factory($filePath);
  25. if(! $dicom->is_dicom()) {
  26. throw new Error("The filePath $filePath not dcm file");
  27. }
  28. $a = $dicom->get(0x0010, 0x0010, 'N/A');
  29. return self::formatDataSet($dicom);
  30. }
  31. public static function formatDataSet($dicom) {
  32. $DICOM_TAG = DicomPaserTag::DICOM_TAG;
  33. $dataSet = [];
  34. foreach ($DICOM_TAG as $Tag) {
  35. $dataSet[$Tag['field']] = $dicom->get($Tag['group'], $Tag['element'], $Tag['default']);
  36. }
  37. return $dataSet;
  38. }
  39. }