endoreg-db 0.1.0__py3-none-any.whl → 0.2.1__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 (121) hide show
  1. endoreg_db/data/__init__.py +14 -0
  2. endoreg_db/data/active_model/data.yaml +3 -0
  3. endoreg_db/data/center/data.yaml +7 -0
  4. endoreg_db/data/endoscope_type/data.yaml +11 -0
  5. endoreg_db/data/endoscopy_processor/data.yaml +45 -0
  6. endoreg_db/data/examination/examinations/data.yaml +17 -0
  7. endoreg_db/data/examination/time/data.yaml +48 -0
  8. endoreg_db/data/examination/time-type/data.yaml +8 -0
  9. endoreg_db/data/examination/type/data.yaml +5 -0
  10. endoreg_db/data/information_source/data.yaml +30 -0
  11. endoreg_db/data/label/label/data.yaml +62 -0
  12. endoreg_db/data/label/label-set/data.yaml +18 -0
  13. endoreg_db/data/label/label-type/data.yaml +7 -0
  14. endoreg_db/data/model_type/data.yaml +7 -0
  15. endoreg_db/data/profession/data.yaml +70 -0
  16. endoreg_db/data/unit/data.yaml +17 -0
  17. endoreg_db/data/unit/length.yaml +31 -0
  18. endoreg_db/data/unit/volume.yaml +26 -0
  19. endoreg_db/data/unit/weight.yaml +31 -0
  20. endoreg_db/forms/__init__.py +2 -0
  21. endoreg_db/forms/settings/__init__.py +8 -0
  22. endoreg_db/forms/unit.py +6 -0
  23. endoreg_db/management/commands/_load_model_template.py +41 -0
  24. endoreg_db/management/commands/delete_legacy_images.py +19 -0
  25. endoreg_db/management/commands/delete_legacy_videos.py +17 -0
  26. endoreg_db/management/commands/extract_legacy_video_frames.py +18 -0
  27. endoreg_db/management/commands/fetch_legacy_image_dataset.py +32 -0
  28. endoreg_db/management/commands/import_legacy_images.py +94 -0
  29. endoreg_db/management/commands/import_legacy_videos.py +76 -0
  30. endoreg_db/management/commands/load_active_model_data.py +45 -0
  31. endoreg_db/management/commands/load_ai_model_data.py +45 -0
  32. endoreg_db/management/commands/load_base_db_data.py +62 -0
  33. endoreg_db/management/commands/load_center_data.py +43 -0
  34. endoreg_db/management/commands/load_endoscope_type_data.py +45 -0
  35. endoreg_db/management/commands/load_endoscopy_processor_data.py +45 -0
  36. endoreg_db/management/commands/load_examination_data.py +75 -0
  37. endoreg_db/management/commands/load_information_source.py +45 -0
  38. endoreg_db/management/commands/load_label_data.py +67 -0
  39. endoreg_db/management/commands/load_profession_data.py +44 -0
  40. endoreg_db/management/commands/load_unit_data.py +46 -0
  41. endoreg_db/management/commands/load_user_groups.py +67 -0
  42. endoreg_db/management/commands/register_ai_model.py +65 -0
  43. endoreg_db/migrations/0001_initial.py +582 -0
  44. endoreg_db/models/__init__.py +53 -0
  45. endoreg_db/models/ai_model/__init__.py +3 -0
  46. endoreg_db/models/ai_model/active_model.py +9 -0
  47. endoreg_db/models/ai_model/model_meta.py +24 -0
  48. endoreg_db/models/ai_model/model_type.py +26 -0
  49. endoreg_db/models/ai_model/utils.py +8 -0
  50. endoreg_db/models/annotation/__init__.py +2 -0
  51. endoreg_db/models/annotation/binary_classification_annotation_task.py +80 -0
  52. endoreg_db/models/annotation/image_classification.py +27 -0
  53. endoreg_db/models/center.py +19 -0
  54. endoreg_db/models/data_file/__init__.py +4 -0
  55. endoreg_db/models/data_file/base_classes/__init__.py +3 -0
  56. endoreg_db/models/data_file/base_classes/abstract_frame.py +51 -0
  57. endoreg_db/models/data_file/base_classes/abstract_video.py +200 -0
  58. endoreg_db/models/data_file/frame.py +45 -0
  59. endoreg_db/models/data_file/report_file.py +88 -0
  60. endoreg_db/models/data_file/video/__init__.py +7 -0
  61. endoreg_db/models/data_file/video/import_meta.py +25 -0
  62. endoreg_db/models/data_file/video/video.py +25 -0
  63. endoreg_db/models/data_file/video_segment.py +107 -0
  64. endoreg_db/models/examination/__init__.py +4 -0
  65. endoreg_db/models/examination/examination.py +26 -0
  66. endoreg_db/models/examination/examination_time.py +27 -0
  67. endoreg_db/models/examination/examination_time_type.py +24 -0
  68. endoreg_db/models/examination/examination_type.py +18 -0
  69. endoreg_db/models/hardware/__init__.py +2 -0
  70. endoreg_db/models/hardware/endoscope.py +44 -0
  71. endoreg_db/models/hardware/endoscopy_processor.py +143 -0
  72. endoreg_db/models/information_source.py +22 -0
  73. endoreg_db/models/label/__init__.py +1 -0
  74. endoreg_db/models/label/label.py +84 -0
  75. endoreg_db/models/legacy_data/__init__.py +3 -0
  76. endoreg_db/models/legacy_data/image.py +34 -0
  77. endoreg_db/models/patient_examination/__init__.py +35 -0
  78. endoreg_db/models/persons/__init__.py +4 -0
  79. endoreg_db/models/persons/examiner/__init__.py +2 -0
  80. endoreg_db/models/persons/examiner/examiner.py +16 -0
  81. endoreg_db/models/persons/examiner/examiner_type.py +2 -0
  82. endoreg_db/models/persons/patient.py +58 -0
  83. endoreg_db/models/persons/person.py +34 -0
  84. endoreg_db/models/persons/portal_user_information.py +29 -0
  85. endoreg_db/models/prediction/__init__.py +2 -0
  86. endoreg_db/models/prediction/image_classification.py +37 -0
  87. endoreg_db/models/prediction/video_prediction_meta.py +244 -0
  88. endoreg_db/models/unit.py +20 -0
  89. endoreg_db/queries/__init__.py +5 -0
  90. endoreg_db/queries/annotations/__init__.py +3 -0
  91. endoreg_db/queries/annotations/legacy.py +159 -0
  92. endoreg_db/queries/get/__init__.py +6 -0
  93. endoreg_db/queries/get/annotation.py +0 -0
  94. endoreg_db/queries/get/center.py +42 -0
  95. endoreg_db/queries/get/model.py +13 -0
  96. endoreg_db/queries/get/patient.py +14 -0
  97. endoreg_db/queries/get/patient_examination.py +20 -0
  98. endoreg_db/queries/get/prediction.py +0 -0
  99. endoreg_db/queries/get/report_file.py +33 -0
  100. endoreg_db/queries/get/video.py +31 -0
  101. endoreg_db/queries/get/video_import_meta.py +0 -0
  102. endoreg_db/queries/get/video_prediction_meta.py +0 -0
  103. endoreg_db/queries/sanity/__init_.py +0 -0
  104. endoreg_db/serializers/__init__.py +10 -0
  105. endoreg_db/serializers/ai_model.py +19 -0
  106. endoreg_db/serializers/annotation.py +17 -0
  107. endoreg_db/serializers/center.py +11 -0
  108. endoreg_db/serializers/examination.py +33 -0
  109. endoreg_db/serializers/frame.py +13 -0
  110. endoreg_db/serializers/hardware.py +21 -0
  111. endoreg_db/serializers/label.py +22 -0
  112. endoreg_db/serializers/patient.py +10 -0
  113. endoreg_db/serializers/prediction.py +15 -0
  114. endoreg_db/serializers/report_file.py +7 -0
  115. endoreg_db/serializers/video.py +27 -0
  116. endoreg_db-0.2.1.dist-info/LICENSE +674 -0
  117. endoreg_db-0.2.1.dist-info/METADATA +27 -0
  118. endoreg_db-0.2.1.dist-info/RECORD +126 -0
  119. endoreg_db-0.1.0.dist-info/METADATA +0 -19
  120. endoreg_db-0.1.0.dist-info/RECORD +0 -10
  121. {endoreg_db-0.1.0.dist-info → endoreg_db-0.2.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,94 @@
1
+ # command expects a directory as an argument
2
+ # directory should contain a img_dicts.jsonl file, a settings.json and an "images" directory
3
+ # images should be in jpeg format
4
+ # reads the img_dicts.jsonl file and creates a new database entry for each image
5
+ # img_dicts contains a line for each image in the following format:
6
+ # {"id": 30604292, "path": "images/30604292.jpg", "labels": ["appendix", "polyp"]}
7
+
8
+ # import_settings.json example:
9
+ # {
10
+ # "annotator": "legacy",
11
+ # "labelset_name": "multilabel_classification",
12
+ # "labelset_version": 0
13
+ # }
14
+
15
+ import os
16
+ import json
17
+ from tqdm import tqdm
18
+ from django.core.management.base import BaseCommand
19
+ from endoreg_db.models import LegacyImage, LabelSet, Label, ImageClassificationAnnotation
20
+ from django.core.files import File
21
+ from uuid import uuid4
22
+
23
+ class Command(BaseCommand):
24
+ """
25
+ Imports images from a directory into the database
26
+
27
+ Usage:
28
+ python manage.py import_legacy_images <directory>
29
+ """
30
+ help = 'Imports images from a directory into the database'
31
+
32
+ def add_arguments(self, parser):
33
+ parser.add_argument('directory', type=str)
34
+
35
+ def handle(self, *args, **options):
36
+ directory = options['directory']
37
+ if not os.path.isdir(directory):
38
+ raise Exception(f"Directory {directory} does not exist")
39
+
40
+ # read settings.json
41
+ with open(os.path.join(directory, 'import_settings.json'), 'r') as f:
42
+ settings = json.load(f)
43
+
44
+ # read img_dicts.jsonl
45
+ with open(os.path.join(directory, 'img_dicts.jsonl'), 'r') as f:
46
+ img_dicts = [json.loads(line) for line in f.readlines()]
47
+
48
+ # get labelset
49
+ labelset_name = settings['labelset_name']
50
+ labelset_version = settings['labelset_version']
51
+ try:
52
+ labelset = LabelSet.objects.get(name=labelset_name, version=labelset_version)
53
+ except LabelSet.DoesNotExist:
54
+ raise Exception(f"No labelset found with the name {labelset_name} and version {labelset_version}")
55
+
56
+
57
+ # get labels in dict to lookup by name
58
+ labels = {label.name: label for label in labelset.labels.all()}
59
+
60
+ # create images and image_classification_annotations
61
+ for img_dict in tqdm(img_dicts):
62
+
63
+ # Open the image file
64
+ with open(os.path.join(directory, img_dict['path']), 'rb') as f:
65
+ # Create the Django File object
66
+ django_file = File(f)
67
+
68
+ # Extract only the filename
69
+ filename = os.path.basename(img_dict['path'])
70
+ img_suffix = os.path.splitext(filename)[1]
71
+ # assign uuid as new filename
72
+ filename = str(uuid4()) + img_suffix
73
+
74
+
75
+ # Create a new LegacyImage instance and save the image
76
+ image = LegacyImage(image=filename, suffix=img_suffix)
77
+ image.image.save(filename, django_file, save=True)
78
+
79
+ image_annotations = []
80
+ for label_name, label in labels.items():
81
+ if label_name in img_dict['labels']:
82
+ value = True
83
+ else:
84
+ value = False
85
+
86
+ image_annotations.append(ImageClassificationAnnotation(
87
+ legacy_image=image,
88
+ label=label,
89
+ value=value,
90
+ annotator=settings['annotator']
91
+ ))
92
+
93
+ ImageClassificationAnnotation.objects.bulk_create(image_annotations)
94
+
@@ -0,0 +1,76 @@
1
+ from endoreg_db.utils.hashs import get_video_hash
2
+ import subprocess
3
+ from django.core.files import File
4
+ from django.core.management.base import BaseCommand
5
+ from endoreg_db.models.data_file.video import LegacyVideo
6
+ import os
7
+ from tqdm import tqdm
8
+ import cv2
9
+
10
+ def convert_mkv_to_mp4(source_path, target_path):
11
+ """
12
+ Convert a .mkv file to a .mp4 file using FFmpeg.
13
+
14
+ Parameters:
15
+ mov_file_path (str): The file path of the input .MOV file.
16
+ mp4_file_path (str): The file path where the output .mp4 file should be saved.
17
+
18
+ Returns:
19
+ None
20
+ """
21
+ cmd = ["ffmpeg", "-y", "-i", source_path, "-vcodec", "h264", "-acodec", "aac", target_path]
22
+ subprocess.run(cmd)
23
+
24
+
25
+ class Command(BaseCommand):
26
+ """
27
+ Imports videos from a directory into the database
28
+
29
+ Usage:
30
+ python manage.py import_legacy_videos <directory>
31
+ """
32
+ help = 'Imports videos from a directory into the database'
33
+
34
+ def add_arguments(self, parser):
35
+ parser.add_argument('directory', type=str)
36
+
37
+ def handle(self, *args, **options):
38
+ directory = options['directory']
39
+ if not os.path.isdir(directory):
40
+ raise Exception(f"Directory {directory} does not exist")
41
+
42
+ # iterate over all subdirectories and gather all .mkv files
43
+ mkv_files = []
44
+ for root, dirs, files in os.walk(directory):
45
+ for file in files:
46
+ if file.endswith(".mkv"):
47
+ mkv_files.append(os.path.join(root, file))
48
+
49
+ # create videos
50
+ for mkv_file in tqdm(mkv_files):
51
+ # get the name of the video
52
+ video_name = os.path.basename(mkv_file).replace(".mkv", "")
53
+
54
+ # convert the .mkv file to a .mp4 file
55
+ mp4_file = os.path.join(directory, video_name + ".mp4")
56
+ if not os.path.isfile(mp4_file):
57
+ convert_mkv_to_mp4(mkv_file, mp4_file)
58
+
59
+ # create the video object
60
+ video_hash = get_video_hash(mp4_file)
61
+
62
+ # check if the video already exists
63
+ if LegacyVideo.objects.filter(video_hash=video_hash).exists():
64
+ print(f"Video with hash {video_hash} already exists. Skipping...")
65
+ continue
66
+
67
+ video = LegacyVideo.objects.create(video_hash=video_hash, suffix = "mp4")
68
+
69
+ # open the .mp4 file
70
+ with open(mp4_file, 'rb') as f:
71
+ # create the Django File object
72
+ django_file = File(f)
73
+ # save the file to the video
74
+ video.file.save(video_name + ".mp4", django_file)
75
+ raise Exception("Stop here: NEED TO FIX OPENCV DEPENDENCY")
76
+ video.initialize_video_specs(cv2.VideoCapture(video.file.path))
@@ -0,0 +1,45 @@
1
+ from django.conf import settings
2
+ import os
3
+ from django.core.management.base import BaseCommand
4
+ from ...models import ActiveModel
5
+ from ...utils import load_model_data_from_yaml
6
+ from ...data import ACTIVE_MODEL_DATA_DIR
7
+
8
+ SOURCE_DIR = ACTIVE_MODEL_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
+
10
+ MODEL_0 = ActiveModel
11
+
12
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
13
+ MODEL_0.__name__,
14
+ ]
15
+
16
+ IMPORT_METADATA = {
17
+ MODEL_0.__name__: {
18
+ "dir": SOURCE_DIR, # e.g. "interventions"
19
+ "model": MODEL_0, # e.g. Intervention
20
+ "foreign_keys": [], # e.g. ["intervention_types"]
21
+ "foreign_key_models": [] # e.g. [InterventionType]
22
+ }
23
+ }
24
+
25
+ class Command(BaseCommand):
26
+ help = """Load all .yaml files in the data/intervention directory
27
+ into the Intervention and InterventionType model"""
28
+
29
+ def add_arguments(self, parser):
30
+ parser.add_argument(
31
+ '--verbose',
32
+ action='store_true',
33
+ help='Display verbose output',
34
+ )
35
+
36
+ def handle(self, *args, **options):
37
+ verbose = options['verbose']
38
+ for model_name in IMPORT_MODELS:
39
+ _metadata = IMPORT_METADATA[model_name]
40
+ load_model_data_from_yaml(
41
+ self,
42
+ model_name,
43
+ _metadata,
44
+ verbose
45
+ )
@@ -0,0 +1,45 @@
1
+ from django.conf import settings
2
+ import os
3
+ from django.core.management.base import BaseCommand
4
+ from ...models import ModelType
5
+ from ...utils import load_model_data_from_yaml
6
+ from ...data import MODEL_TYPE_DATA_DIR
7
+
8
+ SOURCE_DIR = MODEL_TYPE_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
+
10
+ MODEL_0 = ModelType
11
+
12
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
13
+ MODEL_0.__name__,
14
+ ]
15
+
16
+ IMPORT_METADATA = {
17
+ MODEL_0.__name__: {
18
+ "dir": SOURCE_DIR, # e.g. "interventions"
19
+ "model": MODEL_0, # e.g. Intervention
20
+ "foreign_keys": [], # e.g. ["intervention_types"]
21
+ "foreign_key_models": [] # e.g. [InterventionType]
22
+ }
23
+ }
24
+
25
+ class Command(BaseCommand):
26
+ help = """Load all .yaml files in the data/intervention directory
27
+ into the Intervention and InterventionType model"""
28
+
29
+ def add_arguments(self, parser):
30
+ parser.add_argument(
31
+ '--verbose',
32
+ action='store_true',
33
+ help='Display verbose output',
34
+ )
35
+
36
+ def handle(self, *args, **options):
37
+ verbose = options['verbose']
38
+ for model_name in IMPORT_MODELS:
39
+ _metadata = IMPORT_METADATA[model_name]
40
+ load_model_data_from_yaml(
41
+ self,
42
+ model_name,
43
+ _metadata,
44
+ verbose
45
+ )
@@ -0,0 +1,62 @@
1
+ from django.core.management import BaseCommand, call_command
2
+
3
+ class Command(BaseCommand):
4
+ help = 'Run all data loading commands in the correct order'
5
+
6
+ def add_arguments(self, parser):
7
+ parser.add_argument(
8
+ '--verbose',
9
+ action='store_true',
10
+ help='Display verbose output for all commands',
11
+ )
12
+
13
+ def handle(self, *args, **options):
14
+ verbose = options['verbose']
15
+
16
+ self.stdout.write(self.style.SUCCESS("Populating base db models with data..."))
17
+
18
+ # Run the load_profession_data command
19
+ self.stdout.write(self.style.SUCCESS("Running load_profession_data..."))
20
+ call_command('load_profession_data', verbose=verbose)
21
+
22
+ # rund the load_user_groups command
23
+ self.stdout.write(self.style.SUCCESS("Running load_user_groups..."))
24
+ call_command('load_user_groups', verbose=verbose)
25
+
26
+ # Run the load_endoscopy_processor_data command
27
+ self.stdout.write(self.style.SUCCESS("Running load_endoscopy_processor_data..."))
28
+ call_command('load_endoscopy_processor_data', verbose=verbose)
29
+
30
+ # Run the load_endoscope_type_data command
31
+ self.stdout.write(self.style.SUCCESS("Running load_endoscope_type_data..."))
32
+ call_command('load_endoscope_type_data', verbose=verbose)
33
+
34
+ # Run the load_unit_data command
35
+ self.stdout.write(self.style.SUCCESS("Running load_unit_data..."))
36
+ call_command('load_unit_data', verbose=verbose)
37
+
38
+ # Run the load_information_source command
39
+ self.stdout.write(self.style.SUCCESS("Running load_information_source..."))
40
+ call_command('load_information_source', verbose=verbose)
41
+
42
+ # Run the load_center_data command
43
+ self.stdout.write(self.style.SUCCESS("Running load_center_data..."))
44
+ call_command('load_center_data', verbose=verbose)
45
+
46
+ # Run the load_examination_data command
47
+ self.stdout.write(self.style.SUCCESS("Running load_examination_data..."))
48
+ call_command('load_examination_data', verbose=verbose)
49
+
50
+ # Run the load_label_data command
51
+ self.stdout.write(self.style.SUCCESS("Running load_label_data..."))
52
+ call_command('load_label_data', verbose=verbose)
53
+
54
+ # Run the load_ai_model_data command
55
+ self.stdout.write(self.style.SUCCESS("Running load_ai_model_data..."))
56
+ call_command('load_ai_model_data', verbose=verbose)
57
+
58
+ # Run the load_active_model_data command
59
+ self.stdout.write(self.style.SUCCESS("Running load_active_model_data..."))
60
+ call_command('load_active_model_data', verbose=verbose)
61
+
62
+ self.stdout.write(self.style.SUCCESS("All data loading commands executed successfully."))
@@ -0,0 +1,43 @@
1
+ from django.core.management.base import BaseCommand
2
+ from ...utils import load_model_data_from_yaml
3
+ from ...models import Center
4
+ from ...data import CENTER_DATA_DIR
5
+
6
+ SOURCE_DIR = CENTER_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
7
+
8
+ MODEL_0 = Center
9
+
10
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
11
+ MODEL_0.__name__,
12
+ ]
13
+
14
+ IMPORT_METADATA = {
15
+ MODEL_0.__name__: {
16
+ "dir": SOURCE_DIR, # e.g. "interventions"
17
+ "model": MODEL_0, # e.g. Intervention
18
+ "foreign_keys": [], # e.g. ["intervention_types"]
19
+ "foreign_key_models": [] # e.g. [InterventionType]
20
+ }
21
+ }
22
+
23
+ class Command(BaseCommand):
24
+ help = """Load all .yaml files in the data/intervention directory
25
+ into the Intervention and InterventionType model"""
26
+
27
+ def add_arguments(self, parser):
28
+ parser.add_argument(
29
+ '--verbose',
30
+ action='store_true',
31
+ help='Display verbose output',
32
+ )
33
+
34
+ def handle(self, *args, **options):
35
+ verbose = options['verbose']
36
+ for model_name in IMPORT_MODELS:
37
+ _metadata = IMPORT_METADATA[model_name]
38
+ load_model_data_from_yaml(
39
+ self,
40
+ model_name,
41
+ _metadata,
42
+ verbose
43
+ )
@@ -0,0 +1,45 @@
1
+ from django.conf import settings
2
+ import os
3
+ from django.core.management.base import BaseCommand
4
+ from ...models import EndoscopeType
5
+ from ...utils import load_model_data_from_yaml
6
+ from ...data import ENDOSCOPE_TYPE_DATA_DIR
7
+
8
+ SOURCE_DIR = ENDOSCOPE_TYPE_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
+
10
+ MODEL_0 = EndoscopeType
11
+
12
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
13
+ MODEL_0.__name__,
14
+ ]
15
+
16
+ IMPORT_METADATA = {
17
+ MODEL_0.__name__: {
18
+ "dir": SOURCE_DIR, # e.g. "interventions"
19
+ "model": MODEL_0, # e.g. Intervention
20
+ "foreign_keys": [], # e.g. ["intervention_types"]
21
+ "foreign_key_models": [] # e.g. [InterventionType]
22
+ }
23
+ }
24
+
25
+ class Command(BaseCommand):
26
+ help = """Load all .yaml files in the data/intervention directory
27
+ into the Intervention and InterventionType model"""
28
+
29
+ def add_arguments(self, parser):
30
+ parser.add_argument(
31
+ '--verbose',
32
+ action='store_true',
33
+ help='Display verbose output',
34
+ )
35
+
36
+ def handle(self, *args, **options):
37
+ verbose = options['verbose']
38
+ for model_name in IMPORT_MODELS:
39
+ _metadata = IMPORT_METADATA[model_name]
40
+ load_model_data_from_yaml(
41
+ self,
42
+ model_name,
43
+ _metadata,
44
+ verbose
45
+ )
@@ -0,0 +1,45 @@
1
+ from django.conf import settings
2
+ import os
3
+ from django.core.management.base import BaseCommand
4
+ from ...models import EndoscopyProcessor
5
+ from ...utils import load_model_data_from_yaml
6
+ from ...data import ENDOSCOPY_PROCESSOR_DATA_DIR
7
+
8
+ SOURCE_DIR = ENDOSCOPY_PROCESSOR_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
+
10
+ MODEL_0 = EndoscopyProcessor
11
+
12
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
13
+ MODEL_0.__name__,
14
+ ]
15
+
16
+ IMPORT_METADATA = {
17
+ MODEL_0.__name__: {
18
+ "dir": SOURCE_DIR, # e.g. "interventions"
19
+ "model": MODEL_0, # e.g. Intervention
20
+ "foreign_keys": [], # e.g. ["intervention_types"]
21
+ "foreign_key_models": [] # e.g. [InterventionType]
22
+ }
23
+ }
24
+
25
+ class Command(BaseCommand):
26
+ help = """Load all .yaml files in the data/intervention directory
27
+ into the Intervention and InterventionType model"""
28
+
29
+ def add_arguments(self, parser):
30
+ parser.add_argument(
31
+ '--verbose',
32
+ action='store_true',
33
+ help='Display verbose output',
34
+ )
35
+
36
+ def handle(self, *args, **options):
37
+ verbose = options['verbose']
38
+ for model_name in IMPORT_MODELS:
39
+ _metadata = IMPORT_METADATA[model_name]
40
+ load_model_data_from_yaml(
41
+ self,
42
+ model_name,
43
+ _metadata,
44
+ verbose
45
+ )
@@ -0,0 +1,75 @@
1
+ from django.conf import settings
2
+ from django.core.management.base import BaseCommand
3
+ from ...models import (
4
+ Examination,
5
+ ExaminationType, # Replace 'your_app_name' with the actual app name
6
+ ExaminationTime,
7
+ ExaminationTimeType,
8
+ )
9
+ import os
10
+ from ...utils import load_model_data_from_yaml
11
+ from ...data import EXAMINATION_DATA_DIR
12
+
13
+ SOURCE_DIR = EXAMINATION_DATA_DIR
14
+
15
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
16
+ "ExaminationType",
17
+ "Examination",
18
+ "ExaminationTimeType",
19
+ "ExaminationTime"
20
+ ]
21
+
22
+ IMPORT_METADATA = {
23
+ # "": { # same as model name in "import models", e.g. "Intervention"
24
+ # "subdir": os.path.join(SOURCE_DIR,""), # e.g. "interventions"
25
+ # "model": None, # e.g. Intervention
26
+ # "foreign_keys": [], # e.g. ["intervention_types"]
27
+ # "foreign_key_models": [] # e.g. [InterventionType]
28
+ # },
29
+ "ExaminationType": {
30
+ "dir": os.path.join(SOURCE_DIR,"type"), # e.g. "interventions"
31
+ "model": ExaminationType, # e.g. Intervention
32
+ "foreign_keys": [], # e.g. ["intervention_types"]
33
+ "foreign_key_models": [] # e.g. [InterventionType]
34
+ },
35
+ "Examination": {
36
+ "dir": os.path.join(SOURCE_DIR,"examinations"), # e.g. "interventions"
37
+ "model": Examination, # e.g. Intervention
38
+ "foreign_keys": ["examination_types"], # e.g. ["intervention_types"]
39
+ "foreign_key_models": [ExaminationType] # e.g. [InterventionType]
40
+ },
41
+ "ExaminationTimeType": {
42
+ "dir": os.path.join(SOURCE_DIR,"time-type"), # e.g. "interventions"
43
+ "model": ExaminationTimeType, # e.g. Intervention
44
+ "foreign_keys": ["examinations"], # e.g. ["intervention_types"]
45
+ "foreign_key_models": [Examination] # e.g. [InterventionType]
46
+ },
47
+ "ExaminationTime": {
48
+ "dir": os.path.join(SOURCE_DIR,"time"), # e.g. "interventions"
49
+ "model": ExaminationTime, # e.g. Intervention
50
+ "foreign_keys": ["time_types"], # e.g. ["intervention_types"]
51
+ "foreign_key_models": [ExaminationTimeType] # e.g. [InterventionType]
52
+ },
53
+ }
54
+
55
+ class Command(BaseCommand):
56
+ help = """Load all .yaml files in the data/intervention directory
57
+ into the Intervention and InterventionType model"""
58
+
59
+ def add_arguments(self, parser):
60
+ parser.add_argument(
61
+ '--verbose',
62
+ action='store_true',
63
+ help='Display verbose output',
64
+ )
65
+
66
+ def handle(self, *args, **options):
67
+ verbose = options['verbose']
68
+ for model_name in IMPORT_MODELS:
69
+ _metadata = IMPORT_METADATA[model_name]
70
+ load_model_data_from_yaml(
71
+ self,
72
+ model_name,
73
+ _metadata,
74
+ verbose
75
+ )
@@ -0,0 +1,45 @@
1
+ from django.conf import settings
2
+ import os
3
+ from django.core.management.base import BaseCommand
4
+ from ...models import InformationSource
5
+ from ...utils import load_model_data_from_yaml
6
+ from ...data import INFORMATION_DATA_DIR
7
+
8
+ SOURCE_DIR = INFORMATION_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
+
10
+ MODEL_0 = InformationSource
11
+
12
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
13
+ MODEL_0.__name__,
14
+ ]
15
+
16
+ IMPORT_METADATA = {
17
+ MODEL_0.__name__: {
18
+ "dir": SOURCE_DIR, # e.g. "interventions"
19
+ "model": MODEL_0, # e.g. Intervention
20
+ "foreign_keys": [], # e.g. ["intervention_types"]
21
+ "foreign_key_models": [] # e.g. [InterventionType]
22
+ }
23
+ }
24
+
25
+ class Command(BaseCommand):
26
+ help = """Load all .yaml files in the data/intervention directory
27
+ into the Intervention and InterventionType model"""
28
+
29
+ def add_arguments(self, parser):
30
+ parser.add_argument(
31
+ '--verbose',
32
+ action='store_true',
33
+ help='Display verbose output',
34
+ )
35
+
36
+ def handle(self, *args, **options):
37
+ verbose = options['verbose']
38
+ for model_name in IMPORT_MODELS:
39
+ _metadata = IMPORT_METADATA[model_name]
40
+ load_model_data_from_yaml(
41
+ self,
42
+ model_name,
43
+ _metadata,
44
+ verbose
45
+ )
@@ -0,0 +1,67 @@
1
+ from django.conf import settings
2
+ from django.core.management.base import BaseCommand
3
+ from ...models import (
4
+ Label,
5
+ LabelType,
6
+ LabelSet
7
+ )
8
+ import os
9
+ from ...utils import load_model_data_from_yaml
10
+ from ...data import LABEL_DATA_DIR
11
+
12
+ SOURCE_DIR = LABEL_DATA_DIR
13
+
14
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
15
+ "LabelType",
16
+ "Label",
17
+ "LabelSet",
18
+ ]
19
+
20
+ IMPORT_METADATA = {
21
+ # "": { # same as model name in "import models", e.g. "Intervention"
22
+ # "subdir": os.path.join(SOURCE_DIR,""), # e.g. "interventions"
23
+ # "model": None, # e.g. Intervention
24
+ # "foreign_keys": [], # e.g. ["intervention_types"]
25
+ # "foreign_key_models": [] # e.g. [InterventionType]
26
+ # },
27
+ "LabelType": {
28
+ "dir": os.path.join(SOURCE_DIR,"label-type"), # e.g. "interventions"
29
+ "model": LabelType, # e.g. Intervention
30
+ "foreign_keys": [], # e.g. ["intervention_types"]
31
+ "foreign_key_models": [] # e.g. [InterventionType]
32
+ },
33
+ "Label": {
34
+ "dir": os.path.join(SOURCE_DIR,"label"), # e.g. "interventions"
35
+ "model": Label, # e.g. Intervention
36
+ "foreign_keys": ["label_type"], # e.g. ["intervention_types"]
37
+ "foreign_key_models": [LabelType] # e.g. [InterventionType]
38
+ },
39
+ "LabelSet": {
40
+ "dir": os.path.join(SOURCE_DIR,"label-set"), # e.g. "interventions"
41
+ "model": LabelSet, # e.g. Intervention
42
+ "foreign_keys": ["labels"], # e.g. ["intervention_types"]
43
+ "foreign_key_models": [Label] # e.g. [InterventionType]
44
+ },
45
+ }
46
+
47
+ class Command(BaseCommand):
48
+ help = """Load all .yaml files in the data/intervention directory
49
+ into the Intervention and InterventionType model"""
50
+
51
+ def add_arguments(self, parser):
52
+ parser.add_argument(
53
+ '--verbose',
54
+ action='store_true',
55
+ help='Display verbose output',
56
+ )
57
+
58
+ def handle(self, *args, **options):
59
+ verbose = options['verbose']
60
+ for model_name in IMPORT_MODELS:
61
+ _metadata = IMPORT_METADATA[model_name]
62
+ load_model_data_from_yaml(
63
+ self,
64
+ model_name,
65
+ _metadata,
66
+ verbose
67
+ )