hl7apy
hl7apy copied to clipboard
Add a to_dict() method to Element
Many times it's easier to quickly view the contents of an HL7 message in a dictionary format (or convert it to JSON). It would be great if there was a simple to_dict() method on Element that would recursively "do the right thing" and call the to_er7() method while retuning that contents as a dict. I've written some helper methods that I have used for my use case, that could relatively easily be adapted to this use case:
https://gist.github.com/prschmid/801e86891026a39b1fb4df7178828321
Let me know if you have any questions, or if you would like this as a pull request.
Ideally this would be a to_json() method. Many elements in HL7 can repeat and thus would need to go into an array instead of a direct dictionary.