pylantir 0.0.6__tar.gz → 0.0.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: pylantir
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Python - DICOM Modality WorkList
5
5
  Author-email: Milton Camacho <miltoncamachoicc@gmail.com>
6
6
  Requires-Python: >=3.11.1
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "pylantir"
7
- version = "0.0.6"
7
+ version = "0.0.7"
8
8
  authors = [
9
9
  {name = "Milton Camacho", email = "miltoncamachoicc@gmail.com"},
10
10
  ]
@@ -45,38 +45,58 @@ def row_to_mwl_dataset(row: WorklistItem) -> Dataset:
45
45
  ds = Dataset()
46
46
 
47
47
  # Standard Patient Attributes
48
- ds.PatientName = row.patient_name
49
- ds.PatientID = row.patient_id
50
- if row.patient_birth_date:
51
- ds.PatientBirthDate = row.patient_birth_date
52
- if row.patient_sex:
53
- ds.PatientSex = row.patient_sex
54
- if row.study_instance_uid:
55
- ds.StudyInstanceUID = row.study_instance_uid
56
- if row.patient_weight_lb:
57
- ds.PatientWeight = row.patient_weight_lb or "100"
58
- if row.study_description:
59
- ds.StudyDescription = row.study_description
60
-
61
- # Protocol-related fields
62
- if row.protocol_name:
63
- ds.ProtocolName = row.protocol_name # (0018,1030)
48
+ ds.PatientName = row.patient_name or "UNKNOWN"
49
+ ds.PatientID = row.patient_id or "UNKNOWN"
50
+ # ds.IssuerOfPatientID = row.issuer_of_patient_id
51
+ ds.PatientBirthDate = row.patient_birth_date or ""
52
+ ds.PatientSex = row.patient_sex or ""
53
+ # ds.OtherPatientIDs = row.other_patient_ids or ""
54
+ # ds.PatientAge = row.patient_age or ""
55
+ # ds.PatientSize = row.patient_size or "0"
56
+ ds.PatientWeight = row.patient_weight_lb or "100"
57
+ # ds.MedicalAlerts = row.medical_alerts or ""
58
+ # ds.Allergies = row.allergies or ""
59
+ # ds.AdditionalPatientHistory = row.additional_patient_history or ""
60
+ # ds.PregnancyStatus = row.pregnancy_status or "0"
61
+
62
+ # Study-Level Attributes
63
+ ds.StudyInstanceUID = row.study_instance_uid or ""
64
+ # ds.StudyDate = row.study_date or ""
65
+ # ds.StudyTime = row.study_time or ""
66
+ # ds.AccessionNumber = row.accession_number or ""
67
+ ds.ReferringPhysicianName = row.referring_physician_name or ""
68
+ ds.StudyDescription = row.study_description or ""
69
+ # ds.NameOfPhysiciansReadingStudy = row.reading_physicians or ""
70
+ # ds.OperatorsName = row.operators_name or ""
71
+
72
+ # Requested Procedure Attributes
73
+ # ds.RequestingPhysician = row.requesting_physician or ""
74
+ # ds.RequestedProcedureDescription = row.requested_procedure_description or "111"
75
+ ds.RequestedProcedureDescription = "111"
76
+ # ds.RequestedProcedureID = row.requested_procedure_id or ""
77
+ ds.RequestedProcedureID = "111"
78
+ # Admission & Patient State
79
+ # ds.AdmissionID = row.admission_id or ""
80
+ # ds.IssuerOfAdmissionID = row.issuer_of_admission_id or ""
81
+ # ds.SpecialNeeds = row.special_needs or ""
82
+ # ds.CurrentPatientLocation = row.current_patient_location or ""
83
+ # ds.PatientState = row.patient_state or ""
64
84
 
65
85
  # Scheduled Procedure Step Sequence
66
86
  sps = Dataset()
67
87
  sps.Modality = row.modality or "MR"
68
- sps.ScheduledStationAETitle = row.scheduled_station_aetitle or ""
88
+ # sps.ScheduledStationAETitle = row.scheduled_station_aetitle or ""
69
89
  sps.ScheduledProcedureStepStartDate = row.scheduled_start_date or ""
70
90
  sps.ScheduledProcedureStepStartTime = row.scheduled_start_time or ""
71
- sps.ScheduledPerformingPhysicianName = row.performing_physician or ""
72
- sps.ScheduledProcedureStepDescription = row.procedure_description or "DEFAULT_PROCEDURE"
91
+ # sps.ScheduledPerformingPhysicianName = row.performing_physician or ""
92
+ sps.ScheduledProcedureStepDescription = row.protocol_name or "DEFAULT_PROCEDURE"
73
93
  sps.ScheduledStationName = row.station_name or ""
94
+ sps.ScheduledProcedureStepStatus = row.performed_procedure_step_status or "SCHEDULED"
74
95
 
75
- # Adding Local Protocol to Scheduled Protocol Code Sequence. This populates the recomended protocol name in the MWL.
76
- # TODO: improve the protocol name handling
96
+ # Protocol Code Sequence
77
97
  if row.protocol_name:
78
98
  protocol_seq = Dataset()
79
- protocol_seq.CodeValue = row.protocol_name[:16] # Trim long names
99
+ protocol_seq.CodeValue = row.protocol_name[:16]
80
100
  protocol_seq.CodingSchemeDesignator = "LOCAL"
81
101
  protocol_seq.CodeMeaning = row.protocol_name
82
102
  sps.ScheduledProtocolCodeSequence = [protocol_seq]
@@ -103,7 +123,11 @@ def handle_mwl_find(event):
103
123
 
104
124
  # Only return worklist entries that are still scheduled
105
125
  query = query.filter(
106
- or_(WorklistItem.performed_procedure_step_status == "SCHEDULED", WorklistItem.performed_procedure_step_status == "IN_PROGRESS")
126
+ or_(
127
+ WorklistItem.performed_procedure_step_status == "SCHEDULED",
128
+ WorklistItem.performed_procedure_step_status == "IN_PROGRESS",
129
+ WorklistItem.performed_procedure_step_status == "DISCONTINUED"
130
+ )
107
131
  )
108
132
 
109
133
  results = query.all()
@@ -154,14 +178,16 @@ def handle_mpps_n_create(event):
154
178
  managed_instances[ds.SOPInstanceUID] = ds
155
179
 
156
180
  # Update database: Set status to IN_PROGRESS
157
- study_uid = ds.get("StudyInstanceUID", None)
181
+ patient_id = ds.get("PatientID", None)
158
182
  session = Session()
159
- if study_uid:
160
- entry = session.query(WorklistItem).filter_by(study_instance_uid=study_uid).first()
183
+ if patient_id:
184
+ entry = session.query(WorklistItem).filter_by(patient_id=patient_id).first()
161
185
  if entry:
162
186
  entry.performed_procedure_step_status = "IN_PROGRESS"
163
187
  session.commit()
164
- lgr.info(f"DB updated: StudyInstanceUID {study_uid} set to IN_PROGRESS")
188
+ lgr.info(f"DB updated: PatientID {patient_id} set to IN_PROGRESS")
189
+ else:
190
+ lgr.warning("MPPS N-SET received without StudyInstanceUID. Database update skipped.")
165
191
  session.close()
166
192
 
167
193
  lgr.info(f"MPPS N-CREATE success: {ds.SOPInstanceUID} set to IN PROGRESS")
@@ -184,21 +210,21 @@ def handle_mpps_n_set(event):
184
210
 
185
211
  # Log status update
186
212
  new_status = ds.get("PerformedProcedureStepStatus", None)
187
- study_uid = ds.get("StudyInstanceUID", None)
213
+ patient_id = ds.get("PatientID", None)
188
214
 
189
215
  # Update database
190
216
  session = Session()
191
- if study_uid and new_status:
192
- entry = session.query(WorklistItem).filter_by(study_instance_uid=study_uid).first()
217
+ if patient_id and new_status:
218
+ entry = session.query(WorklistItem).filter_by(patient_id=patient_id).first()
193
219
  if entry:
194
220
  if new_status.upper() == "COMPLETED":
195
221
  entry.performed_procedure_step_status = "COMPLETED"
196
222
  session.commit()
197
- lgr.info(f"DB updated: StudyInstanceUID {study_uid} set to COMPLETED")
223
+ lgr.info(f"DB updated: PatientID {patient_id} set to COMPLETED")
198
224
  elif new_status.upper() == "DISCONTINUED":
199
225
  entry.performed_procedure_step_status = "DISCONTINUED"
200
226
  session.commit()
201
- lgr.info(f"DB updated: StudyInstanceUID {study_uid} set to DISCONTINUED")
227
+ lgr.info(f"DB updated: PatientID {patient_id} set to DISCONTINUED")
202
228
  session.close()
203
229
 
204
230
  lgr.info(f"MPPS N-SET success: {req.RequestedSOPInstanceUID} updated to {new_status}")
File without changes
File without changes