endoreg-db 0.6.3__py3-none-any.whl → 0.6.4__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.

Potentially problematic release.


This version of endoreg-db might be problematic. Click here for more details.

Files changed (78) hide show
  1. endoreg_db/data/__init__.py +14 -0
  2. endoreg_db/data/disease_classification/chronic_kidney_disease.yaml +2 -2
  3. endoreg_db/data/disease_classification_choice/chronic_kidney_disease.yaml +6 -6
  4. endoreg_db/data/examination/examinations/data.yaml +22 -21
  5. endoreg_db/data/examination/type/data.yaml +12 -0
  6. endoreg_db/data/examination_indication/endoscopy.yaml +417 -1
  7. endoreg_db/data/examination_indication_classification/endoscopy.yaml +157 -5
  8. endoreg_db/data/finding/data.yaml +18 -11
  9. endoreg_db/data/finding_intervention/endoscopy.yaml +26 -121
  10. endoreg_db/data/finding_intervention/endoscopy_colonoscopy.yaml +163 -0
  11. endoreg_db/data/finding_intervention/endoscopy_egd.yaml +128 -0
  12. endoreg_db/data/finding_intervention/endoscopy_ercp.yaml +32 -0
  13. endoreg_db/data/finding_intervention/endoscopy_eus_lower.yaml +9 -0
  14. endoreg_db/data/finding_intervention/endoscopy_eus_upper.yaml +36 -0
  15. endoreg_db/data/information_source/endoscopy_guidelines.yaml +7 -0
  16. endoreg_db/data/medication_indication/anticoagulation.yaml +4 -4
  17. endoreg_db/data/pdf_type/data.yaml +9 -16
  18. endoreg_db/data/requirement/colonoscopy_indications.yaml +56 -0
  19. endoreg_db/data/requirement/disease_cardiovascular.yaml +79 -0
  20. endoreg_db/data/requirement/disease_classification_choice_cardiovascular.yaml +38 -0
  21. endoreg_db/data/requirement/disease_hepatology.yaml +12 -0
  22. endoreg_db/data/requirement/disease_misc.yaml +12 -0
  23. endoreg_db/data/requirement/disease_renal.yaml +80 -0
  24. endoreg_db/data/requirement/event_cardiology.yaml +251 -0
  25. endoreg_db/data/requirement/lab_value.yaml +120 -0
  26. endoreg_db/data/requirement_operator/lab_operators.yaml +128 -0
  27. endoreg_db/data/requirement_operator/model_operators.yaml +90 -0
  28. endoreg_db/data/requirement_set/endoscopy_bleeding_risk.yaml +12 -0
  29. endoreg_db/data/requirement_set_type/data.yaml +20 -0
  30. endoreg_db/data/requirement_type/requirement_types.yaml +83 -0
  31. endoreg_db/data/risk/bleeding.yaml +26 -0
  32. endoreg_db/data/risk/thrombosis.yaml +37 -0
  33. endoreg_db/data/risk_type/data.yaml +27 -0
  34. endoreg_db/data/unit/time.yaml +36 -1
  35. endoreg_db/management/commands/load_base_db_data.py +14 -1
  36. endoreg_db/management/commands/load_center_data.py +46 -21
  37. endoreg_db/management/commands/load_examination_indication_data.py +49 -27
  38. endoreg_db/management/commands/load_requirement_data.py +156 -0
  39. endoreg_db/management/commands/load_risk_data.py +56 -0
  40. endoreg_db/migrations/0009_requirementoperator_requirementsettype_and_more.py +154 -0
  41. endoreg_db/models/__init__.py +20 -0
  42. endoreg_db/models/ai_model/ai_model.py +0 -13
  43. endoreg_db/models/ai_model/model_meta.py +2 -12
  44. endoreg_db/models/data_file/base_classes/abstract_frame.py +0 -2
  45. endoreg_db/models/data_file/base_classes/abstract_pdf.py +0 -9
  46. endoreg_db/models/data_file/base_classes/abstract_video.py +7 -8
  47. endoreg_db/models/data_file/base_classes/utils.py +0 -22
  48. endoreg_db/models/data_file/frame.py +1 -1
  49. endoreg_db/models/data_file/import_classes/raw_pdf.py +5 -11
  50. endoreg_db/models/data_file/import_classes/raw_video.py +6 -4
  51. endoreg_db/models/data_file/video/video.py +3 -3
  52. endoreg_db/models/disease.py +88 -19
  53. endoreg_db/models/event.py +108 -21
  54. endoreg_db/models/examination/examination_indication.py +108 -29
  55. endoreg_db/models/examination/examination_type.py +20 -6
  56. endoreg_db/models/information_source.py +37 -1
  57. endoreg_db/models/laboratory/lab_value.py +83 -32
  58. endoreg_db/models/requirement/__init__.py +11 -0
  59. endoreg_db/models/requirement/requirement.py +325 -0
  60. endoreg_db/models/requirement/requirement_evaluation/__init__.py +134 -0
  61. endoreg_db/models/requirement/requirement_evaluation/requirement_type_parser.py +102 -0
  62. endoreg_db/models/requirement/requirement_operator.py +58 -0
  63. endoreg_db/models/requirement/requirement_set.py +127 -0
  64. endoreg_db/models/risk/__init__.py +7 -0
  65. endoreg_db/models/risk/risk.py +72 -0
  66. endoreg_db/models/risk/risk_type.py +55 -0
  67. endoreg_db/serializers/video_segmentation.py +12 -25
  68. endoreg_db/urls.py +17 -3
  69. endoreg_db/utils/__init__.py +43 -0
  70. endoreg_db/utils/dataloader.py +38 -19
  71. endoreg_db/utils/hashs.py +1 -0
  72. endoreg_db/utils/paths.py +86 -0
  73. endoreg_db/views/views.py +107 -0
  74. {endoreg_db-0.6.3.dist-info → endoreg_db-0.6.4.dist-info}/METADATA +1 -1
  75. {endoreg_db-0.6.3.dist-info → endoreg_db-0.6.4.dist-info}/RECORD +77 -42
  76. endoreg_db/management/commands/load_name_data.py +0 -37
  77. {endoreg_db-0.6.3.dist-info → endoreg_db-0.6.4.dist-info}/WHEEL +0 -0
  78. {endoreg_db-0.6.3.dist-info → endoreg_db-0.6.4.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,83 @@
1
+ - model: endoreg_db.requirement_type
2
+ fields:
3
+ name: "patient_examination"
4
+ name_de: "Patientenuntersuchung"
5
+ name_en: "Patient examination"
6
+ description: "Requirements of this type are used on PatientExamination Objects."
7
+
8
+ - model: endoreg_db.requirement_type
9
+ fields:
10
+ name: "examination"
11
+ name_de: "Untersuchung"
12
+ name_en: "Examination"
13
+ description: "Examination-related requirements"
14
+
15
+ - model: endoreg_db.requirement_type
16
+ fields:
17
+ name: "examination_indication"
18
+ name_de: "Untersuchungsindikation"
19
+ name_en: "Examination Indication"
20
+ description: "Examination indication requirements"
21
+
22
+ - model: endoreg_db.requirement_type
23
+ fields:
24
+ name: "disease"
25
+ name_de: "Erkrankung"
26
+ name_en: "Disease"
27
+ description: "Disease-related requirements"
28
+
29
+ - model: endoreg_db.requirement_type
30
+ fields:
31
+ name: "disease_classification_choice"
32
+ name_de: "Erkrankungsklassifikation"
33
+ name_en: "Disease Classification"
34
+ description: "Disease classification choice requirements"
35
+
36
+ - model: endoreg_db.requirement_type
37
+ fields:
38
+ name: "event"
39
+ name_de: "Ereignis"
40
+ name_en: "Event"
41
+ description: "Event-related requirements"
42
+
43
+ - model: endoreg_db.requirement_type
44
+ fields:
45
+ name: "lab_value"
46
+ name_de: "Laborwert"
47
+ name_en: "Lab Value"
48
+ description: "Lab value requirements"
49
+
50
+ - model: endoreg_db.requirement_type
51
+ fields:
52
+ name: "finding"
53
+ name_de: "Befund"
54
+ name_en: "Finding"
55
+ description: "Finding requirements"
56
+
57
+ - model: endoreg_db.requirement_type
58
+ fields:
59
+ name: "finding_morphology"
60
+ name_de: "Befundmorphologie"
61
+ name_en: "Finding Morphology"
62
+ description: "Finding morphology requirements"
63
+
64
+ - model: endoreg_db.requirement_type
65
+ fields:
66
+ name: "finding_location"
67
+ name_de: "Befundlokalisation"
68
+ name_en: "Finding Location"
69
+ description: "Finding location requirements"
70
+
71
+ - model: endoreg_db.requirement_type
72
+ fields:
73
+ name: "finding_intervention"
74
+ name_de: "Befundintervention"
75
+ name_en: "Finding Intervention"
76
+ description: "Finding intervention requirements"
77
+
78
+ - model: endoreg_db.requirement_type
79
+ fields:
80
+ name: "finding_interventions"
81
+ name_de: "Befundinterventionen (multiple)"
82
+ name_en: "Finding Interventions (multiple)"
83
+ description: "Finding interventions (multiple) requirements"
@@ -0,0 +1,26 @@
1
+ - model: endoreg_db.risk
2
+ fields:
3
+ name: "bleeding_low"
4
+ name_de: "Blutung (niedrig)"
5
+ name_en: "Bleeding (low)"
6
+ description: "Low bleeding risk"
7
+ risk_type: "bleeding"
8
+ risk_value: 1
9
+
10
+ - model: endoreg_db.risk
11
+ fields:
12
+ name: "bleeding_high"
13
+ name_de: "Blutung (hoch)"
14
+ name_en: "Bleeding (high)"
15
+ description: "High bleeding risk"
16
+ risk_type: "bleeding"
17
+ risk_value: 3
18
+
19
+ - model: endoreg_db.risk
20
+ fields:
21
+ name: "bleeding_unknown"
22
+ name_de: "Blutung (unbekannt)"
23
+ name_en: "Bleeding (unknown)"
24
+ description: "Unknown bleeding risk"
25
+ risk_type: "bleeding"
26
+ risk_value: 0
@@ -0,0 +1,37 @@
1
+ # high medium low thrombosis risk
2
+
3
+ - model: endoreg_db.risk
4
+ fields:
5
+ name: "thrombosis_high"
6
+ name_de: "Thrombose hoch"
7
+ name_en: "Thrombosis high"
8
+ description: "High thrombosis risk"
9
+ risk_type: "thrombosis"
10
+ risk_value: 3
11
+
12
+ - model: endoreg_db.risk
13
+ fields:
14
+ name: "thrombosis_medium"
15
+ name_de: "Thrombose mittel"
16
+ name_en: "Thrombosis medium"
17
+ description: "Medium thrombosis risk"
18
+ risk_type: "thrombosis"
19
+ risk_value: 2
20
+
21
+ - model: endoreg_db.risk
22
+ fields:
23
+ name: "thrombosis_low"
24
+ name_de: "Thrombose niedrig"
25
+ name_en: "Thrombosis low"
26
+ description: "Low thrombosis risk"
27
+ risk_type: "thrombosis"
28
+ risk_value: 1
29
+
30
+ - model: endoreg_db.risk
31
+ fields:
32
+ name: "thrombosis_unknown"
33
+ name_de: "Thrombose unbekannt"
34
+ name_en: "Thrombosis unknown"
35
+ description: "Unknown thrombosis risk"
36
+ risk_type: "thrombosis"
37
+ risk_value: 0
@@ -0,0 +1,27 @@
1
+ - model: endoreg_db.risk_type
2
+ fields:
3
+ name: "bleeding"
4
+ name_de: "Blutung"
5
+ name_en: "Bleeding"
6
+ description: "Bleeding risk"
7
+
8
+ - model: endoreg_db.risk_type
9
+ fields:
10
+ name: "perforation"
11
+ name_de: "Perforation"
12
+ name_en: "Perforation"
13
+ description: "Perforation risk"
14
+
15
+ - model: endoreg_db.risk_type
16
+ fields:
17
+ name: "infection"
18
+ name_de: "Infektion"
19
+ name_en: "Infection"
20
+ description: "Infection risk"
21
+
22
+ - model: endoreg_db.risk_type
23
+ fields:
24
+ name: "thrombosis"
25
+ name_de: "Thrombose"
26
+ name_en: "Thrombosis"
27
+ description: "Thrombosis risk"
@@ -10,4 +10,39 @@
10
10
  name: "minutes"
11
11
  abbreviation: "min"
12
12
  name_de: "Minuten"
13
- name_en: "Minutes"
13
+ name_en: "Minutes"
14
+
15
+ - model: endoreg_db.unit
16
+ fields:
17
+ name: "hours"
18
+ abbreviation: "h"
19
+ name_de: "Stunden"
20
+ name_en: "Hours"
21
+
22
+ - model: endoreg_db.unit
23
+ fields:
24
+ name: "days"
25
+ abbreviation: "d"
26
+ name_de: "Tage"
27
+ name_en: "Days"
28
+
29
+ - model: endoreg_db.unit
30
+ fields:
31
+ name: "weeks"
32
+ abbreviation: "w"
33
+ name_de: "Wochen"
34
+ name_en: "Weeks"
35
+
36
+ - model: endoreg_db.unit
37
+ fields:
38
+ name: "months"
39
+ abbreviation: "mo"
40
+ name_de: "Monate"
41
+ name_en: "Months"
42
+
43
+ - model: endoreg_db.unit
44
+ fields:
45
+ name: "years"
46
+ abbreviation: "y"
47
+ name_de: "Jahre"
48
+ name_en: "Years"
@@ -14,12 +14,23 @@ class Command(BaseCommand):
14
14
 
15
15
  def handle(self, *args, **options):
16
16
  # verbose = options['verbose']
17
+ """
18
+ Orchestrates the sequential execution of data loading commands to populate base database models.
19
+
20
+ This management command displays an initial message and then runs a series of data loading routines
21
+ (via call_command) in a specified order. It ignores any verbose setting from the command-line options
22
+ and forces verbose output. A final success message is printed after all commands complete.
23
+ """
17
24
  verbose = True
18
25
 
19
26
  self.stdout.write(self.style.SUCCESS("Populating base db models with data..."))
20
27
 
21
28
  out = self.stdout
22
29
 
30
+ call_command("load_information_source", stdout=out, verbose=verbose)
31
+
32
+ call_command("load_risk_data", stdout=out, verbose=verbose)
33
+
23
34
  # Load Center Data
24
35
  call_command("load_center_data", stdout=out, verbose=verbose)
25
36
  call_command("load_endoscope_data", stdout=out, verbose=verbose)
@@ -34,11 +45,13 @@ class Command(BaseCommand):
34
45
  call_command("load_organ_data", stdout=out, verbose=verbose)
35
46
  call_command("load_contraindication_data", stdout=out, verbose=verbose)
36
47
  call_command("load_examination_data", stdout=out, verbose=verbose)
37
- call_command("load_examination_indication_data", stdout=out, verbose=verbose)
38
48
  call_command("load_lab_value_data", stdout=out, verbose=verbose)
39
49
  call_command("load_finding_data", stdout=out, verbose=verbose)
50
+ call_command("load_examination_indication_data", stdout=out, verbose=verbose)
40
51
  call_command("load_medication_data", stdout=out, verbose=verbose)
41
52
 
53
+ call_command("load_requirement_data", stdout=out, verbose=verbose)
54
+
42
55
  # Load AI Model Data
43
56
  call_command("load_ai_model_label_data", stdout=out, verbose=verbose)
44
57
  call_command("load_ai_model_data", stdout=out, verbose=verbose)
@@ -1,43 +1,68 @@
1
1
  from django.core.management.base import BaseCommand
2
2
  from ...utils import load_model_data_from_yaml
3
3
  from ...models import Center, FirstName, LastName
4
- from ...data import CENTER_DATA_DIR
4
+ from ...data import CENTER_DATA_DIR, NAMES_FIRST_DATA_DIR, NAMES_LAST_DATA_DIR
5
5
 
6
- SOURCE_DIR = CENTER_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
7
6
 
8
- MODEL_0 = Center
7
+ SOURCE_DIR = CENTER_DATA_DIR # e.g. settings.DATA_DIR_INTERVENTION
9
8
 
10
- IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
11
- MODEL_0.__name__,
9
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
10
+ FirstName.__name__,
11
+ LastName.__name__,
12
+ Center.__name__,
12
13
  ]
13
14
 
14
15
  IMPORT_METADATA = {
15
- MODEL_0.__name__: {
16
- "dir": SOURCE_DIR, # e.g. "interventions"
17
- "model": MODEL_0, # e.g. Intervention
18
- "foreign_keys": ["first_names", "last_names"], # e.g. ["intervention_types"]
19
- "foreign_key_models": [FirstName, LastName] # e.g. [InterventionType]
20
- }
16
+ FirstName.__name__: {
17
+ "dir": NAMES_FIRST_DATA_DIR, # e.g. "interventions"
18
+ "model": FirstName, # e.g. Intervention
19
+ "foreign_keys": [], # e.g. ["intervention_types"]
20
+ "foreign_key_models": [], # e.g. [InterventionType]
21
+ },
22
+ LastName.__name__: {
23
+ "dir": NAMES_LAST_DATA_DIR, # e.g. "interventions"
24
+ "model": LastName, # e.g. Intervention
25
+ "foreign_keys": [], # e.g. ["intervention_types"]
26
+ "foreign_key_models": [], # e.g. [InterventionType]
27
+ },
28
+ Center.__name__: {
29
+ "dir": SOURCE_DIR, # e.g. "interventions"
30
+ "model": Center, # e.g. Intervention
31
+ "foreign_keys": ["first_names", "last_names"], # e.g. ["intervention_types"]
32
+ "foreign_key_models": [FirstName, LastName], # e.g. [InterventionType]
33
+ },
21
34
  }
22
35
 
36
+
23
37
  class Command(BaseCommand):
24
38
  help = """Load all .yaml files in the data/intervention directory
25
39
  into the Intervention and InterventionType model"""
26
40
 
27
41
  def add_arguments(self, parser):
42
+ """
43
+ Adds the '--verbose' flag to the argument parser.
44
+
45
+ When specified, this flag enables verbose output for the management command.
46
+ """
28
47
  parser.add_argument(
29
- '--verbose',
30
- action='store_true',
31
- help='Display verbose output',
48
+ "--verbose",
49
+ action="store_true",
50
+ help="Display verbose output",
32
51
  )
33
52
 
34
53
  def handle(self, *args, **options):
35
- verbose = options['verbose']
54
+ """
55
+ Load YAML data for each predefined model.
56
+
57
+ Iterates over the models specified in IMPORT_MODELS, retrieving each model's metadata from
58
+ IMPORT_METADATA and invoking load_model_data_from_yaml to load YAML data. The verbosity of
59
+ the output is determined by the 'verbose' flag in the command options.
60
+
61
+ Args:
62
+ *args: Additional positional arguments.
63
+ **options: Command options; must include a 'verbose' key to control output detail.
64
+ """
65
+ verbose = options["verbose"]
36
66
  for model_name in IMPORT_MODELS:
37
67
  _metadata = IMPORT_METADATA[model_name]
38
- load_model_data_from_yaml(
39
- self,
40
- model_name,
41
- _metadata,
42
- verbose
43
- )
68
+ load_model_data_from_yaml(self, model_name, _metadata, verbose)
@@ -2,9 +2,10 @@ from django.conf import settings
2
2
  from django.core.management.base import BaseCommand
3
3
  from ...models import (
4
4
  ExaminationIndicationClassification,
5
- ExaminationIndication, # Replace 'your_app_name' with the actual app name
5
+ ExaminationIndication,
6
6
  ExaminationIndicationClassificationChoice,
7
7
  Examination,
8
+ FindingIntervention,
8
9
  )
9
10
  import os
10
11
  from ...utils import load_model_data_from_yaml
@@ -15,51 +16,72 @@ from ...data import (
15
16
  )
16
17
 
17
18
 
18
- IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
19
- ExaminationIndicationClassification.__name__,
19
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
20
20
  ExaminationIndication.__name__,
21
+ ExaminationIndicationClassification.__name__,
21
22
  ExaminationIndicationClassificationChoice.__name__,
22
23
  ]
23
24
 
24
25
  IMPORT_METADATA = {
25
- ExaminationIndicationClassification.__name__: {
26
- "dir": EXAMINATION_INDICATION_CLASSIFICATION_DATA_DIR, # e.g. "interventions"
27
- "model": ExaminationIndicationClassification, # e.g. Intervention
28
- "foreign_keys": [], # e.g. ["intervention_types"]
29
- "foreign_key_models": [] # e.g. [InterventionType]
30
- },
31
26
  ExaminationIndication.__name__: {
32
- "dir": EXAMINATION_INDICATION_DATA_DIR, # e.g. "interventions"
33
- "model": ExaminationIndication, # e.g. Intervention
34
- "foreign_keys": ["classification", "examination"], # e.g. ["intervention_types"]
35
- "foreign_key_models": [ExaminationIndicationClassification, Examination] # e.g. [InterventionType]
27
+ "dir": EXAMINATION_INDICATION_DATA_DIR,
28
+ "model": ExaminationIndication,
29
+ "foreign_keys": [
30
+ "examination",
31
+ "expected_interventions",
32
+ ],
33
+ "foreign_key_models": [
34
+ Examination,
35
+ FindingIntervention,
36
+ ],
37
+ },
38
+ ExaminationIndicationClassification.__name__: {
39
+ "dir": EXAMINATION_INDICATION_CLASSIFICATION_DATA_DIR,
40
+ "model": ExaminationIndicationClassification,
41
+ "foreign_keys": [
42
+ "examination",
43
+ "indications", # This is a many-to-many field
44
+ ],
45
+ "foreign_key_models": [
46
+ Examination,
47
+ ExaminationIndication,
48
+ ],
36
49
  },
37
50
  ExaminationIndicationClassificationChoice.__name__: {
38
- "dir": EXAMINATION_INDICATION_CLASSIFICATION_CHOICE_DATA_DIR, # e.g. "interventions"
39
- "model": ExaminationIndicationClassificationChoice, # e.g. Intervention
40
- "foreign_keys": ["classification"], # e.g. ["intervention_types"]
41
- "foreign_key_models": [ExaminationIndicationClassification] # e.g. [InterventionType]
51
+ "dir": EXAMINATION_INDICATION_CLASSIFICATION_CHOICE_DATA_DIR,
52
+ "model": ExaminationIndicationClassificationChoice,
53
+ "foreign_keys": ["classification"],
54
+ "foreign_key_models": [ExaminationIndicationClassification],
42
55
  },
43
56
  }
44
57
 
58
+
45
59
  class Command(BaseCommand):
46
60
  help = """Load all .yaml files in the data/intervention directory
47
61
  into the Intervention and InterventionType model"""
48
62
 
49
63
  def add_arguments(self, parser):
64
+ """
65
+ Add the --verbose flag to the command-line argument parser.
66
+
67
+ This method augments the parser with a '--verbose' option to enable detailed output
68
+ during command execution.
69
+ """
50
70
  parser.add_argument(
51
- '--verbose',
52
- action='store_true',
53
- help='Display verbose output',
71
+ "--verbose",
72
+ action="store_true",
73
+ help="Display verbose output",
54
74
  )
55
75
 
56
76
  def handle(self, *args, **options):
57
- verbose = options['verbose']
77
+ """
78
+ Executes YAML data import for configured models.
79
+
80
+ Retrieves the verbosity flag from the options and iterates through each model
81
+ in IMPORT_MODELS. For every model, it obtains the associated metadata from
82
+ IMPORT_METADATA and invokes load_model_data_from_yaml to load data from its YAML files.
83
+ """
84
+ verbose = options["verbose"]
58
85
  for model_name in IMPORT_MODELS:
59
86
  _metadata = IMPORT_METADATA[model_name]
60
- load_model_data_from_yaml(
61
- self,
62
- model_name,
63
- _metadata,
64
- verbose
65
- )
87
+ load_model_data_from_yaml(self, model_name, _metadata, verbose)
@@ -0,0 +1,156 @@
1
+ from django.core.management.base import BaseCommand
2
+ from endoreg_db.models import (
3
+ RequirementType,
4
+ RequirementOperator,
5
+ Requirement,
6
+ RequirementSetType,
7
+ RequirementSet,
8
+ Examination,
9
+ ExaminationIndication,
10
+ Disease,
11
+ DiseaseClassificationChoice,
12
+ Event,
13
+ LabValue,
14
+ Finding,
15
+ FindingMorphologyClassificationChoice,
16
+ FindingLocationClassificationChoice,
17
+ FindingIntervention,
18
+ InformationSource,
19
+ Unit,
20
+ Risk,
21
+ RiskType,
22
+ MedicationIndication,
23
+ MedicationIndicationType,
24
+ MedicationSchedule,
25
+ )
26
+ from ...utils import load_model_data_from_yaml
27
+ from ...data import (
28
+ REQUIREMENT_TYPE_DATA_DIR,
29
+ REQUIREMENT_OPERATOR_DATA_DIR,
30
+ REQUIREMENT_DATA_DIR,
31
+ REQUIREMENT_SET_TYPE_DATA_DIR,
32
+ REQUIREMENT_SET_DATA_DIR,
33
+ )
34
+
35
+
36
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
37
+ RequirementType.__name__,
38
+ RequirementOperator.__name__,
39
+ Requirement.__name__,
40
+ RequirementSetType.__name__,
41
+ RequirementSet.__name__,
42
+ ]
43
+
44
+ IMPORT_METADATA = {
45
+ RequirementType.__name__: {
46
+ "dir": REQUIREMENT_TYPE_DATA_DIR, # e.g. "interventions"
47
+ "model": RequirementType, # e.g. Intervention
48
+ "foreign_keys": [], # e.g. ["intervention_types"]
49
+ "foreign_key_models": [], # e.g. [InterventionType]
50
+ },
51
+ RequirementOperator.__name__: {
52
+ "dir": REQUIREMENT_OPERATOR_DATA_DIR, # e.g. "interventions"
53
+ "model": RequirementOperator, # e.g. Intervention
54
+ "foreign_keys": [], # e.g. ["intervention_types"]
55
+ "foreign_key_models": [], # e.g. [InterventionType]
56
+ },
57
+ Requirement.__name__: {
58
+ "dir": REQUIREMENT_DATA_DIR, # e.g. "interventions"
59
+ "model": Requirement, # e.g. Intervention
60
+ "foreign_keys": [
61
+ "requirement_types",
62
+ "operators",
63
+ "unit",
64
+ "examinations",
65
+ "examination_indications",
66
+ "diseases",
67
+ "disease_classification_choices",
68
+ "events",
69
+ "lab_values",
70
+ "findings",
71
+ "finding_morphology_classification_choices",
72
+ "finding_location_classification_choices",
73
+ "finding_interventions",
74
+ "risks",
75
+ "risk_types",
76
+ "medication_indications",
77
+ "medication_indication_types",
78
+ "medication_schedules",
79
+ ],
80
+ "foreign_key_models": [
81
+ RequirementType,
82
+ RequirementOperator,
83
+ Unit,
84
+ Examination,
85
+ ExaminationIndication,
86
+ Disease,
87
+ DiseaseClassificationChoice,
88
+ Event,
89
+ LabValue,
90
+ Finding,
91
+ FindingMorphologyClassificationChoice,
92
+ FindingLocationClassificationChoice,
93
+ FindingIntervention,
94
+ Risk,
95
+ RiskType,
96
+ MedicationIndication,
97
+ MedicationIndicationType,
98
+ MedicationSchedule,
99
+ ],
100
+ },
101
+ RequirementSetType.__name__: {
102
+ "dir": REQUIREMENT_SET_TYPE_DATA_DIR, # e.g. "interventions"
103
+ "model": RequirementSetType, # e.g. Intervention
104
+ "foreign_keys": [], # e.g. ["intervention_types"]
105
+ "foreign_key_models": [], # e.g. [InterventionType]
106
+ },
107
+ RequirementSet.__name__: {
108
+ "dir": REQUIREMENT_SET_DATA_DIR, # e.g. "interventions"
109
+ "model": RequirementSet, # e.g. Intervention
110
+ "foreign_keys": [
111
+ "requirement_set_type",
112
+ "requirements", # This is a many-to-many field
113
+ "links_to_sets",
114
+ "information_sources",
115
+ ], # e.g. ["intervention_types"]
116
+ "foreign_key_models": [
117
+ RequirementSetType,
118
+ Requirement,
119
+ RequirementSet,
120
+ InformationSource,
121
+ ], # e.g. [InterventionType]
122
+ },
123
+ }
124
+
125
+
126
+ class Command(BaseCommand):
127
+ help = """Load all requirement-related YAML files from their respective directories
128
+ into the database, including RequirementType, RequirementOperator, Requirement,
129
+ RequirementSetType, and RequirementSet models"""
130
+
131
+ def add_arguments(self, parser):
132
+ """
133
+ Add command-line arguments to enable verbose output.
134
+
135
+ Adds an optional '--verbose' flag to the command parser. When specified,
136
+ this flag causes the command to display detailed output during execution.
137
+ """
138
+ parser.add_argument(
139
+ "--verbose",
140
+ action="store_true",
141
+ help="Display verbose output",
142
+ )
143
+
144
+ def handle(self, *args, **options):
145
+ """
146
+ Executes data import for requirement models from YAML files.
147
+
148
+ Retrieves the verbosity setting from the command options and iterates over each model
149
+ listed in IMPORT_MODELS. For each model, it obtains the corresponding metadata from
150
+ IMPORT_METADATA and calls a helper to load the YAML data into the database. Verbose mode
151
+ enables detailed output during the process.
152
+ """
153
+ verbose = options["verbose"]
154
+ for model_name in IMPORT_MODELS:
155
+ _metadata = IMPORT_METADATA[model_name]
156
+ load_model_data_from_yaml(self, model_name, _metadata, verbose)
@@ -0,0 +1,56 @@
1
+ from django.core.management.base import BaseCommand
2
+ from endoreg_db.models import Risk, RiskType
3
+ from ...utils import load_model_data_from_yaml
4
+ from ...data import RISK_DATA_DIR, RISK_TYPE_DATA_DIR
5
+
6
+
7
+ IMPORT_MODELS = [ # string as model key, serves as key in IMPORT_METADATA
8
+ RiskType.__name__,
9
+ Risk.__name__,
10
+ ]
11
+
12
+ IMPORT_METADATA = {
13
+ RiskType.__name__: {
14
+ "dir": RISK_TYPE_DATA_DIR, # e.g. "interventions"
15
+ "model": RiskType, # e.g. Intervention
16
+ "foreign_keys": [], # e.g. ["intervention_types"]
17
+ "foreign_key_models": [], # e.g. [InterventionType]
18
+ },
19
+ Risk.__name__: {
20
+ "dir": RISK_DATA_DIR, # e.g. "interventions"
21
+ "model": Risk, # e.g. Intervention
22
+ "foreign_keys": ["risk_type"], # e.g. ["intervention_types"]
23
+ "foreign_key_models": [RiskType], # e.g. [InterventionType]
24
+ },
25
+ }
26
+
27
+
28
+ class Command(BaseCommand):
29
+ help = """Load all .yaml files in the data/intervention directory
30
+ into the Intervention and InterventionType model"""
31
+
32
+ def add_arguments(self, parser):
33
+ """
34
+ Adds the '--verbose' flag to the argument parser for detailed output.
35
+
36
+ This method extends the given parser by adding an option that, when specified,
37
+ enables verbose output during command execution.
38
+ """
39
+ parser.add_argument(
40
+ "--verbose",
41
+ action="store_true",
42
+ help="Display verbose output",
43
+ )
44
+
45
+ def handle(self, *args, **options):
46
+ """
47
+ Execute the command to load YAML data into configured models.
48
+
49
+ Retrieves the verbosity setting from the options and iterates over each model in IMPORT_MODELS.
50
+ For each model, it obtains the corresponding metadata from IMPORT_METADATA and calls the utility
51
+ function load_model_data_from_yaml to load data from the associated YAML files.
52
+ """
53
+ verbose = options["verbose"]
54
+ for model_name in IMPORT_MODELS:
55
+ _metadata = IMPORT_METADATA[model_name]
56
+ load_model_data_from_yaml(self, model_name, _metadata, verbose)