dicom3


https://www.geeksforgeeks.org/python-build-a-rest-api-using-flask/

https://pythonbasics.org/flask-rest-api/

https://auth0.com/blog/developing-restful-apis-with-python-and-flask/

https://stackpython.medium.com/%E0%B8%97%E0%B8%B3-api-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B9%84%E0%B8%9E%E0%B8%98%E0%B8%AD%E0%B8%99%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2%E0%B8%99%E0%B8%B4%E0%B8%94%E0%B9%80%E0%B8%94%E0%B8%B5%E0%B8%A2%E0%B8%A7-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-flask-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%80%E0%B8%AB%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%A2%E0%B8%B2%E0%B8%81%E0%B8%AB%E0%B8%A1%E0%B8%94-84ed925b3293

https://stackpython.co/tutorial/rest-api-flask-101

https://github.com/bjoernalbers/mowoli

http://dicomiseasy.blogspot.com/2012/06/modality-performed-procedure-step.html

https://comp.protocols.dicom.narkive.com/mcGOF6aC/question-about-studyinstanceuid-usage-mwl

https://github.com/sdoloris/orthanc-explorer-2

https://book.orthanc-server.com/plugins/orthanc-explorer-2.html

https://github.com/vsoch/som-orthanc

https://github.com/jmerkow/mwl-orthanc

https://book.orthanc-server.com/plugins/python.html#handling-worklist-scp-requests-new-in-3-2

https://github.com/101josh10/Radiology-Information-System

https://pydicom.github.io/pynetdicom/stable/examples/display.html

https://github.com/sscotti/MWL_PDF_OrthancDemo

https://github.com/mamisoa/webmwl

https://github.com/sscotti/python_script_library

https://github.com/opendicom/opendicomMWLpy

https://github.com/sscotti/MWL_PDF_OrthancDemo

https://book.orthanc-server.com/faq/log.html#log

As indicated in the Orthanc Book, the default modality worklist plugin is just a sample:

https://book.orthanc-server.com/plugins/worklists-plugin.html

On each C-FIND request, this plugin will read all the content of the "Database" folder in the "Worklists" section of the configuration file. Depending on the number of files and on the performance of your disk, this operation might take time.

If this is a problem for you, you could try and serve your worklists from a SSD drive (instead of a HDD, which should greatly improve the throughput). You could also develop a more efficient version of the plugin, e.g. using Python:

https://book.orthanc-server.com/plugins/python.html#handling-worklist-scp-requests-new-in-3-2

This Python plugin could load all the worklists into RAM during the startup, and monitor the changes to the worklists using e.g. the "watchdog" module:

http://thepythoncorner.com/dev/how-to-create-a-watchdog-in-python-to-look-for-filesystem-changes/

Finally, instead of scanning a folder for worklists, you could consider creating a plugin that uses HL7 messages or REST calls to update the worklist databases:

https://book.orthanc-server.com/contributing.html

findscu -W 127.0.0.1 4242 -k 0008,0050="*" -k 0010,0010="*" -k 0010,2110="*" -k 0032,1060 -k "ScheduledProcedureStepSequence[0].Modality" -k "ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartDate=20221101"

findscu -W 127.0.0.1 4242 -k 0008,0050="*" -k 0010,0010="*" -k 0010,0020 -k 0010,2110="*" -k 0032,1060 -k "ScheduledProcedureStepSequence[0].Modality" -k "ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartDate=20221101" -k "ScheduledProcedureStepSequence[0].RequestedContrastAgent" -k "ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartTime"

findscu -W 127.0.0.1 4242 -k 0008,0050="*" -k 0010,0010="DEW^kri" -k 0010,2110="*" -k 0032,1060

findscu -W 127.0.0.1 4242 -k 0008,0050="*"

findscu -W -k "ScheduledProcedureStepSequence[0].Modality=CR" 127.0.0.1 4242

findscu -v -d --study -k 0008,0052=STUDY -k 0010,0010="LastName^FirstName" -k 0010,0030=19290301 -k 0010,0020 -k 0020,000D 127.0.0.1 4242

it will generate a new log file in C:\Program Files\Orthanc Server\Logs on Windows and in /var/log/orthanc/ on Linux


By default findscu will query for imaging studies. The output file you have specified will be DICOM binary format. You can specify the output to be xml using the -X option.

To query a Dicom Modality Worklist use '-M MWL'. You can also specify query and return keys in an xml file - see etc/findscu/mwl.xml.

example: ./findscu -c DCM4CHEE@localhost:11112 -M MWL -X --out-cat --out-file test.xml --out-dir ~/work -- ../etc/findscu/mwl.xml

Command: findscu -c xxxx...@127.0.0.1:11112 -m StudyDate=20211101 --out-cat --out-file test.csv --out-dir ~/work/

Output: 20210615 R STUDY T DCM4CHEE V ONLINEˆ 0 ˆ @ 20210615 R STUDY T DCM4CHEE V ONLINEˆ 0 ˆ @

(0008,0020) StudyDate

(0008,0030) StudyTime

(0008,0050) AccessionNumber

(0008,0090) ReferringPhysicianName

(0010,0010) PatientName

(0010,0020) PatientID

(0010,0021) IssuerOfPatientID

(0010,0030) PatientBirthDate

(0010,0040) PatientSex

(0010,2297) Responsible Person

(0010,2298) Responsible Person Role

(0032,1032) RequestingPhysician

(0038,0010) AdmissionID

(0040,0100) ScheduledProcedureStepSequence

(0008,0060) > Modality

(0040,0001) > ScheduledStationAETitle

(0040,0002) > ScheduledProcedureStepStartDate

(0040,0003) > ScheduledProcedureStepStartTime

(0040,0006) > ScheduledPerformingPhysicianName

(0040,1001) RequestedProcedureID

(0040,1003) RequestedProcedurePriority


https://github.com/101josh10/Radiology-Information-System

test

https://book.orthanc-server.com/plugins/worklists-plugin.html#worklists-plugin

https://github.com/sscotti/python_script_library

https://book.orthanc-server.com/plugins/python.html#handling-worklist-scp-requests-new-in-3-2

https://github.com/bjoernalbers/mowoli

python create mwl

https://github.com/opendicom/opendicomMWLpy

https://stackoverflow.com/questions/71015541/is-there-a-python-dicom-modality-worklist-setup-library

dcmdump wklist1.wl > sample-worklist.txt

dump2dcm sample-worklist.txt sample-worklist.wl

https://groups.google.com/g/orthanc-users/c/6ygCGjhDrsA

python file

import json

import orthanc

def OnChange(changeType, level, resource):

if changeType == orthanc.ChangeType.ORTHANC_STARTED:

print('Started')

mwlquery = dict()

mwlquery["AccessionNumber"] = '00007'

MWL = orthanc.RestApiPost('/modalities/PACS1/find-worklist', json.dumps(mwlquery))

print(MWL)

orthanc.RegisterOnChangeCallback(OnChange)

Json file

Plugins:

0: "/home/jodogne/orthanc-python/Build"

1: "/home/jodogne/orthanc/Build"

PythonScript: "scotti.py"

DicomModalities:

PACS1:

0: "ORTHANC"

1: "localhost"

2: 4242

Worklists:

Enable: true

Database: "/home/jodogne/orthanc/OrthancServer/Plugins/Samples/ModalityWorklists/WorklistsDatabase"

------------

Using Orthanc Worklist Plugin

Orthanc server has worklist plugin1 which will serve worklist files that are stored in a particular directory. Let us download sample worklist files from Orthanc repository and keep in "WorklistDatabase" directory.

Generate default configuration by running the following command.

$ ./Orthanc --config=config.json


In the orthanc configuration file, enable worklist plugin, specify the worklist database directory so that Orthanc can locate relevant worklist files, add required modalities and restart the server.

"Plugins" : [

"libModalityWorklists.dylib"

],


"Worklists" : {

"Enable": true,

"Database": "./WorklistsDatabase",

"FilterIssuerAet": false,

"LimitAnswers": 0

},


"DicomModalities" : {

"PYNETDICOM" : ["PYNETDICOM", "127.0.0.1", 4243],

"FINDSCU" : ["FINDSCU", "127.0.0.1", 4244]

}


Once the plugin is enabled, we can use findscu to send C-FIND query.

$ findscu -W -k "ScheduledProcedureStepSequence" 127.0.0.1 4242


This will retrieve all worklist files from the server.

Using wlmscpfs

dcmtk 2 is a collection of utilities for DICOM standard. It has wlmscpfs application which implements basic Service Class Provider(SCP). We can start the service by running the following command.

wlmscpfs --debug --data-files-path WorklistsDatabase 4242


Once the service is started modalities can send C-FIND query to this service.

Conclusion

We have seen how to setup MWL SCP using Orthanc & wmlscpfs. Now that we have PACS & WML SCP up and running, in the next article lets see how to dig deeper in to the dicom standard.


  1. https://book.orthanc-server.com/plugins/worklists-plugin.html

  2. https://github.com/DCMTK/dcmtk

---------------------

https://www.findbestopensource.com/product/janpipek-pydiq

https://github.com/janpipek/pydiq

https://github.com/wenyalintw/Dicom-Viewer ยังเเปิดได้แต่ PNG

https://github.com/josvromans/imageviewer/tree/3860e96e27edfb551077d6b216698ad7bd9aea9a เปิดได้แต่ jpg

https://morphuslabs.com/how-i-got-into-hacking-ultrasound-machines-part-02-3b16b799974c


Thai ISO 2022 IR 166



ระบบ PACS (Picture Archiving and Communication System) [4]

PACS คือระบบที่ใช้ในการจัดเก็บรูปภาพทางการแพทย์ (Medical Images) หรือภาพถ่ายทางรังสี โดยมีการรับส่งข้อมูลภาพในรูปแบบดิจิตอล PACS ใช้การจัดการรับส่งข้อมูล ผ่านทางระบบเครือข่ายคอมพิวเตอร์ โดยการส่งภาพข้อมูลตามมาตรฐาน DICOM ระบบ PACS จะช่วยให้แพทย์ได้รับภาพถ่ายทางรังสีและผลวิเคราะห์จากรังสีแพทย์อย่างรวดเร็ว ทำให้แพทย์วินิจฉัยโรคและให้การรักษาผู้ป่วยได้เร็วยิ่งขึ้น โดยเฉพาะผู้ป่วยหนัก นอกจากนี้ ปัญหาการจัดเก็บและค้นหาฟิล์มเอกซเรย์ ก็ทำให้เกิดความล่าช้าของการรายงานผลเอกซเรย์ได้ บางครั้งเราอาจจะพบว่ามีการสูญหายของฟิล์มเอกซเรย์ ซึ่งมีความจำเป็นในการใช้เปรียบเทียบการเปลี่ยนแปลงของโรค ระบบ PACS มีการจัดเก็บข้อมูลไว้ในคอมพิวเตอร์ซึ่งมีระบบเก็บข้อมูลสำรอง จึงช่วยแก้ปัญหานี้ได้

ข้อสังเกต DICOM file

- DICOM files are not recognized by Windows® as image files ดังนั้น เราไม่สามารถเปิดไฟล์โดยใช้ software หรือ application ทั่วไปได้ [2]

- ในการจะเปิดดูไฟล์ จำเป็นต้องใช้ additional software package called “DICOM browser” เช่น 3D-Doctor Viewer v 4.0.070803, DCM View etc. [3]

- รูปภาพที่แสดงจะประกอบไปด้วยจุดจำนวนมาก เรียกแต่ละจุดนี่ว่า “pixels” ซึ่งจำนวน pixels นี่ก็ขึ้นอยู่กับ ชนิดของ Digital medical image ที่เราใช้ เช่น ถ้าเป็นของ CT scan จะเป็น 512 x 512 pixels ขณะที่ของ MRI จะเป็น 256 x 256 pixels โดยพื้นที่ในการจัดเก็บ และ Resolution ของ Digital image ต่างๆ เป็นไปตามตารางนี้ [2]


Computer tomography (CT)

หลักการ [5]

- เป็นการปล่อย X-ray ลำแคบๆ กระทบตัวผู้ป่วยและเก็บภาพโดย Detector โดยที่จะมีการเก็บข้อมูลในมุมที่ต่างๆ กัน และนำข้อมูลที่ได้ไปประมวลผลโดย Computer เพื่อแปรผลภาพออกมาในมุมและระนาบที่ต้องการ

- ปัจจุบันได้มีการพัฒนาขึ้นโดยให้มีการฉาย X-ray เป็นรูปพัด โดยที่มี Detector เรียงตัวเป็นวงกลมโดยรอบและมีเพียงหลอด X-ray เท่านั้นที่หมุนรอบตัวผู้ป่วย

ลักษณะการสแกน

1. Single scan CT สแกนเป็น Shot

2. Spiral CT สแกนต่อเ้นื่องเป็นวง

Density

ในภาพ CT นั้นจะได้ออกมาเป็น Grayscale Picture ซึ่งมีเฉดสีเทาที่สามารถแยกได้หลายระดับ โดยที่จะวัดหน่วยเป็น Hounsfield unit (HU) ซึ่งมีตั้งแต่ -1000 HU ไปจนถึง +1000 HU โดยมีรายละเอียดคร่าวๆ ดังนี้

Air < -500 HU ดำสุด

Fat < -90 HU

Water & CSF 0 HU

Hematoma 50–90 HU

Calcification > +80 HU

Bone > +500 HU ขาวสุด

What is a Hounsfield unit or CT number? [6][10]

The unit of measurement in CT scans is the Hounsfield Unit (HU), which is a measure of radiodensity. The range of CT numbers is 2000 HU wide although some modern scanners have a greater range of HU up to 4000. Each number represents a shade of grey with +1000 (white) and –1000 (black) at either end of the spectrum. (note: the upper limit is determined by the scanner type). [12]

Axial computed tomography (CT) image with sample typical CT numbers in HU. CSF, cerebrospinal fluid. [11]

Display Parameter [5]

หน่วยที่ใช้วัดความหนาแน่น(ความเข้ม)ของอวัยวะต่างๆในร่างกายจากภาพ CT image คือ Hounsfield Unit โดยมีความกว้างของหน่วยตั้งแต่ -1,000 ไปจนถึง +1,000 ซึ่งทำให้สามารถแสดงเฉดสีเทาที่แตกต่างกันออกไปได้มากถึง 2,000 เฉด แต่เนื่องจากความสามารถทางกายภาพ หรือตาของมนุษย์ไม่สามารถจะแยกแยะความแตกต่างได้มากขนาดนั้น จึงจำเป็นต้องกำหนดกรอบเฉพาะ ช่วงค่าที่เราสนใจ เพื่อให้แพทย์สามารถแปลผลได้ดีขึ้น โดยการปรับ Parameter 2 ตัวนี้

1. Window Level (WL)

เป็นค่าที่ใช้ระบุค่าสีเทากลางของภาพ ว่าต้องการให้มีการแสดงผลที่ระดับความเข้มใดเป็นหลัก เช่น ถ้าหากต้องการที่จะดูส่วนที่เป็นกระดูก ก็ควรตั้งค่าให้สูงในช่วงระดับของความเข้มระดับของกระดูก ( เช่น 700 HU เป็นต้น)

2. Window Width (WW)

เป็นการระบุค่าความกว้าง หรือ Range ที่ต้องการให้มีการแสดงผลระดับเฉดสีเทานั้นๆ ซึ่งจะยึดจากค่า Level เป็นหลัก ว่าต้องการค่ากว้างเท่าใด (ตัวอย่างเช่น Level = +700 HU และ Window = 200 HU จะทำให้มีการแสดงผลเฉพาะช่วง +600 ถึง +800 เท่านั้น)

****** หมายเหตุ : ตัวเลขในหัวข้อนี้เป็นเพียงการสมมติให้เข้าใจได้ง่ายขึ้นเท่านั้น ไม่ควรยึดติดเป็นตัวเลขที่ใช้จริง ******

หมายถึง สารที่ใช้ในการตรวจทางรังสีวิทยา เพื่อให้เกิดความแตกต่างในการดูดกลืนรังสีระหว่างอวัยวะที่ต้องการตรวจกับอวัยวะหรือโครงสร้างอื่นที่อยู่ใกล้เคียง เป็นผลให้เห็นอวัยวะที่ต้องการตรวจได้ชัดเจนขึ้น ซึ่งสามารถนำเข้าสู่ร่างกายได้หลายทาง เช่น การรับประทาน , การสวนเข้าทางทวารหนัก และฉีดเข้าหลอดเลือด หรือเข้าช่องโพรงของร่างกาย (จามรี, 2538 : ชรินทร์, 2542 : สมเกียรติ, 2538)

สารทึบรังสีชนิดฉีดเข้าหลอดเลือด เป็นสารที่มีความจำเป็นในการแยกความแตกต่างของอวัยวะที่ต้องการตรวจกับอวัยวะที่อยู่ใกล้เคียง ทั้งนี้เพื่อช่วยให้ภาพจากการตรวจทางรังสีมีความชัดเจนมากขึ้น ดังนั้นสารทึบรังสีจึงเข้ามามีบทบาทในการตรวจทางรังสีหลายชนิด ได้แก่ การตรวจเอกซเรย์คอมพิวเตอร์ ( CT ), การตรวจดูการทำงานของไต (Intravenous pyelography ), การถ่ายภาพรังสีหลอดเลือด ( Angiography / Venography ), การตรวจด้วยคลื่นแม่เหล็กไฟฟ้า ( MRI )

การตรวจ CT จำเป็นต้องมีการใช้สารทึบรังสี (iodinated contrast medium; ICM) เพื่อช่วยในการแยกแยะพยาธิ สภาพออกจากอวัยวะปกติภายใน CNS โดยเฉพาะ โรคของหลอดเลือด เนื้องอกและการติดเชื้อ ICM มี หลายชนิดและมีวิธีการให้ขึ้นอยู่กับข้อบ่งชี้ในผู้ป่วย แต่ละราย [9]

สำหรับคนที่กำลังจะเริ่มทำ Deep learning on CT image ผมแนะนำลองไปติดตามอ่าน Blog ของ ThaiKeras ตาม Link นี้เลยครับ เพื่อเป็นแนวทางในการ prepare data ก่อน จะ feed เข้า Model ครับ

Ref:

1. https://sites.google.com/site/medicaldigitalimage/home/digital-image-distribution-and-networks/dicom

2. Varma DR. Managing DICOM images: Tips and tricks for the radiologist. The Indian journal of radiology & imaging. 2012 Jan;22(1):4.

3. Varma DR. Free DICOM browsers. The Indian journal of radiology & imaging. 2008 Feb;18(1):12.

4. https://med.mahidol.ac.th/sdmc/th/technology/PAC-th

5. http://ventangelo.blogspot.com/2010/10/principle-of-ct-and-mri.html

6. https://web.archive.org/web/20071129085332/http://www.intl.elsevierhealth.com/e-books/pdf/940.pdf

7. https://oncologymedicalphysics.com/ct-basic-operations/

8. https://www.vibhavadi.com/health186

9. https://thaistrokesociety.files.wordpress.com/2017/05/09-iodinated-contrast-medium_30-03-60.pdf

10. https://towardsdatascience.com/medical-image-analysis-with-deep-learning-9557cad44944

11. https://www.sciencedirect.com/topics/medicine-and-dentistry/hounsfield-scale

12. https://www.startradiology.com/the-basics/x-rayct-technique/