phc-ingestion 0.10.6__py3-none-any.whl → 0.10.8__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.
@@ -72,9 +72,16 @@ class ManifestAssembler:
72
72
 
73
73
  response = self.client.invoke(path, "get", None, params)
74
74
  entries = response.get("entry", [])
75
- patient = entries[0]["resource"] if len(entries) > 0 else None
76
75
 
77
- return patient
76
+ if len(entries) == 0:
77
+ return None
78
+
79
+ if len(entries) > 1:
80
+ raise RuntimeError(
81
+ f"Found {len(entries)} patients with kit id {self.kit_id}. Expected 1."
82
+ )
83
+
84
+ return entries[0]["resource"]
78
85
 
79
86
  def __fetch_resource_by_type_and_reference(
80
87
  self,
@@ -92,14 +99,11 @@ class ManifestAssembler:
92
99
  except RuntimeError:
93
100
  return None
94
101
 
95
- def __extract_identifier_from_resource(self, resource: Resource | None) -> str:
96
- if not resource:
97
- return ""
98
-
102
+ def __extract_identifier_from_resource(self, resource: Resource) -> str:
99
103
  identifiers = resource.get("identifier", [])
100
104
  return identifiers[0].get("value", "") if identifiers else ""
101
105
 
102
- def __extract_id_from_reference(self, reference: Reference) -> str:
106
+ def __extract_id_from_reference(self, reference: Reference | None) -> str:
103
107
  if not reference:
104
108
  return ""
105
109
 
@@ -110,10 +114,12 @@ class ManifestAssembler:
110
114
  parts = ref_string.split("/")
111
115
  return parts[1] if len(parts) > 1 else parts[0]
112
116
 
113
- def __extract_elation_mrn(self, patient: Patient) -> str:
114
- if not patient:
117
+ def __extract_id_from_reference_list(self, references: list[Reference] | None) -> str:
118
+ if not references or len(references) == 0:
115
119
  return ""
120
+ return self.__extract_id_from_reference(references[0])
116
121
 
122
+ def __extract_elation_mrn(self, patient: Patient) -> str:
117
123
  identifier = next(
118
124
  (
119
125
  x
@@ -134,12 +140,9 @@ class ManifestAssembler:
134
140
 
135
141
  def __parse_human_name(self, human_name: list[HumanName] | None):
136
142
  if not human_name:
137
- return None
138
-
139
- human_name = next((x for x in human_name if x.get("use") == "official"), None)
143
+ return {}
140
144
 
141
- if not human_name:
142
- return None
145
+ human_name = next((x for x in human_name if x.get("use") == "official"), human_name[0])
143
146
 
144
147
  last_name = human_name.get("family", "")
145
148
  first_name = human_name.get("given", [])[0]
@@ -163,11 +166,16 @@ class ManifestAssembler:
163
166
  "Organization", patient.get("managingOrganization")
164
167
  )
165
168
 
166
- general_practitioner: Practitioner | None = self.__fetch_resource_by_type_and_reference(
167
- "Practitioner", patient.get("generalPractitioner")
168
- )
169
+ # Handle generalPractitioner as a list
170
+ general_practitioner: Practitioner | None = None
171
+ general_practitioner_refs: list[Reference] = patient.get("generalPractitioner", [])
172
+ if general_practitioner_refs:
173
+ general_practitioner = self.__fetch_resource_by_type_and_reference(
174
+ "Practitioner",
175
+ {"reference": self.__extract_id_from_reference_list(general_practitioner_refs)},
176
+ )
169
177
 
170
- patient_info = self.__parse_human_name(patient["name"])
178
+ patient_info = self.__parse_human_name(patient.get("name"))
171
179
  practitioner_info = self.__parse_human_name(
172
180
  general_practitioner.get("name") if general_practitioner else None
173
181
  )
@@ -185,10 +193,10 @@ class ManifestAssembler:
185
193
  "indication": NEBULA_INDICATION,
186
194
  "indicationDisplay": NEBULA_INDICATION,
187
195
  "patientInfo": {
188
- "lastName": patient_info.get("lastName"),
196
+ "lastName": patient_info.get("lastName", ""),
189
197
  "dob": datetime.fromisoformat(patient_birth_date).strftime("%Y-%m-%d"),
190
- "firstName": patient_info.get("firstName"),
191
- "gender": patient["gender"],
198
+ "firstName": patient_info.get("firstName", ""),
199
+ "gender": patient.get("gender", ""),
192
200
  },
193
201
  **(
194
202
  {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phc-ingestion
3
- Version: 0.10.6
3
+ Version: 0.10.8
4
4
  Summary: Functions for LifeOmic PHC genomic ingestions
5
5
  License: MIT
6
6
  Author-email: LifeOmic Development <development@lifeomic.com>
@@ -28,7 +28,7 @@ ingestion/generic/process.py,sha256=ZaVnZ_gx9faDUsuresI1A0oCegTa-dPQT7DBFMeZGyY,
28
28
  ingestion/generic/utils.py,sha256=1MEIru7uq38IjUdL8lcHqDH0oTki9uWrz1f2e-pmRoU,2814
29
29
  ingestion/nebula/__init__.py,sha256=VauK-rup_N8ZXVohx3HYqHX_PE_WoPyMUhdv2R7al4o,45
30
30
  ingestion/nebula/constants.py,sha256=thKqSwemdaAwAmKvF4FEVI9l1Ph5ergsnMlx6nWte7E,357
31
- ingestion/nebula/manifest_assembler.py,sha256=OPUnuvzL1Bti_1-4N3fDP22wHtaK__4Bwh5K21Mg-C4,6416
31
+ ingestion/nebula/manifest_assembler.py,sha256=9DME3AlPVvXY2SuR9QBgqfvHh3rJ-DoZRLcJPTonh2E,6974
32
32
  ingestion/nebula/process.py,sha256=D2ct9tF60ZIP_jZdjvgjfTkhEAkNNEhxaSqa04CtNR8,2237
33
33
  ingestion/nextgen/__init__.py,sha256=7LQ-h_Bvc5P1QcHMdzsqi1Qm4fTJn04-ozar2ty9wSc,59
34
34
  ingestion/nextgen/process.py,sha256=5Z0RfclwTAYZruGDiLPutjPCYFh1DJpoWY9dnttghT4,3993
@@ -59,6 +59,6 @@ ingestion/vcf_standardization/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
59
59
  ingestion/vcf_standardization/util/af_helpers.py,sha256=dpTzoeIQVeBRt0ETF3a9rp5ojZqznHg4x_hCZ8OPcOg,1061
60
60
  ingestion/vcf_standardization/util/dp_helpers.py,sha256=Nq8oLOLObu4_pv16qwwgpALRlUoJVCULrd9cFOD-eoI,823
61
61
  ingestion/vcf_standardization/util/read_write.py,sha256=x3Pf6Dq8tmolblbCS5CrNmrcHS3FGfqBSFpFgvFGC4g,2526
62
- phc_ingestion-0.10.6.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
63
- phc_ingestion-0.10.6.dist-info/METADATA,sha256=IhIQUPLXKsepjBwgwe4ARhaZ2fKrmvsJhsgey1Yui7o,677
64
- phc_ingestion-0.10.6.dist-info/RECORD,,
62
+ phc_ingestion-0.10.8.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
63
+ phc_ingestion-0.10.8.dist-info/METADATA,sha256=y4CsB4FWZJOJR4-qSq1sHl6FCGwu5eXpnI48DLuma40,677
64
+ phc_ingestion-0.10.8.dist-info/RECORD,,