How to remove trailing/empty iterations of patient address in PID:11
I'm required to do a transformation around patient physical addresses. If (for whatever reason) a patient has multiple addresses, I want to move the home address to the first iteration of PID:11 and remove all other iterations. I've accomplished the first bit using DTL, but for patients who have multiple addresses they are left with empty trailing iterations. Here is an example I mocked up:
How can I remove those trailing iterations?
This is part of the DTL I've written to do my transformation:
<foreach property='target.{PID:PatientAddress()}' key='i' >
<if condition='source.{PID:PatientAddress(i).addresstype}'="H"' >
<true>
<assign value='' property='target.{PID:PatientAddress(i)}' action='remove' key='"i"' />
</true>
<false>
<assign value='source.{PID:PatientAddress(i).streetaddressSAD.streetormailingaddress}' property='target.{PID:PatientAddress(1).streetaddressSAD.streetormailingaddress}' action='set' />
<assign value='source.{PID:PatientAddress(i).otherdesignation}' property='target.{PID:PatientAddress(1).otherdesignation}' action='set' />
<assign value='source.{PID:PatientAddress(i).city}' property='target.{PID:PatientAddress(1).city}' action='set' />
<assign value='source.{PID:PatientAddress(i).stateorprovince}' property='target.{PID:PatientAddress(1).stateorprovince}' action='set' />
<assign value='source.{PID:PatientAddress(i).ziporpostalcode}' property='target.{PID:PatientAddress(1).ziporpostalcode}' action='set' />
<assign value='source.{PID:PatientAddress(i).country}' property='target.{PID:PatientAddress(1).country}' action='set' />
<assign value='"HOME"' property='target.{PID:PatientAddress(1).addresstype}' action='set' /> <assign value='' property='target.{PID:PatientAddress(i)}' action='remove' key='"i"' /> </false>
</if>
</foreach>
Thanks