· Feb 3, 2022

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}&apos;="H"' >
<assign value='' property='target.{PID:PatientAddress(i)}' action='remove' key='"i"' />
<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>


Product version: HealthShare 2017.2
$ZV: Cache for Windows (x86-64) 2017.2.2 (Build 867_4_20177U) Fri Aug 14 2020 21:51:37 EDT
Discussion (2)0
Log in or sign up to continue

Hi Marcus,

Sometimes it easier not copy all the addresses across in the first place, so that the target addresses field is empty when you start the 'for each' loop, but if you have copied all the addresses across then I would clear all the target addresses out, before your 'for each' loop.

So the code would be something like:

<assign value='' property='target.{PatientAddress}' action='clear' />
<foreach property='source.{PatientAddress()}' key='k1' >
<if condition='source.{PatientAddress(k1).addresstype}="H"' >
<assign value='source.{PatientAddress(k1)}' property='target.{PatientAddress(1)}' action='set' />
<assign value='"HOME"' property='target.{PatientAddress(1).addresstype}' action='set' />

Hop this helps.