OpenREM 1.0.0b2__py3-none-any.whl → 1.0.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. openrem/locale/de/LC_MESSAGES/django.po +1060 -1059
  2. openrem/locale/django.pot +973 -972
  3. openrem/locale/es_MX/LC_MESSAGES/django.po +1049 -1048
  4. openrem/locale/it/LC_MESSAGES/django.po +1044 -1043
  5. openrem/locale/lt/LC_MESSAGES/django.po +989 -988
  6. openrem/locale/nb_NO/LC_MESSAGES/django.po +985 -984
  7. openrem/locale/pt_BR/LC_MESSAGES/django.po +1003 -1002
  8. openrem/manage.py +10 -10
  9. openrem/openremproject/__init__.py +1 -1
  10. openrem/openremproject/local_settings.py.linux +128 -128
  11. openrem/openremproject/local_settings.py.windows +144 -144
  12. openrem/openremproject/local_settings.py.windows-sqlite3 +129 -129
  13. openrem/openremproject/settings.py +278 -278
  14. openrem/openremproject/urls.py +32 -32
  15. openrem/openremproject/wsgi.py.example +28 -28
  16. openrem/remapp/__init__.py +2 -2
  17. openrem/remapp/admin.py +31 -31
  18. openrem/remapp/exports/ct_export.py +780 -753
  19. openrem/remapp/exports/dx_export.py +817 -805
  20. openrem/remapp/exports/export_common.py +931 -951
  21. openrem/remapp/exports/export_common_pandas.py +2422 -0
  22. openrem/remapp/exports/exportviews.py +815 -860
  23. openrem/remapp/exports/mg_csv_nhsbsp.py +292 -292
  24. openrem/remapp/exports/mg_export.py +673 -510
  25. openrem/remapp/exports/nm_export.py +796 -575
  26. openrem/remapp/exports/rf_export.py +1418 -1431
  27. openrem/remapp/extractors/ct_philips.py +424 -414
  28. openrem/remapp/extractors/ct_toshiba.py +2116 -2108
  29. openrem/remapp/extractors/dx.py +1033 -952
  30. openrem/remapp/extractors/extract_common.py +817 -817
  31. openrem/remapp/extractors/import_views.py +426 -426
  32. openrem/remapp/extractors/mam.py +685 -672
  33. openrem/remapp/extractors/nm_image.py +439 -431
  34. openrem/remapp/extractors/ptsizecsv2db.py +368 -368
  35. openrem/remapp/extractors/rdsr.py +667 -654
  36. openrem/remapp/extractors/rdsr_methods.py +1771 -1768
  37. openrem/remapp/extractors/rrdsr_methods.py +630 -622
  38. openrem/remapp/fixtures/openskin_safelist.json +11 -11
  39. openrem/remapp/forms.py +2286 -2277
  40. openrem/remapp/interface/chart_functions.py +2412 -2393
  41. openrem/remapp/interface/mod_filters.py +1241 -1243
  42. openrem/remapp/migrations/0001_initial.py.1-0-upgrade +1043 -1043
  43. openrem/remapp/models.py +3418 -3407
  44. openrem/remapp/netdicom/dicomviews.py +681 -683
  45. openrem/remapp/netdicom/qrscu.py +2646 -2646
  46. openrem/remapp/netdicom/tools.py +134 -134
  47. openrem/remapp/static/css/bootstrap-theme.css +587 -587
  48. openrem/remapp/static/css/bootstrap-theme.min.css +4 -4
  49. openrem/remapp/static/css/bootstrap.css +6800 -6800
  50. openrem/remapp/static/css/bootstrap.min.css +4 -4
  51. openrem/remapp/static/css/datepicker3.css +790 -790
  52. openrem/remapp/static/css/jquery.qtip.min.css +2 -2
  53. openrem/remapp/static/css/openrem-extra.css +442 -442
  54. openrem/remapp/static/css/openrem.css +96 -96
  55. openrem/remapp/static/css/registration.css +34 -34
  56. openrem/remapp/static/fonts/glyphicons-halflings-regular.svg +287 -287
  57. openrem/remapp/static/js/bootstrap-datepicker.js +1671 -1671
  58. openrem/remapp/static/js/bootstrap.js +2363 -2363
  59. openrem/remapp/static/js/bootstrap.min.js +6 -6
  60. openrem/remapp/static/js/charts/chartCommonFunctions.js +75 -75
  61. openrem/remapp/static/js/charts/chartFullScreen.js +41 -41
  62. openrem/remapp/static/js/charts/ctChartAjax.js +331 -331
  63. openrem/remapp/static/js/charts/dxChartAjax.js +290 -290
  64. openrem/remapp/static/js/charts/mgChartAjax.js +144 -144
  65. openrem/remapp/static/js/charts/nmChartAjax.js +64 -64
  66. openrem/remapp/static/js/charts/plotly-2.35.2.min.js +8 -0
  67. openrem/remapp/static/js/charts/rfChartAjax.js +128 -128
  68. openrem/remapp/static/js/chroma.min.js +32 -32
  69. openrem/remapp/static/js/datepicker.js +5 -5
  70. openrem/remapp/static/js/dicom.js +115 -115
  71. openrem/remapp/static/js/django_reverse/reverse.js +13 -13
  72. openrem/remapp/static/js/formatDate.js +7 -7
  73. openrem/remapp/static/js/html5shiv.min.js +8 -8
  74. openrem/remapp/static/js/jquery-1.11.0.min.js +4 -4
  75. openrem/remapp/static/js/npm.js +12 -12
  76. openrem/remapp/static/js/respond.min.js +4 -4
  77. openrem/remapp/static/js/skin-dose-maps/jquery.qtip.min.js +4 -4
  78. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMap3dHUDObject.js +112 -112
  79. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMap3dObject.js +367 -367
  80. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMap3dPersonObject.js +158 -158
  81. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMapColourScaleObject.js +153 -153
  82. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMapObject.js +367 -367
  83. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMapping.js +584 -584
  84. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMapping3d.js +255 -255
  85. openrem/remapp/static/js/skin-dose-maps/rfSkinDoseMappingAjax.js +267 -212
  86. openrem/remapp/static/js/skin-dose-maps/three.min.js +835 -835
  87. openrem/remapp/static/js/sorttable.js +495 -495
  88. openrem/remapp/templates/base.html +253 -253
  89. openrem/remapp/templates/registration/changepassword.html +25 -25
  90. openrem/remapp/templates/registration/changepassworddone.html +12 -12
  91. openrem/remapp/templates/registration/login.html +42 -42
  92. openrem/remapp/templates/remapp/backgroundtaskmaximumrows_form.html +29 -29
  93. openrem/remapp/templates/remapp/base.html +1 -1
  94. openrem/remapp/templates/remapp/ctdetail.html +235 -235
  95. openrem/remapp/templates/remapp/ctfiltered.html +310 -310
  96. openrem/remapp/templates/remapp/dicomdeletesettings_form.html +31 -31
  97. openrem/remapp/templates/remapp/dicomqr.html +147 -147
  98. openrem/remapp/templates/remapp/dicomquerydetails.html +83 -83
  99. openrem/remapp/templates/remapp/dicomqueryimages.html +49 -49
  100. openrem/remapp/templates/remapp/dicomqueryseries.html +109 -109
  101. openrem/remapp/templates/remapp/dicomquerysummary.html +48 -48
  102. openrem/remapp/templates/remapp/dicomremoteqr_confirm_delete.html +60 -60
  103. openrem/remapp/templates/remapp/dicomremoteqr_form.html +32 -32
  104. openrem/remapp/templates/remapp/dicomstorescp_confirm_delete.html +53 -53
  105. openrem/remapp/templates/remapp/dicomstorescp_form.html +48 -48
  106. openrem/remapp/templates/remapp/dicomsummary.html +257 -257
  107. openrem/remapp/templates/remapp/displaychartoptions.html +184 -184
  108. openrem/remapp/templates/remapp/displayhomepageoptions.html +57 -57
  109. openrem/remapp/templates/remapp/displayname-count.html +6 -6
  110. openrem/remapp/templates/remapp/displayname-last-date.html +3 -3
  111. openrem/remapp/templates/remapp/displayname-modality.html +86 -105
  112. openrem/remapp/templates/remapp/displayname-skinmap.html +18 -18
  113. openrem/remapp/templates/remapp/displaynameupdate.html +100 -100
  114. openrem/remapp/templates/remapp/displaynameview.html +222 -219
  115. openrem/remapp/templates/remapp/dxdetail.html +176 -176
  116. openrem/remapp/templates/remapp/dxfiltered.html +324 -324
  117. openrem/remapp/templates/remapp/exports-active.html +25 -25
  118. openrem/remapp/templates/remapp/exports-complete.html +35 -35
  119. openrem/remapp/templates/remapp/exports-error.html +26 -26
  120. openrem/remapp/templates/remapp/exports-queue.html +18 -18
  121. openrem/remapp/templates/remapp/exports.html +191 -191
  122. openrem/remapp/templates/remapp/failed_summary_list.html +27 -27
  123. openrem/remapp/templates/remapp/filteredbase.html +162 -162
  124. openrem/remapp/templates/remapp/highdosemetricalertsettings_form.html +76 -76
  125. openrem/remapp/templates/remapp/home-list-modalities.html +94 -94
  126. openrem/remapp/templates/remapp/home.html +202 -202
  127. openrem/remapp/templates/remapp/list_filters.html +24 -24
  128. openrem/remapp/templates/remapp/mgdetail.html +160 -138
  129. openrem/remapp/templates/remapp/mgfiltered.html +311 -311
  130. openrem/remapp/templates/remapp/nmdetail.html +300 -300
  131. openrem/remapp/templates/remapp/nmfiltered.html +255 -255
  132. openrem/remapp/templates/remapp/notpatient.html +190 -190
  133. openrem/remapp/templates/remapp/notpatientindicators_form_base.html +81 -81
  134. openrem/remapp/templates/remapp/notpatientindicatorsid_confirm_delete.html +54 -54
  135. openrem/remapp/templates/remapp/notpatientindicatorsid_form.html +23 -23
  136. openrem/remapp/templates/remapp/notpatientindicatorsname_confirm_delete.html +54 -54
  137. openrem/remapp/templates/remapp/notpatientindicatorsname_form.html +23 -23
  138. openrem/remapp/templates/remapp/notpatientindicatorsname_form_base.html +85 -85
  139. openrem/remapp/templates/remapp/openskinsafelist_add.html +130 -130
  140. openrem/remapp/templates/remapp/openskinsafelist_confirm_delete.html +100 -100
  141. openrem/remapp/templates/remapp/openskinsafelist_form.html +207 -207
  142. openrem/remapp/templates/remapp/patientidsettings_form.html +83 -83
  143. openrem/remapp/templates/remapp/populate_summary_progress.html +83 -83
  144. openrem/remapp/templates/remapp/populate_summary_progress_error.html +36 -36
  145. openrem/remapp/templates/remapp/review_failed_imports.html +157 -157
  146. openrem/remapp/templates/remapp/review_failed_study.html +41 -41
  147. openrem/remapp/templates/remapp/review_studies_delete_button.html +20 -20
  148. openrem/remapp/templates/remapp/review_study.html +19 -19
  149. openrem/remapp/templates/remapp/review_summary_list.html +245 -245
  150. openrem/remapp/templates/remapp/rf_dose_alert_email_template.html +14 -1
  151. openrem/remapp/templates/remapp/rfalertnotificationsview.html +59 -59
  152. openrem/remapp/templates/remapp/rfdetail.html +547 -543
  153. openrem/remapp/templates/remapp/rfdetailbase.html +18 -18
  154. openrem/remapp/templates/remapp/rffiltered.html +404 -404
  155. openrem/remapp/templates/remapp/sizeimports.html +119 -119
  156. openrem/remapp/templates/remapp/sizeprocess.html +96 -96
  157. openrem/remapp/templates/remapp/sizeupload.html +110 -110
  158. openrem/remapp/templates/remapp/skindosemapcalcsettings_form.html +28 -28
  159. openrem/remapp/templates/remapp/standardname-modality.html +69 -69
  160. openrem/remapp/templates/remapp/standardnames_confirm_delete.html +71 -71
  161. openrem/remapp/templates/remapp/standardnames_form.html +87 -87
  162. openrem/remapp/templates/remapp/standardnamesettings_form.html +41 -41
  163. openrem/remapp/templates/remapp/standardnamesrefreshall.html +92 -92
  164. openrem/remapp/templates/remapp/standardnameview.html +103 -103
  165. openrem/remapp/templates/remapp/study_confirm_delete.html +147 -147
  166. openrem/remapp/templates/remapp/task_admin.html +265 -265
  167. openrem/remapp/templates/remapp/tasks.html +76 -76
  168. openrem/remapp/templatetags/formfilters.py +13 -13
  169. openrem/remapp/templatetags/proper_paginate.py +38 -38
  170. openrem/remapp/templatetags/remappduration.py +36 -36
  171. openrem/remapp/templatetags/sigdig.py +38 -38
  172. openrem/remapp/templatetags/sort_class_property_value.py +15 -15
  173. openrem/remapp/templatetags/update_variable.py +20 -20
  174. openrem/remapp/templatetags/url_replace.py +25 -25
  175. openrem/remapp/tests/test_charts_common.py +202 -202
  176. openrem/remapp/tests/test_charts_ct.py +7111 -7111
  177. openrem/remapp/tests/test_charts_dx.py +3513 -3513
  178. openrem/remapp/tests/test_charts_mg.py +1116 -1115
  179. openrem/remapp/tests/test_dcmdatetime.py +189 -189
  180. openrem/remapp/tests/test_dicom_qr.py +2580 -2580
  181. openrem/remapp/tests/test_display_name.py +274 -274
  182. openrem/remapp/tests/test_export_ct_xlsx.py +272 -248
  183. openrem/remapp/tests/test_export_dx_xlsx.py +137 -134
  184. openrem/remapp/tests/test_export_mammo_csv.py +242 -242
  185. openrem/remapp/tests/test_export_rf_xlsx.py +246 -246
  186. openrem/remapp/tests/test_files/DX-Im-DRGEM.dcm +0 -0
  187. openrem/remapp/tests/test_files/MG-RDSR-GEPristina-2D.dcm +0 -0
  188. openrem/remapp/tests/test_files/MG-RDSR-GEPristina-DBT.dcm +0 -0
  189. openrem/remapp/tests/test_files/MG-RDSR-Giotto-DBT.dcm +0 -0
  190. openrem/remapp/tests/test_files/skin_map_alphenix.py +590 -590
  191. openrem/remapp/tests/test_files/skin_map_zee.py +354 -354
  192. openrem/remapp/tests/test_filters_ct.py +321 -321
  193. openrem/remapp/tests/test_filters_dx.py +92 -92
  194. openrem/remapp/tests/test_filters_mammo.py +183 -183
  195. openrem/remapp/tests/test_filters_rf.py +118 -118
  196. openrem/remapp/tests/test_get_values.py +72 -72
  197. openrem/remapp/tests/test_hash_id.py +65 -65
  198. openrem/remapp/tests/test_import_ct_esr_ge.py +3034 -3034
  199. openrem/remapp/tests/test_import_ct_philips_rdsr.py +42 -42
  200. openrem/remapp/tests/test_import_ct_rdsr_multiple.py +256 -256
  201. openrem/remapp/tests/test_import_ct_rdsr_siemens.py +827 -827
  202. openrem/remapp/tests/test_import_ct_rdsr_spectrumdynamics.py +91 -91
  203. openrem/remapp/tests/test_import_ct_rdsr_toshiba_dosecheck.py +67 -67
  204. openrem/remapp/tests/test_import_ct_rdsr_toshiba_multivaluesd.py +33 -33
  205. openrem/remapp/tests/test_import_ct_rdsr_toshiba_pixelmed.py +118 -118
  206. openrem/remapp/tests/test_import_ct_sc_philips.py +44 -44
  207. openrem/remapp/tests/test_import_dual_rdsr.py +110 -110
  208. openrem/remapp/tests/test_import_dx.py +1267 -1191
  209. openrem/remapp/tests/test_import_dx_rdsr.py +1250 -1253
  210. openrem/remapp/tests/test_import_mam.py +438 -438
  211. openrem/remapp/tests/test_import_mg_im_hol_proj.py +46 -46
  212. openrem/remapp/tests/test_import_mg_rdsr.py +586 -586
  213. openrem/remapp/tests/test_import_nm_image.py +420 -420
  214. openrem/remapp/tests/test_import_nm_siemens_rdsr.py +396 -396
  215. openrem/remapp/tests/test_import_px.py +161 -161
  216. openrem/remapp/tests/test_import_rf_rdsr.py +420 -418
  217. openrem/remapp/tests/test_missing_date.py +42 -42
  218. openrem/remapp/tests/test_not_patient.py +60 -60
  219. openrem/remapp/tests/test_openskin.py +272 -272
  220. openrem/remapp/tests/test_patient_id_settings.py +72 -72
  221. openrem/remapp/tests/test_pt_size_import.py +232 -232
  222. openrem/remapp/tests/test_rf_detail.py +113 -113
  223. openrem/remapp/tests/test_rf_high_dose_alert.py +361 -361
  224. openrem/remapp/tools/background.py +361 -361
  225. openrem/remapp/tools/check_standard_name_status.py +47 -0
  226. openrem/remapp/tools/check_uid.py +70 -70
  227. openrem/remapp/tools/dcmdatetime.py +248 -248
  228. openrem/remapp/tools/default_import.py +44 -47
  229. openrem/remapp/tools/get_values.py +230 -230
  230. openrem/remapp/tools/hash_id.py +58 -58
  231. openrem/remapp/tools/make_skin_map.py +448 -406
  232. openrem/remapp/tools/not_patient_indicators.py +72 -72
  233. openrem/remapp/tools/openskin/calc_exp_map.py +173 -173
  234. openrem/remapp/tools/openskin/geomclass.py +475 -475
  235. openrem/remapp/tools/openskin/geomfunc.py +433 -432
  236. openrem/remapp/tools/openskin/skinmap.py +417 -417
  237. openrem/remapp/tools/populate_summary.py +185 -193
  238. openrem/remapp/tools/save_skin_map_structure.py +73 -73
  239. openrem/remapp/tools/send_high_dose_alert_emails.py +238 -207
  240. openrem/remapp/urls.py +456 -448
  241. openrem/remapp/version.py +11 -11
  242. openrem/remapp/views.py +1147 -1052
  243. openrem/remapp/views_admin.py +3876 -3936
  244. openrem/remapp/views_charts_ct.py +2110 -2058
  245. openrem/remapp/views_charts_dx.py +1906 -1836
  246. openrem/remapp/views_charts_mg.py +1349 -1196
  247. openrem/remapp/views_charts_nm.py +535 -535
  248. openrem/remapp/views_charts_rf.py +1219 -1241
  249. openrem/remapp/views_openskin.py +379 -384
  250. openrem/sample-config/openrem-consumer.service +12 -12
  251. openrem/sample-config/openrem-gunicorn.service +13 -13
  252. openrem/sample-config/openrem-server +14 -13
  253. openrem/sample-config/openrem_orthanc_config_linux.lua +454 -454
  254. openrem/sample-config/openrem_orthanc_config_windows.lua +455 -455
  255. openrem/sample-config/queue-init.bat +73 -73
  256. openrem/scripts/openrem_ctphilips.py +25 -25
  257. openrem/scripts/openrem_cttoshiba.py +28 -28
  258. openrem/scripts/openrem_dx.py +22 -22
  259. openrem/scripts/openrem_mg.py +22 -22
  260. openrem/scripts/openrem_nm.py +22 -22
  261. openrem/scripts/openrem_ptsizecsv.py +17 -17
  262. openrem/scripts/openrem_qr.py +12 -12
  263. openrem/scripts/openrem_rdsr.py +25 -25
  264. {OpenREM-1.0.0b2.dist-info → openrem-1.0.0b3.dist-info}/METADATA +39 -29
  265. openrem-1.0.0b3.dist-info/RECORD +379 -0
  266. {OpenREM-1.0.0b2.dist-info → openrem-1.0.0b3.dist-info}/WHEEL +1 -1
  267. {OpenREM-1.0.0b2.dist-info → openrem-1.0.0b3.dist-info/licenses}/COPYING-GPLv3 +674 -674
  268. {OpenREM-1.0.0b2.dist-info → openrem-1.0.0b3.dist-info/licenses}/LICENSE +22 -22
  269. OpenREM-1.0.0b2.dist-info/RECORD +0 -373
  270. openrem/remapp/static/js/charts/plotly-2.17.1.min.js +0 -8
  271. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_ctphilips.py +0 -0
  272. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_cttoshiba.py +0 -0
  273. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_dx.py +0 -0
  274. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_mg.py +0 -0
  275. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_nm.py +0 -0
  276. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_ptsizecsv.py +0 -0
  277. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_qr.py +0 -0
  278. {OpenREM-1.0.0b2.data → openrem-1.0.0b3.data}/scripts/openrem_rdsr.py +0 -0
  279. {OpenREM-1.0.0b2.dist-info → openrem-1.0.0b3.dist-info}/top_level.txt +0 -0
@@ -1,406 +1,448 @@
1
- # This Python file uses the following encoding: utf-8
2
- # OpenREM - Radiation Exposure Monitoring tools for the physicist
3
- # Copyright (C) 2012,2013 The Royal Marsden NHS Foundation Trust
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # Additional permission under section 7 of GPLv3:
16
- # You shall not make any use of the name of The Royal Marsden NHS
17
- # Foundation trust in connection with this Program in any press or
18
- # other public announcement without the prior written consent of
19
- # The Royal Marsden NHS Foundation Trust.
20
- #
21
- # You should have received a copy of the GNU General Public License
22
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
-
24
- """
25
- .. module:: make_skin_map.
26
- :synopsis: Module to calculate skin dose map from study data.
27
-
28
- .. moduleauthor:: Ed McDonagh, David Platten, Wens Kong
29
-
30
- """
31
- import os
32
- import sys
33
- import logging
34
-
35
- import django
36
- from django.core.exceptions import ObjectDoesNotExist
37
- import numpy as np
38
-
39
- # Setup django. This is required on windows, because process is created via spawn and
40
- # django will not be initialized anymore then (On Linux this will only be executed once)
41
- basepath = os.path.dirname(__file__)
42
- projectpath = os.path.abspath(os.path.join(basepath, "..", ".."))
43
- if projectpath not in sys.path:
44
- sys.path.insert(1, projectpath)
45
- os.environ["DJANGO_SETTINGS_MODULE"] = "openremproject.settings"
46
- django.setup()
47
-
48
- from remapp.models import ( # pylint: disable=wrong-import-position
49
- GeneralStudyModuleAttr,
50
- SkinDoseMapResults,
51
- OpenSkinSafeList,
52
- )
53
- from .background import record_task_info # pylint: disable=wrong-import-position
54
- from .save_skin_map_structure import ( # pylint: disable=wrong-import-position
55
- save_openskin_structure,
56
- )
57
- from .openskin.calc_exp_map import CalcExpMap # pylint: disable=wrong-import-position
58
- from ..version import __skin_map_version__ # pylint: disable=wrong-import-position
59
-
60
- # Explicitly name logger so that it is still handled when using __main__
61
- logger = logging.getLogger("remapp.tools.make_skin_map")
62
-
63
-
64
- def make_skin_map(study_pk=None):
65
- # pylint: disable=too-many-branches
66
- # pylint: disable=too-many-statements
67
- # pylint: disable=too-many-locals
68
- # noqa: C901
69
-
70
- if study_pk:
71
- study = GeneralStudyModuleAttr.objects.get(pk=study_pk)
72
- record_task_info(
73
- f"Unit: {study.generalequipmentmoduleattr_set.get().unique_equipment_name.display_name} | "
74
- f"PK: {study_pk} | Study UID: {study.study_instance_uid.replace('.', '. ')}"
75
- )
76
-
77
- # Get all OpenSkinSafeList table entries that match the manufacturer and model name of the current study
78
- entries = OpenSkinSafeList.objects.all().filter(
79
- manufacturer=study.generalequipmentmoduleattr_set.get().manufacturer,
80
- manufacturer_model_name=study.generalequipmentmoduleattr_set.get().manufacturer_model_name,
81
- )
82
-
83
- # Look for an entry which has a matching software version with the current study,
84
- # or an entry where the software version is blank (any software version)
85
- entry = None
86
- for current_entry in entries:
87
- if (
88
- current_entry.software_version
89
- == study.generalequipmentmoduleattr_set.get().software_versions
90
- or current_entry.software_version is None
91
- or not current_entry.software_version
92
- ):
93
- entry = current_entry
94
- break
95
-
96
- if entry is None:
97
- # There is no match, so return a blank dummy openSkin structure without trying
98
- # to calculate a skin dose map
99
- return_structure = {
100
- "skin_map": [0, 0],
101
- "skin_map_version": __skin_map_version__,
102
- }
103
- save_openskin_structure(study, return_structure)
104
- return
105
-
106
- pat_mass_source = "assumed"
107
- try:
108
- pat_mass = float(study.patientstudymoduleattr_set.get().patient_weight)
109
- pat_mass_source = "extracted"
110
- except (ValueError, TypeError):
111
- pat_mass = 73.2
112
-
113
- if pat_mass == 0.0:
114
- pat_mass = 73.2
115
- pat_mass_source = "assumed"
116
-
117
- pat_height_source = "assumed"
118
- try:
119
- pat_height = (
120
- float(study.patientstudymoduleattr_set.get().patient_size) * 100
121
- )
122
-
123
- pat_height_source = "extracted"
124
- except (ValueError, TypeError):
125
- pat_height = 178.6
126
-
127
- if pat_height == 0.0:
128
- pat_height = 178.6
129
- pat_height_source = "assumed"
130
-
131
- ptr = None
132
- orientation_modifier = None
133
- try:
134
- ptr_meaning = (
135
- study.projectionxrayradiationdose_set.get()
136
- .irradeventxraydata_set.all()[0]
137
- .patient_table_relationship_cid.code_meaning.lower()
138
- )
139
- if ptr_meaning in "headfirst":
140
- ptr = "H"
141
- elif ptr_meaning in "feet-first":
142
- ptr = "F"
143
- else:
144
- logger.info(
145
- f"Study PK {study_pk}: Patient table relationship not recognised ({ptr_meaning}). "
146
- f"Assuming head first."
147
- )
148
- except AttributeError:
149
- logger.info(
150
- f"Study PK {study_pk}: Patient table relationship not found. Assuming head first."
151
- )
152
- except IndexError:
153
- logger.info(
154
- f"Study PK {study_pk}: No irradiation event x-ray data found. Assuming head first."
155
- )
156
- try:
157
- orientation_modifier_meaning = (
158
- study.projectionxrayradiationdose_set.get()
159
- .irradeventxraydata_set.all()[0]
160
- .patient_orientation_modifier_cid.code_meaning.lower()
161
- )
162
- if orientation_modifier_meaning in "supine":
163
- orientation_modifier = "S"
164
- elif orientation_modifier_meaning in "prone":
165
- orientation_modifier = "P"
166
- else:
167
- logger.info(
168
- f"Study PK {study_pk}: Orientation modifier not recognised ({orientation_modifier_meaning}). "
169
- f"Assuming supine."
170
- )
171
- except AttributeError:
172
- logger.info(
173
- f"Study PK {study_pk}: Orientation modifier not found. Assuming supine."
174
- )
175
- except IndexError:
176
- logger.info(
177
- f"Study PK {study_pk}: No irradiation event x-ray data found. Assuming supine."
178
- )
179
- if ptr and orientation_modifier:
180
- pat_pos_source = "extracted"
181
- pat_pos = ptr + "F" + orientation_modifier
182
- elif ptr:
183
- pat_pos_source = "supine assumed"
184
- pat_pos = ptr + "FS"
185
- elif orientation_modifier:
186
- pat_pos_source = "head first assumed"
187
- pat_pos = "HF" + orientation_modifier
188
- else:
189
- pat_pos_source = "assumed"
190
- pat_pos = "HFS"
191
- logger.debug(f"patPos is {pat_pos} and source is {pat_pos_source}")
192
-
193
- my_exp_map = CalcExpMap(
194
- phantom_type="3D",
195
- pat_pos=pat_pos,
196
- pat_mass=pat_mass,
197
- pat_height=pat_height,
198
- table_thick=0.5,
199
- table_width=45.0,
200
- table_length=150.0,
201
- matt_thick=4.0,
202
- )
203
-
204
- for (
205
- irrad
206
- ) in study.projectionxrayradiationdose_set.get().irradeventxraydata_set.all():
207
- try:
208
- delta_x = (
209
- float(
210
- irrad.irradeventxraymechanicaldata_set.get()
211
- .doserelateddistancemeasurements_set.get()
212
- .table_longitudinal_position
213
- )
214
- / 10.0
215
- )
216
- except (ObjectDoesNotExist, TypeError):
217
- delta_x = 0.0
218
- try:
219
- delta_y = (
220
- float(
221
- irrad.irradeventxraymechanicaldata_set.get()
222
- .doserelateddistancemeasurements_set.get()
223
- .table_lateral_position
224
- )
225
- / 10.0
226
- )
227
- except (ObjectDoesNotExist, TypeError):
228
- delta_y = 0.0
229
- try:
230
- delta_z = (
231
- float(
232
- irrad.irradeventxraymechanicaldata_set.get()
233
- .doserelateddistancemeasurements_set.get()
234
- .table_height_position
235
- )
236
- / 10.0
237
- )
238
- except (ObjectDoesNotExist, TypeError):
239
- delta_z = 0.0
240
- if irrad.irradeventxraymechanicaldata_set.get().positioner_primary_angle:
241
- angle_x = float(
242
- irrad.irradeventxraymechanicaldata_set.get().positioner_primary_angle
243
- )
244
- else:
245
- angle_x = 0.0
246
- try:
247
- angle_y = float(
248
- irrad.irradeventxraymechanicaldata_set.get().positioner_secondary_angle
249
- )
250
- except (ObjectDoesNotExist, TypeError):
251
- angle_y = 0.0
252
- try:
253
- d_ref = (
254
- float(
255
- irrad.irradeventxraymechanicaldata_set.get()
256
- .doserelateddistancemeasurements_set.get()
257
- .distance_source_to_isocenter
258
- )
259
- / 10.0
260
- - 15.0
261
- )
262
- except (ObjectDoesNotExist, TypeError):
263
- # This will result in failure to calculate skin dose map. Need a sensible default, or a lookup to a
264
- # user-entered value
265
- d_ref = None
266
- try:
267
- dap = float(irrad.dose_area_product)
268
- except (ObjectDoesNotExist, TypeError):
269
- dap = None
270
- try:
271
- ref_ak = float(irrad.irradeventxraysourcedata_set.get().dose_rp)
272
- except (ObjectDoesNotExist, TypeError):
273
- ref_ak = None
274
- try:
275
- kvp = np.mean(
276
- irrad.irradeventxraysourcedata_set.get()
277
- .kvp_set.all()
278
- .exclude(kvp__isnull=True)
279
- .exclude(kvp__exact=0)
280
- .values_list("kvp", flat=True)
281
- )
282
- kvp = float(kvp)
283
- if np.isnan(kvp):
284
- kvp = None
285
- except (ObjectDoesNotExist, TypeError):
286
- kvp = None
287
-
288
- filter_cu = 0.0
289
- if irrad.irradeventxraysourcedata_set.get().xrayfilters_set.all():
290
- for (
291
- xray_filter
292
- ) in irrad.irradeventxraysourcedata_set.get().xrayfilters_set.all():
293
- try:
294
- if xray_filter.xray_filter_material.code_value == "C-127F9":
295
- filter_cu += float(
296
- xray_filter.xray_filter_thickness_minimum
297
- )
298
- except AttributeError:
299
- pass
300
-
301
- if irrad.irradiation_event_type:
302
- run_type = irrad.irradiation_event_type.code_meaning
303
- else:
304
- run_type = None
305
- try:
306
- frames = float(
307
- irrad.irradeventxraysourcedata_set.get().number_of_pulses
308
- )
309
- except TypeError:
310
- try:
311
- frames = float(
312
- irrad.irradeventxraysourcedata_set.get().exposure_time
313
- / irrad.irradeventxraysourcedata_set.get()
314
- .pulsewidth_set.get()
315
- .pulse_width
316
- )
317
- except (ObjectDoesNotExist, TypeError):
318
- frames = None
319
- except ObjectDoesNotExist:
320
- frames = None
321
- try:
322
- end_angle = float(
323
- irrad.irradeventxraymechanicaldata_set.get().positioner_primary_end_angle
324
- )
325
- except (ObjectDoesNotExist, TypeError):
326
- end_angle = None
327
- if ref_ak and d_ref:
328
- my_exp_map.add_view(
329
- delta_x=delta_x,
330
- delta_y=delta_y,
331
- delta_z=delta_z,
332
- angle_x=angle_x,
333
- angle_y=angle_y,
334
- d_ref=d_ref,
335
- dap=dap,
336
- ref_ak=ref_ak,
337
- kvp=kvp,
338
- filter_cu=filter_cu,
339
- run_type=run_type,
340
- frames=frames,
341
- end_angle=end_angle,
342
- pat_pos=pat_pos,
343
- )
344
-
345
- # Flip the skin dose map left-right so the view is from the front
346
- # my_exp_map.my_dose.fliplr()
347
- my_exp_map.my_dose.total_dose = np.roll(
348
- my_exp_map.my_dose.total_dose,
349
- int(my_exp_map.phantom.phantom_flat_dist // 2),
350
- axis=0,
351
- )
352
- try:
353
- my_exp_map.my_dose.total_dose = np.rot90(my_exp_map.my_dose.total_dose)
354
- except ValueError:
355
- pass
356
- try:
357
- SkinDoseMapResults.objects.get(
358
- general_study_module_attributes=study
359
- ).delete()
360
- except ObjectDoesNotExist:
361
- pass
362
- # assume that calculation failed if max(peak_skin_dose) == 0 ==> set peak_skin_dose to None
363
- max_skin_dose = np.max(my_exp_map.my_dose.total_dose, initial=0)
364
- max_skin_dose = max_skin_dose if max_skin_dose > 0 else None
365
- try:
366
- dap_fraction = my_exp_map.my_dose.dap_count / float(study.total_dap)
367
- except ZeroDivisionError:
368
- dap_fraction = 1.0
369
- SkinDoseMapResults(
370
- general_study_module_attributes=study,
371
- patient_orientation=pat_pos,
372
- patient_mass=pat_mass,
373
- patient_mass_assumed=pat_mass_source,
374
- patient_size_assumed=pat_height_source,
375
- patient_orientation_assumed=pat_pos_source,
376
- phantom_width=my_exp_map.phantom.phantom_width,
377
- phantom_height=my_exp_map.phantom.phantom_height,
378
- phantom_depth=my_exp_map.phantom.phantom_depth,
379
- patient_size=pat_height,
380
- skin_map_version=__skin_map_version__,
381
- peak_skin_dose=max_skin_dose,
382
- dap_fraction=dap_fraction,
383
- ).save()
384
- return_structure = {
385
- "skin_map": my_exp_map.my_dose.total_dose.flatten().tolist(),
386
- "width": my_exp_map.phantom.width,
387
- "height": my_exp_map.phantom.height,
388
- "phantom_width": my_exp_map.phantom.phantom_width,
389
- "phantom_height": my_exp_map.phantom.phantom_height,
390
- "phantom_head_height": my_exp_map.phantom.phantom_head_height,
391
- "phantom_head_radius": my_exp_map.phantom.phantom_head_radius,
392
- "phantom_depth": my_exp_map.phantom.phantom_depth,
393
- "phantom_flat_dist": my_exp_map.phantom.phantom_flat_dist,
394
- "phantom_curved_dist": my_exp_map.phantom.phantom_curved_dist,
395
- "patient_height": pat_height,
396
- "patient_mass": pat_mass,
397
- "patient_orientation": pat_pos,
398
- "patient_height_source": pat_height_source,
399
- "patient_mass_source": pat_mass_source,
400
- "patient_orientation_source": pat_pos_source,
401
- "fraction_DAP": dap_fraction,
402
- "skin_map_version": __skin_map_version__,
403
- }
404
-
405
- # Save the return_structure as a pickle in a skin_maps sub-folder of the MEDIA_ROOT folder
406
- save_openskin_structure(study, return_structure)
1
+ # This Python file uses the following encoding: utf-8
2
+ # OpenREM - Radiation Exposure Monitoring tools for the physicist
3
+ # Copyright (C) 2012,2013 The Royal Marsden NHS Foundation Trust
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # Additional permission under section 7 of GPLv3:
16
+ # You shall not make any use of the name of The Royal Marsden NHS
17
+ # Foundation trust in connection with this Program in any press or
18
+ # other public announcement without the prior written consent of
19
+ # The Royal Marsden NHS Foundation Trust.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ """
25
+ .. module:: make_skin_map.
26
+ :synopsis: Module to calculate skin dose map from study data.
27
+
28
+ .. moduleauthor:: Ed McDonagh, David Platten, Wens Kong
29
+
30
+ """
31
+ import decimal
32
+ import os
33
+ import sys
34
+ import logging
35
+
36
+ import django
37
+ from django.core.exceptions import ObjectDoesNotExist
38
+ import numpy as np
39
+
40
+ # Setup django. This is required on windows, because process is created via spawn and
41
+ # django will not be initialized anymore then (On Linux this will only be executed once)
42
+ basepath = os.path.dirname(__file__)
43
+ projectpath = os.path.abspath(os.path.join(basepath, "..", ".."))
44
+ if projectpath not in sys.path:
45
+ sys.path.insert(1, projectpath)
46
+ os.environ["DJANGO_SETTINGS_MODULE"] = "openremproject.settings"
47
+ django.setup()
48
+
49
+ from remapp.models import ( # pylint: disable=wrong-import-position
50
+ GeneralStudyModuleAttr,
51
+ SkinDoseMapResults,
52
+ OpenSkinSafeList,
53
+ )
54
+ from .background import ( # pylint: disable=wrong-import-position
55
+ get_current_task,
56
+ )
57
+
58
+ from .save_skin_map_structure import ( # pylint: disable=wrong-import-position
59
+ save_openskin_structure,
60
+ )
61
+ from .openskin.calc_exp_map import CalcExpMap # pylint: disable=wrong-import-position
62
+ from ..version import __skin_map_version__ # pylint: disable=wrong-import-position
63
+
64
+ # Explicitly name logger so that it is still handled when using __main__
65
+ logger = logging.getLogger("remapp.tools.make_skin_map")
66
+
67
+
68
+ def make_skin_map(study_pk=None):
69
+ # pylint: disable=too-many-branches
70
+ # pylint: disable=too-many-statements
71
+ # pylint: disable=too-many-locals
72
+ # noqa: C901
73
+
74
+ background_task = get_current_task()
75
+
76
+ if study_pk:
77
+ study = GeneralStudyModuleAttr.objects.prefetch_related(
78
+ "projectionxrayradiationdose_set__irradeventxraydata_set"
79
+ ).get(pk=study_pk)
80
+ # study = GeneralStudyModuleAttr.objects.get(pk=study_pk)
81
+
82
+ display_name = (
83
+ study.generalequipmentmoduleattr_set.get().unique_equipment_name.display_name
84
+ )
85
+
86
+ if background_task is not None:
87
+ background_task.info = (
88
+ f"Unit: {display_name} | "
89
+ f"PK: {study_pk} | Study UID: {study.study_instance_uid.replace('.', '. ')}"
90
+ )
91
+ background_task.save()
92
+
93
+ pat_mass_source = "assumed"
94
+ try:
95
+ pat_mass = float(study.patientstudymoduleattr_set.get().patient_weight)
96
+ pat_mass_source = "extracted"
97
+ except (ValueError, TypeError):
98
+ pat_mass = 73.2
99
+
100
+ if pat_mass == 0.0:
101
+ pat_mass = 73.2
102
+ pat_mass_source = "assumed"
103
+
104
+ pat_height_source = "assumed"
105
+ try:
106
+ pat_height = (
107
+ float(study.patientstudymoduleattr_set.get().patient_size) * 100
108
+ )
109
+
110
+ pat_height_source = "extracted"
111
+ except (ValueError, TypeError):
112
+ pat_height = 178.6
113
+
114
+ if pat_height == 0.0:
115
+ pat_height = 178.6
116
+ pat_height_source = "assumed"
117
+
118
+ ptr = None
119
+ orientation_modifier = None
120
+ try:
121
+ ptr_meaning = (
122
+ study.projectionxrayradiationdose_set.get()
123
+ .irradeventxraydata_set.all()[0]
124
+ .patient_table_relationship_cid.code_meaning.lower()
125
+ )
126
+ if ptr_meaning in "headfirst":
127
+ ptr = "H"
128
+ elif ptr_meaning in "feet-first":
129
+ ptr = "F"
130
+ else:
131
+ logger.info(
132
+ f"Study PK {study_pk}: Patient table relationship not recognised ({ptr_meaning}). "
133
+ f"Assuming head first."
134
+ )
135
+ except AttributeError:
136
+ logger.info(
137
+ f"Study PK {study_pk}: Patient table relationship not found. Assuming head first."
138
+ )
139
+ except IndexError:
140
+ logger.info(
141
+ f"Study PK {study_pk}: No irradiation event x-ray data found. Assuming head first."
142
+ )
143
+ try:
144
+ orientation_modifier_meaning = (
145
+ study.projectionxrayradiationdose_set.get()
146
+ .irradeventxraydata_set.all()[0]
147
+ .patient_orientation_modifier_cid.code_meaning.lower()
148
+ )
149
+ if orientation_modifier_meaning in "supine":
150
+ orientation_modifier = "S"
151
+ elif orientation_modifier_meaning in "prone":
152
+ orientation_modifier = "P"
153
+ else:
154
+ logger.info(
155
+ f"Study PK {study_pk}: Orientation modifier not recognised ({orientation_modifier_meaning}). "
156
+ f"Assuming supine."
157
+ )
158
+ except AttributeError:
159
+ logger.info(
160
+ f"Study PK {study_pk}: Orientation modifier not found. Assuming supine."
161
+ )
162
+ except IndexError:
163
+ logger.info(
164
+ f"Study PK {study_pk}: No irradiation event x-ray data found. Assuming supine."
165
+ )
166
+ if ptr and orientation_modifier:
167
+ pat_pos_source = "extracted"
168
+ pat_pos = ptr + "F" + orientation_modifier
169
+ elif ptr:
170
+ pat_pos_source = "supine assumed"
171
+ pat_pos = ptr + "FS"
172
+ elif orientation_modifier:
173
+ pat_pos_source = "head first assumed"
174
+ pat_pos = "HF" + orientation_modifier
175
+ else:
176
+ pat_pos_source = "assumed"
177
+ pat_pos = "HFS"
178
+ logger.debug(f"patPos is {pat_pos} and source is {pat_pos_source}")
179
+
180
+ my_exp_map = CalcExpMap(
181
+ phantom_type="3D",
182
+ pat_pos=pat_pos,
183
+ pat_mass=pat_mass,
184
+ pat_height=pat_height,
185
+ table_thick=0.5,
186
+ table_width=45.0,
187
+ table_length=150.0,
188
+ matt_thick=4.0,
189
+ )
190
+
191
+ prefetch_set = {
192
+ "irradeventxraymechanicaldata_set",
193
+ "irradeventxraymechanicaldata_set__doserelateddistancemeasurements_set",
194
+ "irradeventxraysourcedata_set",
195
+ "irradeventxraysourcedata_set__kvp_set",
196
+ "irradeventxraysourcedata_set__xrayfilters_set",
197
+ }
198
+ all_irradiations = (
199
+ study.projectionxrayradiationdose_set.get()
200
+ .irradeventxraydata_set.prefetch_related(*prefetch_set)
201
+ .all()
202
+ )
203
+ num_irradiations = all_irradiations.count()
204
+
205
+ for count, irrad in enumerate(all_irradiations):
206
+ if background_task is not None:
207
+ background_task.info = (
208
+ f"Unit: {display_name} | "
209
+ f"PK: {study_pk} | Working on irradiation {count+1} of {num_irradiations}"
210
+ )
211
+ background_task.save()
212
+
213
+ try:
214
+ delta_x = (
215
+ float(
216
+ irrad.irradeventxraymechanicaldata_set.get()
217
+ .doserelateddistancemeasurements_set.get()
218
+ .table_longitudinal_position
219
+ )
220
+ / 10.0
221
+ )
222
+ except (ObjectDoesNotExist, TypeError):
223
+ delta_x = 0.0
224
+ try:
225
+ delta_y = (
226
+ float(
227
+ irrad.irradeventxraymechanicaldata_set.get()
228
+ .doserelateddistancemeasurements_set.get()
229
+ .table_lateral_position
230
+ )
231
+ / 10.0
232
+ )
233
+ except (ObjectDoesNotExist, TypeError):
234
+ delta_y = 0.0
235
+ try:
236
+ delta_z = (
237
+ float(
238
+ irrad.irradeventxraymechanicaldata_set.get()
239
+ .doserelateddistancemeasurements_set.get()
240
+ .table_height_position
241
+ )
242
+ / 10.0
243
+ )
244
+ except (ObjectDoesNotExist, TypeError):
245
+ delta_z = 0.0
246
+ if irrad.irradeventxraymechanicaldata_set.get().positioner_primary_angle:
247
+ angle_x = float(
248
+ irrad.irradeventxraymechanicaldata_set.get().positioner_primary_angle
249
+ )
250
+ else:
251
+ angle_x = 0.0
252
+ try:
253
+ angle_y = float(
254
+ irrad.irradeventxraymechanicaldata_set.get().positioner_secondary_angle
255
+ )
256
+ except (ObjectDoesNotExist, TypeError):
257
+ angle_y = 0.0
258
+ try:
259
+ d_ref = (
260
+ float(
261
+ irrad.irradeventxraymechanicaldata_set.get()
262
+ .doserelateddistancemeasurements_set.get()
263
+ .distance_source_to_isocenter
264
+ )
265
+ / 10.0
266
+ - 15.0
267
+ )
268
+ except (ObjectDoesNotExist, TypeError):
269
+ # This will result in failure to calculate skin dose map. Need a sensible default, or a lookup to a
270
+ # user-entered value
271
+ d_ref = None
272
+ try:
273
+ dap = float(irrad.dose_area_product)
274
+ except (ObjectDoesNotExist, TypeError):
275
+ dap = None
276
+ try:
277
+ ref_ak = float(irrad.irradeventxraysourcedata_set.get().dose_rp)
278
+ except (ObjectDoesNotExist, TypeError):
279
+ ref_ak = None
280
+ try:
281
+ kvp = np.mean(
282
+ irrad.irradeventxraysourcedata_set.get()
283
+ .kvp_set.all()
284
+ .exclude(kvp__isnull=True)
285
+ .exclude(kvp__exact=0)
286
+ .values_list("kvp", flat=True)
287
+ )
288
+ kvp = float(kvp)
289
+ if np.isnan(kvp):
290
+ kvp = None
291
+ except (ObjectDoesNotExist, TypeError):
292
+ kvp = None
293
+
294
+ filter_cu = 0.0
295
+ if irrad.irradeventxraysourcedata_set.get().xrayfilters_set.all():
296
+ for (
297
+ xray_filter
298
+ ) in irrad.irradeventxraysourcedata_set.get().xrayfilters_set.all():
299
+ try:
300
+ if xray_filter.xray_filter_material.code_value == "C-127F9":
301
+ filter_cu += float(
302
+ xray_filter.xray_filter_thickness_minimum
303
+ )
304
+ except AttributeError:
305
+ pass
306
+
307
+ if irrad.irradiation_event_type:
308
+ run_type = irrad.irradiation_event_type.code_meaning
309
+ else:
310
+ run_type = None
311
+ try:
312
+ frames = float(
313
+ irrad.irradeventxraysourcedata_set.get().number_of_pulses
314
+ )
315
+ except TypeError:
316
+ try:
317
+ frames = float(
318
+ irrad.irradeventxraysourcedata_set.get().exposure_time
319
+ / irrad.irradeventxraysourcedata_set.get()
320
+ .pulsewidth_set.get()
321
+ .pulse_width
322
+ )
323
+ except (ObjectDoesNotExist, TypeError, decimal.InvalidOperation):
324
+ frames = None
325
+ except ObjectDoesNotExist:
326
+ frames = None
327
+ try:
328
+ end_angle = float(
329
+ irrad.irradeventxraymechanicaldata_set.get().positioner_primary_end_angle
330
+ )
331
+ except (ObjectDoesNotExist, TypeError):
332
+ end_angle = None
333
+ if ref_ak and d_ref:
334
+ my_exp_map.add_view(
335
+ delta_x=delta_x,
336
+ delta_y=delta_y,
337
+ delta_z=delta_z,
338
+ angle_x=angle_x,
339
+ angle_y=angle_y,
340
+ d_ref=d_ref,
341
+ dap=dap,
342
+ ref_ak=ref_ak,
343
+ kvp=kvp,
344
+ filter_cu=filter_cu,
345
+ run_type=run_type,
346
+ frames=frames,
347
+ end_angle=end_angle,
348
+ pat_pos=pat_pos,
349
+ )
350
+
351
+ if background_task is not None:
352
+ background_task.info = (
353
+ f"Unit: {display_name} | "
354
+ f"PK: {study_pk} | Study UID: {study.study_instance_uid.replace('.', '. ')}"
355
+ )
356
+ background_task.save()
357
+
358
+ # Flip the skin dose map left-right so the view is from the front
359
+ # my_exp_map.my_dose.fliplr()
360
+ my_exp_map.my_dose.total_dose = np.roll(
361
+ my_exp_map.my_dose.total_dose,
362
+ int(my_exp_map.phantom.phantom_flat_dist // 2),
363
+ axis=0,
364
+ )
365
+ try:
366
+ my_exp_map.my_dose.total_dose = np.rot90(my_exp_map.my_dose.total_dose)
367
+ except ValueError:
368
+ pass
369
+ try:
370
+ SkinDoseMapResults.objects.get(
371
+ general_study_module_attributes=study
372
+ ).delete()
373
+ except ObjectDoesNotExist:
374
+ pass
375
+ # assume that calculation failed if max(peak_skin_dose) == 0 ==> set peak_skin_dose to None
376
+ max_skin_dose = np.max(my_exp_map.my_dose.total_dose, initial=0)
377
+ max_skin_dose = max_skin_dose if max_skin_dose > 0 else None
378
+
379
+ if max_skin_dose is None:
380
+ background_task.complete = True
381
+ background_task.completed_successfully = False
382
+ background_task.error = "Skin dose map calculation failed"
383
+ background_task.save()
384
+ return
385
+
386
+ try:
387
+ dap_fraction = my_exp_map.my_dose.dap_count / float(study.total_dap)
388
+ except ZeroDivisionError:
389
+ dap_fraction = 1.0
390
+ SkinDoseMapResults(
391
+ general_study_module_attributes=study,
392
+ patient_orientation=pat_pos,
393
+ patient_mass=pat_mass,
394
+ patient_mass_assumed=pat_mass_source,
395
+ patient_size_assumed=pat_height_source,
396
+ patient_orientation_assumed=pat_pos_source,
397
+ phantom_width=my_exp_map.phantom.phantom_width,
398
+ phantom_height=my_exp_map.phantom.phantom_height,
399
+ phantom_depth=my_exp_map.phantom.phantom_depth,
400
+ patient_size=pat_height,
401
+ skin_map_version=__skin_map_version__,
402
+ peak_skin_dose=max_skin_dose,
403
+ dap_fraction=dap_fraction,
404
+ ).save()
405
+ return_structure = {
406
+ "skin_map": my_exp_map.my_dose.total_dose.flatten().tolist(),
407
+ "width": my_exp_map.phantom.width,
408
+ "height": my_exp_map.phantom.height,
409
+ "phantom_width": my_exp_map.phantom.phantom_width,
410
+ "phantom_height": my_exp_map.phantom.phantom_height,
411
+ "phantom_head_height": my_exp_map.phantom.phantom_head_height,
412
+ "phantom_head_radius": my_exp_map.phantom.phantom_head_radius,
413
+ "phantom_depth": my_exp_map.phantom.phantom_depth,
414
+ "phantom_flat_dist": my_exp_map.phantom.phantom_flat_dist,
415
+ "phantom_curved_dist": my_exp_map.phantom.phantom_curved_dist,
416
+ "patient_height": pat_height,
417
+ "patient_mass": pat_mass,
418
+ "patient_orientation": pat_pos,
419
+ "patient_height_source": pat_height_source,
420
+ "patient_mass_source": pat_mass_source,
421
+ "patient_orientation_source": pat_pos_source,
422
+ "fraction_DAP": dap_fraction,
423
+ "skin_map_version": __skin_map_version__,
424
+ }
425
+
426
+ # Save the return_structure as a pickle in a skin_maps sub-folder of the MEDIA_ROOT folder
427
+ save_openskin_structure(study, return_structure)
428
+
429
+
430
+ def skin_dose_maps_enabled_for_xray_system(study):
431
+ # Get all OpenSkinSafeList table entries that match the manufacturer and model name of the current study
432
+ entries = OpenSkinSafeList.objects.all().filter(
433
+ manufacturer=study.generalequipmentmoduleattr_set.get().manufacturer,
434
+ manufacturer_model_name=study.generalequipmentmoduleattr_set.get().manufacturer_model_name,
435
+ )
436
+ # Look for an entry which has a matching software version with the current study,
437
+ # or an entry where the software version is blank (any software version)
438
+ entry = False
439
+ for current_entry in entries:
440
+ if (
441
+ current_entry.software_version
442
+ == study.generalequipmentmoduleattr_set.get().software_versions
443
+ or current_entry.software_version is None
444
+ or not current_entry.software_version
445
+ ):
446
+ entry = True
447
+ break
448
+ return entry