Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blood_pressure query ignores limit option on iOS #244

Open
rafaellop opened this issue Jan 19, 2022 · 6 comments
Open

blood_pressure query ignores limit option on iOS #244

rafaellop opened this issue Jan 19, 2022 · 6 comments

Comments

@rafaellop
Copy link

rafaellop commented Jan 19, 2022

I've got two measurements in the Health app. I call query on the health object and specify limit as 1 to get the latest record in the data range, but in the result I get two.

navigator.health.query({
          startDate: fromDate,
          endDate: new Date(),
          dataType: 'blood_pressure',
          limit: 1
        },
          function(dataread) {
              console.log(dataread);
            }
          },
          function(dataread) {
            console.log(err);
        });

In result two data objects:

{
  endDate: Mon Jan 17 2022 13:04:00 GMT+0100 (CET)
  id: "113AE760-1B1C-4574-B709-A1D0383031AA"
  sourceBundleId: "com.apple.Health"
  sourceName: "Health"
  startDate: Mon Jan 17 2022 13:04:00 GMT+0100 (CET)
  unit: "mmHG"
  value: {systolic: 127, diastolic: 77}
},
{
  endDate: Wed Jan 19 2022 11:53:26 GMT+0100 (CET)
  id: "6F676788-1FE1-4AC7-96AE-0D8348239010"
  sourceBundleId: "com.myapp"
  sourceName: "My App"
  startDate: Wed Jan 19 2022 11:52:56 GMT+0100 (CET)
  unit: "mmHG"
  value: {systolic: 120, diastolic: 78}
}

I've tried to fix the code in the www/ios./health.js line 269 where query specific options are created without the limit option and it to the options, but it's ignored in the platform sources I think.
https://github.com/dariosalvi78/cordova-plugin-health/blob/master/www/ios/health.js#L269

    var qops = { // query-specific options
      startDate: opts.startDate,
      endDate: opts.endDate,
      correlationType: dataTypes[opts.dataType],
      limit: opts.limit
    }

Any ideas?

@dariosalvi78
Copy link
Owner

query correlation type in the native code misses the limit argument.
I would be ideal to simply add it as done in the other query methods.

@dariosalvi78
Copy link
Owner

looks like it's not possible to limit correlation types:
https://developer.apple.com/documentation/healthkit/hkcorrelationquery/1614145-initwithtype?language=objc

we can enforce this in the JS code though

@rafaellop
Copy link
Author

It would be enough to query separately the systolic and diastolic datatypes and combine them into a result like the current blood_pressure returns. For the store function the current solutions works correctly. I can try but not very soon (busy with my app update).

@dariosalvi78
Copy link
Owner

yes, limiting the results is easy!
return array.slice(0, limit) 😉

@rafaellop
Copy link
Author

No, not this way. This would unnecessarily fetch big chunk of data each time for example if I would like to check the newest reading in last 30 days. I would rather stay with the current solution of querying separate datatypes .

@dariosalvi78
Copy link
Owner

we can do both... leave the separate BPs and also actually use the limit parameter with the ugly hack.
Anyway, I am also fine with just ignoring limit for this datatype.

@dariosalvi78 dariosalvi78 changed the title blood_pressure query ignores limit option blood_pressure query ignores limit option on iOS Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants