This would switch the https://github.com/CDCgov/phdi/blob/main/containers/message-parser/app/phdc/phdc.py#L255 logic with two changes in mind:
- Change root and other ID extensions to a list
- Change loop through XML types to a dictionary
This was the scratch code I had worked on as part of the initial ticket:
def _build_recordTarget(
self,
**kwargs,
# id: str,
# root: str = None,
# assigningAuthorityName: str = None,
# telecom_data: str = None,
# addr_data: str = None,
# patient_data: str = None,
):
"""
Builds a `recordTarget` XML element for recordTarget data, which refers to
the medical record of the patient.
:param id: recordTarget identifier
:param root: recordTarget root
:param assigningAuthorityName: recordTarget assigningAuthorityName
:param telecom_data: XML data from _build_telecom
:param addr_data: XML data from _build_addr
:param patient_data: XML data from _build_patient
:raises ValueError: recordTarget needs ID to be defined.
:return recordTarget_data: XML element of the recordTarget
"""
if "id" not in kwargs or kwargs["id"] is None:
raise ValueError("The recordTarget id parameter must be a defined.")
# create recordTarget element
recordTarget_data = ET.Element("recordTarget")
# Create and append 'patientRole' element
patientRole = ET.Element("patientRole")
recordTarget_data.append(patientRole)
# initialize id data, add data, then append to patientRole
id_element = ET.Element("id")
id_element.set("extension", kwargs["id"])
element_list = ["root", "assigningAuthorityName"]
for id_elem in element_list:
if id_elem in kwargs:
id_element.set(id_elem, kwargs[id_elem])
patientRole.append(id_element)
# add address, telecom, patient
element_methods = {
"addr_data": self._build_addr,
"telecom_data": self._build_telecom,
"patient_data": self._build_patient,
}
for elem_key, method in element_methods.items():
if elem_key in kwargs:
element = method(**kwargs[elem_key])
patientRole.append(element)
The primary benefits to this are that it is a bit more compact and also allows more methods and extensions to be added to recordTarget more seamlessly and without initializing more variables, bringing it more in line with the other methods in the file.
This would switch the https://github.com/CDCgov/phdi/blob/main/containers/message-parser/app/phdc/phdc.py#L255 logic with two changes in mind:
This was the scratch code I had worked on as part of the initial ticket:
The primary benefits to this are that it is a bit more compact and also allows more methods and extensions to be added to recordTarget more seamlessly and without initializing more variables, bringing it more in line with the other methods in the file.