Created 09-18-2017 02:17 PM
My AttributesToJSON outputs values this way from a hl7 file after going through ExtractHL7Attributes,
{"PID.PatientName.FamilyName":"Patient","PID.PatientName.GivenName":"Test"}
I want to format the above in this fashion,
"name":[{"family":"Patient","given":"Test"}]
Can it be achieved by using RegEx in properties or through any other processor. Please provide any sample case.
Thanks in advance.
Created 09-18-2017 02:20 PM
Created 09-18-2017 02:43 PM
@Vigneswar Gv Regex probably isn't the right solution here. Instead I'd recommend looking at one of the following:
There are pros and cons to each. Sometimes figuring out the right JOLT specification can be a little tricky but I think this [1] is close to what you're looking for. Solving this with a Groovy script should be pretty straightforward though since you always want to split the keys on the dots. You'll just need a recursive function that iterates through keys, pops off the leading content before the dot and merges it into a sub-entry.
Created 09-19-2017 08:21 AM
Hi @jfrazee
Thanks for the response. I played around with JoltTransformJSON and was able to transform it from this,
{ "PID.PatientName.FamilyName": "Patient", "PID.PatientName.GivenName": "Test" }
to this,
{ "family": "Patient", "given": "Test" }
The JOLT specification i used was,
[{
"operation": "shift",
"spec": {
"PID.PatientName.FamilyName": "family", "PID.PatientName.GivenName": "given"
}
}]
However i wasn't able to include the part "name" in the json which was end result expected,
"name":[{"family":"Patient","given":"Test"}]
Can you advice of what should be done in JOLT spec to get the desired result ?
With input attributes like,
{ "PID.PatientName.FamilyName": "Patient", "PID.PatientName.GivenName": "Test", "PID.PhoneNumber.Home": "(123)456789"}
The final JSON formatted output will be looking something like the one below,
{"resourceType":"Patient","identifier":[{"use":"official","system":"urn:fake:mrns","value":"800001","assigner":{"display":"HealthCare Org"}}],"name":[{"family":"Patient","given":"Test12"}],"telecom":[{"system":"phone","value":"111-111-1111","use":"home"}]}
Created 09-22-2017 09:55 PM
I'm not sure why you need an array around the name object - can you explain? Otherwise, you can achieve your desired result by putting "name" in front of your other sub-objects.
[{
"operation": "shift",
"spec": {
"PID.PatientName.FamilyName": "name.family", "PID.PatientName.GivenName": "name.given"
}
}]
Created 09-20-2017 11:05 AM
@Vigneswar Gv you always can use this debugger before use the processor to make sure it will work OK http://jolt-demo.appspot.com/#prefixSoupToBuckets