• Re: Tool to parse Apple Health data

    From Chris@21:1/5 to badgolferman on Tue Nov 15 19:16:50 2022
    XPost: uk.comp.sys.mac

    badgolferman <REMOVETHISbadgolferman@gmail.com> wrote:
    Chris wrote:


    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file. Are their any offline tools for reading
    the file and export to a more sensible format? I could write my own,
    but I can't be the only one who wants to do this. Had a google and
    couldn't find anything obvious.

    I've seen the HealthView app and others but they either don't do what
    I want or cost quite a lot of money to just export the data. Hence
    the request for an offline tool.

    Thanks!

    I think Microsoft Edge is able to display XML in a way which is human readble.

    Firefox can too, but not this file.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris@21:1/5 to Jolly Roger on Tue Nov 15 19:29:36 2022
    XPost: uk.comp.sys.mac

    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a more
    sensible format? I could write my own, but I can't be the only one who
    wants to do this. Had a google and couldn't find anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem to
    parse the XML, and it was relatively easy to grab the records I wanted.
    The relevant methods are:

    ---
    def parse_apple_health_xml_file(filepath)
    document = nil

    contents = IO.read(filepath, chomp: false)
    begin
    document = Nokogiri::XML(contents)
    rescue StandardError => exception
    puts "ERROR: Could not parse #{filename} due to exception: #{exception.message}"
    end

    document
    end

    def get_blood_pressure_records(document)
    records = Array.new

    nodes = document.xpath("//HealthData/Record[contains(@type,'BloodPressure')]")
    nodes.each_with_index do |node, index|
    type = node['type'][/HKQuantityTypeIdentifierBloodPressure(Diastolic|Systolic)/, 1]
    unit = node['unit']
    date = node['creationDate']
    value = node['value']

    existing_record = records.select {|r| r[:date] == date}.first
    if existing_record.nil?
    record = {:date => date, :unit => unit, type.downcase.to_sym => value}
    records << record
    else
    existing_record[type.downcase.to_sym] = value
    end
    end

    records.sort_by!{|r| r[:date]}
    end
    ---

    The resulting records array of hashes look like this:

    ---
    [
    ...
    [44] {
    :date => "2022-09-07 09:15:40 -0700",
    :unit => "mmHg",
    :systolic => "120",
    :diastolic => "88"
    },
    [45] {
    :date => "2022-09-08 10:31:27 -0700",
    :unit => "mmHg",
    :systolic => "129",
    :diastolic => "87"
    },
    [46] {
    :date => "2022-09-09 10:01:00 -0700",
    :unit => "mmHg",
    :systolic => "122",
    :diastolic => "86"
    }
    ]
    ---

    So you can print out:

    ---
    2022-09-07 09:15:40 -0700: S: 120 mmHg D: 88 mmHg
    2022-09-08 10:31:27 -0700: S: 129 mmHg D: 87 mmHg
    2022-09-09 10:01:00 -0700: S: 122 mmHg D: 86 mmHg
    ---

    Pretty simple, really. Just change the XPath to get whatever you want,
    and collect the information in a records array that suits your needs.


    Thanks. That's really useful. Should be able to get a python script to do something similar. I just don't have the time at the moment and need to
    drop off my bp readings at the GP.

    This should be easier than having to write your own code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jolly Roger@21:1/5 to Chris on Tue Nov 15 20:45:15 2022
    XPost: uk.comp.sys.mac

    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a more
    sensible format? I could write my own, but I can't be the only one who
    wants to do this. Had a google and couldn't find anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem to
    parse the XML, and it was relatively easy to grab the records I wanted.
    The relevant methods are:

    (snip)

    Pretty simple, really. Just change the XPath to get whatever you want,
    and collect the information in a records array that suits your needs.


    Thanks. That's really useful. Should be able to get a python script to do something similar. I just don't have the time at the moment and need to
    drop off my bp readings at the GP.

    This should be easier than having to write your own code.

    I suppose there's a small opportunity for someone to create an app to
    parse the data and export it as CSV/whatever. I'm just not sure how many
    people would be willing to purchase it.

    --
    E-mail sent to this address may be devoured by my ravenous SPAM filter.
    I often ignore posts from Google. Use a real news client instead.

    JR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jolly Roger@21:1/5 to Chris on Tue Nov 15 20:43:15 2022
    XPost: uk.comp.sys.mac

    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    badgolferman <REMOVETHISbadgolferman@gmail.com> wrote:
    Chris wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file. Are their any offline tools for reading
    the file and export to a more sensible format? I could write my own,
    but I can't be the only one who wants to do this. Had a google and
    couldn't find anything obvious.

    I've seen the HealthView app and others but they either don't do what
    I want or cost quite a lot of money to just export the data. Hence
    the request for an offline tool.

    Thanks!

    I think Microsoft Edge is able to display XML in a way which is human
    readble.

    Firefox can too, but not this file.

    Probably due to its size. The file is rather huge uncompressed.

    --
    E-mail sent to this address may be devoured by my ravenous SPAM filter.
    I often ignore posts from Google. Use a real news client instead.

    JR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jolly Roger@21:1/5 to Chris on Tue Nov 15 23:13:43 2022
    XPost: uk.comp.sys.mac

    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    On 15/11/2022 20:45, Jolly Roger wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a
    more sensible format? I could write my own, but I can't be the
    only one who wants to do this. Had a google and couldn't find
    anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem
    to parse the XML, and it was relatively easy to grab the records I
    wanted. The relevant methods are:

    (snip)

    Pretty simple, really. Just change the XPath to get whatever you
    want, and collect the information in a records array that suits
    your needs.


    Thanks. That's really useful. Should be able to get a python script
    to do something similar. I just don't have the time at the moment
    and need to drop off my bp readings at the GP.

    This should be easier than having to write your own code.

    I suppose there's a small opportunity for someone to create an app to
    parse the data and export it as CSV/whatever. I'm just not sure how
    many people would be willing to purchase it.

    It doesn't have to be an app. I'm more than happy with some code on
    github. As I'm sure many others would be.

    Have you looked? I just did a search on GitHub for "apple health" and
    see a few hits.

    --
    E-mail sent to this address may be devoured by my ravenous SPAM filter.
    I often ignore posts from Google. Use a real news client instead.

    JR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jolly Roger@21:1/5 to Chris on Tue Nov 15 22:55:27 2022
    XPost: uk.comp.sys.mac

    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I just don't have the time at the moment and need to drop off my bp
    readings at the GP.

    This should be easier than having to write your own code.

    You may be able to share your data with your GP this way instead:

    <https://support.apple.com/en-us/HT213359>

    --
    E-mail sent to this address may be devoured by my ravenous SPAM filter.
    I often ignore posts from Google. Use a real news client instead.

    JR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris@21:1/5 to Jolly Roger on Tue Nov 15 23:00:28 2022
    XPost: uk.comp.sys.mac

    On 15/11/2022 22:55, Jolly Roger wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I just don't have the time at the moment and need to drop off my bp
    readings at the GP.

    This should be easier than having to write your own code.

    You may be able to share your data with your GP this way instead:

    <https://support.apple.com/en-us/HT213359>

    The digital capabilities of frontline NHS services are chronically
    out-of-date. No chance my GP is equipped to accept the data.

    However, sharing requires iCloud which I haven't enabled.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris@21:1/5 to Jolly Roger on Tue Nov 15 22:46:33 2022
    XPost: uk.comp.sys.mac

    On 15/11/2022 20:45, Jolly Roger wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a more
    sensible format? I could write my own, but I can't be the only one who >>>> wants to do this. Had a google and couldn't find anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem to
    parse the XML, and it was relatively easy to grab the records I wanted.
    The relevant methods are:

    (snip)

    Pretty simple, really. Just change the XPath to get whatever you want,
    and collect the information in a records array that suits your needs.


    Thanks. That's really useful. Should be able to get a python script to do
    something similar. I just don't have the time at the moment and need to
    drop off my bp readings at the GP.

    This should be easier than having to write your own code.

    I suppose there's a small opportunity for someone to create an app to
    parse the data and export it as CSV/whatever. I'm just not sure how many people would be willing to purchase it.

    It doesn't have to be an app. I'm more than happy with some code on
    github. As I'm sure many others would be.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Bestley@21:1/5 to Jolly Roger on Tue Nov 15 23:27:39 2022
    XPost: uk.comp.sys.mac

    Jolly Roger <jollyroger@pobox.com> writes:

    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I just don't have the time at the moment and need to drop off my bp
    readings at the GP.

    This should be easier than having to write your own code.

    You may be able to share your data with your GP this way instead:

    <https://support.apple.com/en-us/HT213359>

    As stated on that page
    If you live in the United States, you can share your health data with participating healthcare providers

    So not use here.

    Also having found I can not access my medical records on the web but spread over 3 different places only one of which is from the nhs home page but the others do use the NHS authentication to login. And experience from Moorfields where I had a test and
    they did not know I had tests the previous month for something else as was on a different system. I don;t think the NHS could deal with it even if Apple allowed them.

    --
    Mark

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Bestley@21:1/5 to Chris on Tue Nov 15 23:22:22 2022
    XPost: uk.comp.sys.mac

    Chris <ithinkiam@gmail.com> writes:

    On 15/11/2022 20:45, Jolly Roger wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a more >>>>> sensible format? I could write my own, but I can't be the only one who >>>>> wants to do this. Had a google and couldn't find anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem to >>>> parse the XML, and it was relatively easy to grab the records I wanted. >>>> The relevant methods are:

    (snip)

    Pretty simple, really. Just change the XPath to get whatever you want, >>>> and collect the information in a records array that suits your needs.


    Thanks. That's really useful. Should be able to get a python script to do >>> something similar. I just don't have the time at the moment and need to
    drop off my bp readings at the GP.

    This should be easier than having to write your own code.
    I suppose there's a small opportunity for someone to create an app
    to
    parse the data and export it as CSV/whatever. I'm just not sure how many
    people would be willing to purchase it.

    It doesn't have to be an app. I'm more than happy with some code on
    github. As I'm sure many others would be.



    I am in the same state wanting to export data - the XMl is actually quite nice but I wanted step data and that is not per day so more complex.

    There used to be an app it still has permissions to read my health data but looking through my purchases I can't find it so I guess was 32-bit. It shows up as being called Access

    Searching in App Store I do see Health Export CSV for #2.49 plus in app purchases but mutters about a website and also as I can't see what the in-app purchases are for I won't try it. See <https://healthexport.app/>

    --
    Mark

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris@21:1/5 to Jolly Roger on Wed Nov 16 07:26:43 2022
    XPost: uk.comp.sys.mac

    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    On 15/11/2022 20:45, Jolly Roger wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:
    Jolly Roger <jollyroger@pobox.com> wrote:
    On 2022-11-15, Chris <ithinkiam@gmail.com> wrote:

    I've exported my health data from the Health App, but it's in a
    horribly mangled XML file.

    The XML isn't mangled - it's completely valid XML. ; )

    Are their any offline tools for reading the file and export to a
    more sensible format? I could write my own, but I can't be the
    only one who wants to do this. Had a google and couldn't find
    anything obvious.

    I did just that (wrote my own) earlier this year to grab my blood
    pressure records from it. I wrote it in Ruby using the nokogiri gem
    to parse the XML, and it was relatively easy to grab the records I
    wanted. The relevant methods are:

    (snip)

    Pretty simple, really. Just change the XPath to get whatever you
    want, and collect the information in a records array that suits
    your needs.


    Thanks. That's really useful. Should be able to get a python script
    to do something similar. I just don't have the time at the moment
    and need to drop off my bp readings at the GP.

    This should be easier than having to write your own code.

    I suppose there's a small opportunity for someone to create an app to
    parse the data and export it as CSV/whatever. I'm just not sure how
    many people would be willing to purchase it.

    It doesn't have to be an app. I'm more than happy with some code on
    github. As I'm sure many others would be.

    Have you looked? I just did a search on GitHub for "apple health" and
    see a few hits.

    I did a google not specifically github.

    Anyway, I've written a very basic script to extract the data I need.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jeremy@21:1/5 to Jolly Roger on Wed Nov 16 08:53:27 2022
    XPost: uk.comp.sys.mac

    On 15 Nov 2022 at 17:56:57 GMT, "Jolly Roger" <jollyroger@pobox.com> wrote:

    I came across exactly this - I wanted to track my weight in a
    spreadsheet - had been adding it into the phone daily. The XML was
    quite horrible

    I'm not sure why you guys think anything is wrong with the XML. It's completely valid and easily parsed...

    Ok let's be clearer - no suggestion that the XML was not valid but was not in
    a format that could be easily (as far as I could see) into a typical end user app such as Excel - I wanted just two data items (date & weight - note that
    the data items don't always have to rhyme) and in the absence of knowledge of any other tools, took an approach that I knew I could make work (was only to
    be a one-off).


    --
    jeremy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jolly Roger@21:1/5 to jeremy on Wed Nov 16 14:40:37 2022
    XPost: uk.comp.sys.mac

    On 2022-11-16, jeremy <jeremy0505@gmail.com> wrote:
    On 15 Nov 2022 at 17:56:57 GMT, "Jolly Roger" <jollyroger@pobox.com> wrote:

    I came across exactly this - I wanted to track my weight in a
    spreadsheet - had been adding it into the phone daily. The XML was
    quite horrible

    I'm not sure why you guys think anything is wrong with the XML. It's
    completely valid and easily parsed...

    Ok let's be clearer - no suggestion that the XML was not valid but was
    not in a format that could be easily (as far as I could see) into a
    typical end user app such as Excel - I wanted just two data items
    (date & weight - note that the data items don't always have to rhyme)
    and in the absence of knowledge of any other tools, took an approach
    that I knew I could make work (was only to be a one-off).

    I get that, but I wouldn't put much faith in Excel being able to read or
    render every flavor of XML out there.

    --
    E-mail sent to this address may be devoured by my ravenous SPAM filter.
    I often ignore posts from Google. Use a real news client instead.

    JR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)