endoreg-db 0.6.1__py3-none-any.whl → 0.6.3__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 (28) hide show
  1. endoreg_db/data/distribution/numeric/data.yaml +1 -1
  2. endoreg_db/mermaid/Overall_flow_patient_finding_intervention.md +10 -0
  3. endoreg_db/mermaid/anonymized_image_annotation.md +20 -0
  4. endoreg_db/mermaid/binary_classification_annotation.md +50 -0
  5. endoreg_db/mermaid/classification.md +8 -0
  6. endoreg_db/mermaid/examination.md +8 -0
  7. endoreg_db/mermaid/findings.md +7 -0
  8. endoreg_db/mermaid/image_classification.md +28 -0
  9. endoreg_db/mermaid/interventions.md +8 -0
  10. endoreg_db/mermaid/morphology.md +8 -0
  11. endoreg_db/mermaid/patient_creation.md +14 -0
  12. endoreg_db/mermaid/video_segmentation_annotation.md +17 -0
  13. endoreg_db/models/ai_model/ai_model.py +1 -1
  14. endoreg_db/models/ai_model/model_meta.py +1 -1
  15. endoreg_db/models/data_file/base_classes/utils.py +1 -1
  16. endoreg_db/serializers/raw_pdf_anony_text_validation.py +137 -0
  17. endoreg_db/serializers/raw_pdf_meta_validation.py +223 -0
  18. endoreg_db/serializers/raw_video_meta_validation.py +163 -1
  19. endoreg_db/serializers/video_segmentation.py +207 -112
  20. endoreg_db/urls.py +110 -11
  21. endoreg_db/views/raw_pdf_anony_text_validation_views.py +95 -0
  22. endoreg_db/views/raw_pdf_meta_validation_views.py +111 -0
  23. endoreg_db/views/raw_video_meta_validation_views.py +128 -18
  24. endoreg_db/views/video_segmentation_views.py +28 -11
  25. {endoreg_db-0.6.1.dist-info → endoreg_db-0.6.3.dist-info}/METADATA +11 -1
  26. {endoreg_db-0.6.1.dist-info → endoreg_db-0.6.3.dist-info}/RECORD +28 -13
  27. {endoreg_db-0.6.1.dist-info → endoreg_db-0.6.3.dist-info}/WHEEL +0 -0
  28. {endoreg_db-0.6.1.dist-info → endoreg_db-0.6.3.dist-info}/licenses/LICENSE +0 -0
@@ -10,5 +10,5 @@
10
10
  fields:
11
11
  name: "uniform_high_x1.5"
12
12
  distribution_type: "uniform"
13
- min_descriptor: "max_x_1"
13
+ min_descriptor: "min_x_1"
14
14
  max_descriptor: "max_x_1.5"
@@ -0,0 +1,10 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ %% Main Patient Workflow
5
+ A[Patient: John] --> B[Examination: Colonoscopy]
6
+ B --> C[Finding: Colon Polyp]
7
+ C --> D[Finding Location: Colonoscopy Default - Right Flexure]
8
+ D --> E[Finding Morphology: Colon Lesion Planarity Default - Colon Lesion Planarity Excavated]
9
+ E --> F[Intervention: Colon Lesion Polypectomy - Hot Snare]
10
+ F --> G[Report Generation]
@@ -0,0 +1,20 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ %% File Handling Process
5
+ A[**Uploaded File**] -->|Original File Uploaded| B[**Anonymized File**]
6
+ B -->|File Anonymized & Stored| C[**Anonymous Image Annotation**]
7
+
8
+ %% Image Annotation & Processing
9
+ C -->|Label Assigned| D[**Anonymized Image Label**]
10
+ C -->|Detected Personal Info Removed| E[**Dropped Name**]
11
+
12
+ %% Relationships & Processing
13
+ E -->|Stored for Record-Keeping| C;
14
+ D -->|Predefined Labels Used| C;
15
+
16
+ %% Example Data (Corrected & Meaningful)
17
+ X1(["**Example: Uploaded colonoscopy.jpg**"]) -.-> A;
18
+ X2(["**Example: anonymized_colonoscopy.jpg**"]) -.-> B;
19
+ X3(["**Example: Label - 'Polyp Detected'**"]) -.-> D;
20
+ X4(["**Example: Name 'John Doe' removed**"]) -.-> E;
@@ -0,0 +1,50 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+
5
+
6
+ %% Step 1: Image Classification (Start)
7
+
8
+ A[**Image Classification**] -->|Uses| B[**Label**];
9
+
10
+
11
+
12
+ %% Step 2: Video Segmentation
13
+
14
+ A -->|Segments Stored In| C[**Video Segmentation**];
15
+
16
+
17
+
18
+ %% Step 3: Automatic Segmentation Detection
19
+
20
+ D["**find_segments_in_prediction_array()**"] -->|Detects & Segments| C;
21
+
22
+
23
+
24
+ %% Step 4: Fetching Unclassified Frames for Annotation
25
+
26
+ E["get_legacy_binary_classification_annotation_tasks_by_label()"] -->|Finds Frames Needing Annotation| F;
27
+
28
+
29
+
30
+ %% Step 5: Binary Classification Task Management
31
+
32
+ F[**Binary Classification Task**] -->|Assigned To| G[**Frame**];
33
+
34
+ F -->|Assigned To| H[**Legacy Frame**];
35
+
36
+ F -->|Uses| B;
37
+
38
+ %% Step 6: Task Completion & Cleanup (End)
39
+
40
+ I["clear_finished_legacy_tasks()"] -->|Removes Completed Tasks| F;
41
+
42
+
43
+
44
+ %% Example Data
45
+
46
+ X1(["Example: Frame classified as 'Polyp Present'"]) -.-> A;
47
+
48
+ X2(["Example: Video segment marked from 100s to 200s"]) -.-> C;
49
+
50
+ X3(["Example: 10 unclassified frames found"]) -.-> F;
@@ -0,0 +1,8 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Select Finding Location Classification"] --> B["Store in endoreg_db_findinglocationclassification"]
5
+ B --> C["Retrieve Available Choices"]
6
+ C --> D["Save Selected Location in endoreg_db_patientfinding_locations"]
7
+ D --> E["Link Location to Patient Finding via Foreign Key"]
8
+ E --> F["Finding Location Process Completed"]
@@ -0,0 +1,8 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Record Examination"] --> B["Store in endoreg_db_examination"]
5
+ B --> C["Retrieve Patient ID"]
6
+ C --> D["Save in endoreg_db_patientexamination with Patient ID"]
7
+ D --> E["Link Patient to Examination via Foreign Key"]
8
+ E --> F["Examination Process Completed"]
@@ -0,0 +1,7 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Identify Medical Finding"] --> B["Store in endoreg_db_finding"]
5
+ B --> C["Retrieve Patient Examination ID"]
6
+ C --> D["Save in endoreg_db_patientfinding with Examination ID (Link Finding to Examination via Foreign Key)"]
7
+ D --> E["Finding Process Completed"]
@@ -0,0 +1,28 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ %% Image Classification Process
5
+ A[**Image Classification Annotation**] -->|Attached to| B[**Frame**];
6
+ A -->|Attached to| C[**Legacy Frame**];
7
+ A -->|Attached to| D[**Legacy Image**];
8
+ A -->|Uses Predefined| E[**Label**];
9
+
10
+ %% Video Segmentation Process
11
+ F[**Abstract Label Video Segment**] -->|Base Class for| G[**Legacy Label Video Segment**];
12
+ F -->|Base Class for| H[**Label Video Segment**];
13
+
14
+ %% Video References
15
+ G -->|Segmentation of| I[**Legacy Video**];
16
+ H -->|Segmentation of| J[**Modern Video**];
17
+
18
+ %% Metadata & Prediction Handling
19
+ G -->|Uses Prediction Data| K[**Legacy Video Prediction Meta**];
20
+ H -->|Uses Prediction Data| L[**Video Prediction Meta**];
21
+
22
+ %% Automatic Segmentation Process
23
+ M["**find_segments_in_prediction_array()**"] -->|Detects & Segments Frames| F;
24
+
25
+ %% Example Data
26
+ X1(["**Example: Frame classified as 'Polyp Present'**"]) -.-> A;
27
+ X2(["**Example: Segment starts at frame 100, ends at frame 200**"]) -.-> F;
28
+ X3(["**Example: Legacy Video used for segmentation**"]) -.-> G;
@@ -0,0 +1,8 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Select Intervention"] --> B["Store in endoreg_db_findingintervention"]
5
+ B --> C["Retrieve Patient Finding ID"]
6
+ C --> D["Save in endoreg_db_patientfindingintervention"]
7
+ D --> E["Link Intervention to Patient Finding via Foreign Key"]
8
+ E --> F["Intervention Process Completed"]
@@ -0,0 +1,8 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Select Morphology Classification"] --> B["Store in endoreg_db_findingmorphologyclassification"]
5
+ B --> C["Retrieve Associated Classification Type"]
6
+ C --> D["Save in endoreg_db_patientfinding_morphology"]
7
+ D --> E["Link Morphology to Patient Finding via Foreign Key"]
8
+ E --> F["Morphology Process Completed"]
@@ -0,0 +1,14 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ A["Start: Create New Patient (John)"] --> B{"Does the Center Exist?"}
5
+
6
+ B -- Yes --> C["Retrieve Existing Center ID"]
7
+ B -- No --> D["Create New Medical Center"]
8
+
9
+ D --> E["Retrieve Newly Created Center ID"]
10
+ C --> F["Save Patient in endoreg_db_patient with Center ID"]
11
+ E --> F
12
+
13
+ F --> G["Patient Registration Completed"]
14
+
@@ -0,0 +1,17 @@
1
+ ```mermaid
2
+ graph TD;
3
+
4
+ %% Label Management
5
+ A[**Video Segmentation Label**] -->|Used in| B[**Video Segmentation Annotation**];
6
+
7
+ %% Annotation Process
8
+ B -->|Assigned to| C[**Raw Video File**];
9
+
10
+ %% Attributes Breakdown
11
+ A -->|Has Fields| A1[**Name, Description, Color, Priority**];
12
+ B -->|Has Fields| B1[**Start Time, Stop Time, Validity**];
13
+
14
+ %% Example Data (Placed Outside for Clarity)
15
+ X1(["Example: Label - 'Polyp Detected'"]) -.-> A;
16
+ X2(["Example: Video1.mp4, Start: 10s, Stop: 15s"]) -.-> B;
17
+
@@ -7,7 +7,7 @@ import os
7
7
  from django.db import models
8
8
  from icecream import ic
9
9
 
10
- PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data")))
10
+ PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data"))).expanduser()
11
11
 
12
12
  STORAGE_LOCATION = PSEUDO_DIR
13
13
  WEIGHTS_DIR_NAME = "db_model_weights"
@@ -14,7 +14,7 @@ from icecream import ic
14
14
  if TYPE_CHECKING:
15
15
  from endoreg_db.models import LabelSet, AiModel # pylint: disable=import-outside-toplevel
16
16
 
17
- PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data")))
17
+ PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data"))).expanduser()
18
18
 
19
19
  STORAGE_LOCATION = PSEUDO_DIR
20
20
  WEIGHTS_DIR_NAME = "db_model_weights"
@@ -10,7 +10,7 @@ import numpy as np
10
10
  DJANGO_NAME_SALT = os.environ.get("DJANGO_NAME_SALT", "default_salt")
11
11
 
12
12
  # Directory stuff
13
- PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data")))
13
+ PSEUDO_DIR = Path(os.environ.get("DJANGO_PSEUDO_DIR", Path("./erc_data"))).expanduser()
14
14
  STORAGE_LOCATION = PSEUDO_DIR
15
15
  FRAME_DIR_NAME = os.environ.get("DJANGO_FRAME_DIR_NAME", "db_frames")
16
16
  RAW_FRAME_DIR_NAME = os.environ.get("DJANGO_RAW_FRAME_DIR_NAME", "db_raw_frames")
@@ -0,0 +1,137 @@
1
+ from pathlib import Path
2
+ from rest_framework import serializers
3
+ from django.conf import settings
4
+ from ..models import RawPdfFile
5
+
6
+ class RawPdfAnonyTextSerializer(serializers.ModelSerializer):
7
+ """
8
+ Serializer to fetch PDF metadata along with `anonymized_text` from `RawPdfFile`.
9
+ Ensures Vue.js can process JSON efficiently.
10
+ """
11
+
12
+ pdf_url = serializers.SerializerMethodField()
13
+ full_pdf_path = serializers.SerializerMethodField()
14
+ file = serializers.SerializerMethodField()
15
+
16
+ class Meta:
17
+ model = RawPdfFile
18
+ fields = ['id', 'file', 'pdf_url', 'full_pdf_path',
19
+ 'sensitive_meta_id', 'anonymized_text']
20
+
21
+ @staticmethod
22
+ def get_next_pdf(last_id=None):
23
+ """
24
+ Retrieves the first available PDF if `last_id` is NOT provided.
25
+ Otherwise, fetches the next available PDF where `id > last_id`.
26
+ """
27
+ query_filter = {} if last_id is None else {"id__gt": int(last_id)}
28
+ pdf_entry = RawPdfFile.objects.filter(**query_filter).order_by('id').first()
29
+ return pdf_entry
30
+
31
+ def get_pdf_url(self, obj):
32
+ """
33
+ Generates the full URL where Vue.js can fetch and display the PDF.
34
+ """
35
+ request = self.context.get('request')
36
+ return request.build_absolute_uri(f"/api/pdf/anony_text/?id={obj.id}") if request and obj.file else None
37
+
38
+ def get_file(self, obj):
39
+ """
40
+ Returns the relative file path stored in the database.
41
+ """
42
+ return str(obj.file.name).strip() if obj.file else None
43
+
44
+ def get_full_pdf_path(self, obj):
45
+ """
46
+ Constructs the full absolute file path using `settings.MEDIA_ROOT`.
47
+ """
48
+ if not obj.file:
49
+ return None
50
+ pdf_relative_path = str(obj.file.name)
51
+ full_path = Path(settings.MEDIA_ROOT) / pdf_relative_path
52
+ return str(full_path) if full_path.exists() else None
53
+
54
+ def validate_anonymized_text(self, value):
55
+ """
56
+ Ensures the anonymized_text is not empty or too long.
57
+ """
58
+ if not value.strip():
59
+ raise serializers.ValidationError("Anonymized text cannot be empty.")
60
+ if len(value) > 5000: # Arbitrary limit to prevent excessively long text
61
+ raise serializers.ValidationError("Anonymized text exceeds the maximum length of 5000 characters.")
62
+ return value
63
+
64
+ def update(self, instance, validated_data):
65
+ """
66
+ Updates only `anonymized_text` without modifying other fields.
67
+ """
68
+ instance.anonymized_text = validated_data.get('anonymized_text', instance.anonymized_text)
69
+ instance.save()
70
+ return instance
71
+
72
+
73
+
74
+ """
75
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
76
+
77
+ const fetchPdfWithAnonymizedText = async (lastId = null) => {
78
+ const url = lastId
79
+ ? `http://localhost:8000/api/pdf/anony_text/?last_id=${lastId}`
80
+ : "http://localhost:8000/api/pdf/anony_text/";
81
+
82
+ try {
83
+ const response = await axios.get(url, { headers: { "Accept": "application/json" } });
84
+ console.log("PDF Data:", response.data);
85
+ } catch (error) {
86
+ console.error("Error fetching PDF:", error.response?.data || error);
87
+ }
88
+ };
89
+
90
+ fetchPdfWithAnonymizedText();
91
+
92
+ """
93
+
94
+ """
95
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
96
+
97
+ const updateAnonymizedText = async (pdfId, newText) => {
98
+ try {
99
+ const response = await axios.patch("http://localhost:8000/api/pdf/update_anony_text/", {
100
+ id: pdfId,
101
+ anonymized_text: newText
102
+ }, { headers: { "Content-Type": "application/json" } });
103
+
104
+ console.log("Update Success:", response.data);
105
+ } catch (error) {
106
+ console.error("Update Error:", error.response?.data || error);
107
+ }
108
+ };
109
+
110
+ updateAnonymizedText(1, "Updated anonymized text.");
111
+
112
+ """
113
+
114
+ """
115
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
116
+
117
+ const updateAnonymizedText = async () => {
118
+ const updatedData = {
119
+ id: 1,
120
+ anonymized_text: "This is the updated anonymized text."
121
+ };
122
+
123
+ try {
124
+ const response = await axios.patch("http://localhost:8000/api/pdf/update_anony_text/", updatedData, {
125
+ headers: { "Content-Type": "application/json" }
126
+ });
127
+
128
+ console.log("Update Success:", response.data);
129
+ alert("Anonymized text updated successfully!");
130
+ } catch (error) {
131
+ console.error("Update Error:", error.response?.data || error);
132
+ alert("Failed to update anonymized text.");
133
+ }
134
+ };
135
+
136
+ updateAnonymizedText();
137
+ """
@@ -0,0 +1,223 @@
1
+ from pathlib import Path
2
+ from rest_framework import serializers
3
+ from django.conf import settings
4
+ from ..models import RawPdfFile, SensitiveMeta
5
+
6
+
7
+ class PDFFileForMetaSerializer(serializers.ModelSerializer):
8
+ """
9
+ Serializer to fetch PDF metadata along with linked `SensitiveMeta` details.
10
+ Implements validation and ensures Vue.js can process errors easily.
11
+ """
12
+
13
+ # Fetch patient details from `SensitiveMeta`
14
+ patient_first_name = serializers.CharField(source="sensitive_meta.patient_first_name", read_only=True)
15
+ patient_last_name = serializers.CharField(source="sensitive_meta.patient_last_name", read_only=True)
16
+ patient_dob = serializers.CharField(source="sensitive_meta.patient_dob", read_only=True)
17
+ examination_date = serializers.CharField(source="sensitive_meta.examination_date", read_only=True)
18
+
19
+ # PDF file URL where Vue.js can fetch the document
20
+ pdf_url = serializers.SerializerMethodField()
21
+
22
+ # Full absolute path of the PDF file
23
+ full_pdf_path = serializers.SerializerMethodField()
24
+
25
+ # Direct file path from the database
26
+ file = serializers.SerializerMethodField()
27
+
28
+ class Meta:
29
+ model = RawPdfFile
30
+ fields = ['id', 'file', 'pdf_url', 'full_pdf_path',
31
+ 'sensitive_meta_id', 'patient_first_name',
32
+ 'patient_last_name', 'patient_dob', 'examination_date']
33
+
34
+ @staticmethod
35
+ def get_next_pdf(last_id=None):
36
+ """
37
+ Retrieves the first available PDF if `last_id` is NOT provided.
38
+ Otherwise, fetches the next available PDF where `id > last_id`.
39
+ """
40
+ query_filter = {} if last_id is None else {"id__gt": int(last_id)}
41
+
42
+ # Get the next available PDF
43
+ pdf_entry = RawPdfFile.objects.select_related("sensitive_meta").filter(**query_filter).order_by('id').first()
44
+
45
+ return pdf_entry # Returns a model instance or None
46
+
47
+ def get_pdf_url(self, obj):
48
+ """
49
+ Generates the full URL for Vue.js to fetch and display the PDF.
50
+ """
51
+ request = self.context.get('request')
52
+ print("---------------------here :",obj.file)
53
+ if request and obj.file:
54
+ return request.build_absolute_uri(f"/api/pdf/sensitivemeta/?id={obj.id}") # Constructs full API endpoint
55
+ return None # Return None if file is missing
56
+
57
+ def get_file(self, obj):
58
+ """
59
+ Returns the relative file path stored in the database.
60
+ """
61
+ if not obj.file:
62
+ return None # No file linked
63
+ return str(obj.file.name).strip() # Ensures clean output
64
+
65
+ def get_full_pdf_path(self, obj):
66
+ """
67
+ Constructs the full absolute file path using `settings.MEDIA_ROOT`.
68
+ """
69
+ if not obj.file:
70
+ return None # No file linked
71
+
72
+ pdf_relative_path = str(obj.file.name)
73
+
74
+ full_path = Path(settings.MEDIA_ROOT) / pdf_relative_path
75
+
76
+ return str(full_path) if full_path.exists() else None # Returns path or None if file is missing
77
+
78
+ def validate(self, data):
79
+ """
80
+ Ensures that the PDF file is valid and has required fields.
81
+ """
82
+ errors = {}
83
+
84
+ if 'file' in data and not data['file']:
85
+ errors['file'] = "A valid PDF file is required."
86
+
87
+ if 'sensitive_meta_id' in data and not SensitiveMeta.objects.filter(id=data['sensitive_meta_id']).exists():
88
+ errors['sensitive_meta_id'] = "The provided sensitive_meta_id does not exist."
89
+
90
+ if errors:
91
+ raise serializers.ValidationError(errors) # Returns structured error response
92
+
93
+ return data # Returns validated data
94
+
95
+
96
+ from rest_framework import serializers
97
+ from ..models import SensitiveMeta
98
+
99
+ class SensitiveMetaUpdateSerializer(serializers.ModelSerializer):
100
+ """
101
+ Serializer for updating patient details in the `SensitiveMeta` table.
102
+ Allows partial updates.
103
+ """
104
+
105
+ sensitive_meta_id = serializers.IntegerField(write_only=True) # Needed for lookup, not included in response
106
+
107
+ class Meta:
108
+ model = SensitiveMeta
109
+ fields = ['sensitive_meta_id', 'patient_first_name', 'patient_last_name', 'patient_dob', 'examination_date']
110
+
111
+ def validate(self, data):
112
+ """
113
+ Ensures valid input before updating.
114
+ """
115
+ errors = {}
116
+
117
+ if 'patient_first_name' in data and (not data['patient_first_name'].strip()):
118
+ errors['patient_first_name'] = "First name cannot be empty."
119
+
120
+ if 'patient_last_name' in data and (not data['patient_last_name'].strip()):
121
+ errors['patient_last_name'] = "Last name cannot be empty."
122
+
123
+ if 'patient_dob' in data and not data['patient_dob']:
124
+ errors['patient_dob'] = "Date of birth is required."
125
+
126
+ if 'examination_date' in data and not data['examination_date']:
127
+ errors['examination_date'] = "Examination date is required."
128
+
129
+ if errors:
130
+ raise serializers.ValidationError(errors)
131
+
132
+ return data
133
+
134
+ def update(self, instance, validated_data):
135
+ """
136
+ Updates only the provided fields dynamically.
137
+ """
138
+ validated_data.pop("sensitive_meta_id", None) # Remove ID before updating
139
+
140
+ for attr, value in validated_data.items():
141
+ setattr(instance, attr, value) # Dynamically update fields
142
+
143
+ instance.save()
144
+ return instance
145
+
146
+
147
+
148
+ """
149
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
150
+ const fetchPdfMeta = async (lastId = 1) => {
151
+ const url = lastId
152
+ ? `http://localhost:8000/api/pdf/sensitivemeta/?last_id=${lastId}`
153
+ : "http://localhost:8000/api/pdf/sensitivemeta/";
154
+
155
+ try {
156
+ const response = await axios.get(url);
157
+ console.log("PDF Metadata:", response.data);
158
+ } catch (error) {
159
+ console.error("Error fetching PDFs:", error.response?.data || error);
160
+ }
161
+ };
162
+
163
+ fetchPdfMeta(); // Fetch the first available PDF
164
+
165
+ """
166
+
167
+ """with header response"""
168
+ """
169
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
170
+
171
+ const fetchPdfMeta = async (lastId = 1) => {
172
+ const url = lastId
173
+ ? `http://localhost:8000/api/pdf/sensitivemeta/?last_id=${lastId}`
174
+ : "http://localhost:8000/api/pdf/sensitivemeta/";
175
+
176
+ try {
177
+ const response = await axios.get(url, {
178
+ headers: {
179
+ "Accept": "application/json"
180
+ }
181
+ });
182
+
183
+ console.log("PDF Metadata (JSON Expected):", response.data);
184
+ } catch (error) {
185
+ console.error("Error fetching PDFs:", error.response?.data || error);
186
+ }
187
+ };
188
+
189
+ fetchPdfMeta();
190
+ """
191
+
192
+
193
+ """
194
+ await import('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
195
+
196
+ const updatePatientInfo = async () => {
197
+ const updatedData = {
198
+ sensitive_meta_id: 1,
199
+ patient_first_name: "dummy value",
200
+ patient_last_name: "dummy value",
201
+ patient_dob: "1994-06-15",
202
+ examination_date: "2024-06-15"
203
+ };
204
+
205
+ try {
206
+ const response = await axios.patch("http://localhost:8000/api/pdf/update_sensitivemeta/", updatedData, {
207
+ headers: { "Content-Type": "application/json" }
208
+ });
209
+
210
+ console.log("Update Success:", response.data);
211
+ alert("Patient information updated successfully!");
212
+
213
+ return response.data;
214
+ } catch (error) {
215
+ console.error("Update Error:", error.response?.data || error);
216
+ alert("Failed to update patient information.");
217
+ return error.response?.data || { error: "Unknown error" };
218
+ }
219
+ };
220
+
221
+ updatePatientInfo().then(response => console.log("Final Response:", response));
222
+
223
+ """