Requirement: I have a Source file that has multiple client IDs and each client ID may have x number of patients. So, I would like to group that data as per client ID in Data Mapping like as shown below:-
Source File:
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Record recordNumber="1">
<Centron_Client_ID>DE31553B</Centron_Client_ID>
<Patient_ID>patient5</Patient_ID>
</Record>
<Record recordNumber="2">
<Centron_Client_ID>DE31553B</Centron_Client_ID>
<Patient_ID>patient4</Patient_ID>
</Record>
<Record recordNumber="3">
<Centron_Client_ID>DE31553B</Centron_Client_ID>
<Patient_ID>463521</Patient_ID>
</Record>
<Record recordNumber="4">
<Centron_Client_ID>CE31553B</Centron_Client_ID>
<Patient_ID>memberSam123</Patient_ID>
</Record>
<Record recordNumber="5">
<Centron_Client_ID>CE31553B</Centron_Client_ID>
<Patient_ID>patient2</Patient_ID>
</Record>
Expected Output:
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Record recordNumber="1">
<ClientId>DE31553B</ClientId>
<PatientIds>patient5</PatientIds>
<PatientIds>patient4</PatientIds>
<PatientIds>463521</PatientIds>
</Record>
<Record recordNumber="2">
<ClientId>CE31553B</ClientId>
<PatientIds>memberSam123</PatientIds>
<Patient_ID>patient2</Patient_ID>
</Record>
</Root>
Solution: Kindly, follow the below-mentioned steps in Data Mapping in order to achieve this requirement.
1. Create a Key function and define Key Name: "GroupByClientId", KeyMatch: "Record" and Key Use: "Centron_Client_ID".
2. Now, define the below rule in the for-each tab of Record node.
$Input_AntSource/Root/Record[generate-id()= generate-id(key('GroupByClientId',Centron_Client_ID)[1])]
Note: Change the Record Xpath ($Input_AntSource/Root/Record) accordingly.
3. Create a local variable like varCID on Record node with value:-
normalize-space($Input_AntSource/Root/Record/Centron_Client_ID)
4. Now, on Patient_Id node, define the for-each rule.
//Root/Record[normalize-space(Centron_Client_ID ) = $varCID]
5. Map the Target Node by using Textual rule and write the Node name without their Xpath.
Comments
0 comments
Article is closed for comments.