Skip to content

Commit

Permalink
fix: Apply Date Range to Advanced Query Result (#74)
Browse files Browse the repository at this point in the history
Apply Date Range when processing Advanced Query Result, in order to avoid fetching data blocks that don't belong to the requested dates. On the bridge, it is only needed an update to the OSHealthFitnessLib and the OSHealthFitness file.
  • Loading branch information
OS-ricardomoreirasilva authored Jul 25, 2022
1 parent f6a2958 commit c1c96ae
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 145 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The changes documented here do not include those from the original repository.

## [Version 1.2.7]

- Fix: Apply Date Range filter while processing Advanced Query Results, so that data blocks that don't belong to the requested dates can be omitted (https://outsystemsrd.atlassian.net/browse/RMET-1718).

## [Version 1.2.6]

- Feat: Implemented option to return only filled blocks in the advanced query. (https://outsystemsrd.atlassian.net/browse/RMET-1714)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.outsystems.plugins.healthfitness",
"version": "1.2.6",
"version": "1.2.7",
"description": "Health & Fitness cordova plugin for OutSystems applications.",
"keywords": [
"ecosystem:cordova",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin id="com.outsystems.plugins.healthfitness" version="1.2.6" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="com.outsystems.plugins.healthfitness" version="1.2.7" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>HealthFitness</name>
<description>Health &amp; Fitness cordova plugin for OutSystems applications.</description>
<author>OutSystems Inc</author>
Expand Down
167 changes: 71 additions & 96 deletions src/ios/OSHealthFitness.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import OSHealthFitnessLib

@objc(OSHealthFitness)
Expand All @@ -12,29 +11,20 @@ class OSHealthFitness: CordovaImplementation {

@objc(requestPermissions:)
func requestPermissions(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId

let customPermissions = command.arguments[0] as? String ?? ""
let allVariables = command.arguments[1] as? String ?? ""
let fitnessVariables = command.arguments[2] as? String ?? ""
let healthVariables = command.arguments[3] as? String ?? ""
let profileVariables = command.arguments[4] as? String ?? ""
let summaryVariables = command.arguments[5] as? String ?? ""
let variable = VariableStruct(allVariables: allVariables, fitnessVariables: fitnessVariables, healthVariables: healthVariables, profileVariables: profileVariables, summaryVariables: summaryVariables)

plugin?.requestPermissions(customPermissions:customPermissions,
allVariables:allVariables,
fitnessVariables:fitnessVariables,
healthVariables:healthVariables,
profileVariables:profileVariables,
summaryVariables:summaryVariables) { [self] (authorized, error) in
self.plugin?.requestPermissions(customPermissions:customPermissions, variable: variable) { [weak self] authorized, error in
guard let self = self else { return }

if let err = error {
self.sendResult(result: "", error:err , callBackID: self.callbackId)
}

if authorized {
self.sendResult(result: "", error: nil, callBackID: self.callbackId)
}
self.sendResult(result: "", error: !authorized ? error : nil, callBackID: self.callbackId)
}
}

Expand Down Expand Up @@ -62,29 +52,22 @@ class OSHealthFitness: CordovaImplementation {

@objc(updateBackgroundJob:)
func updateBackgroundJob(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId

let queryParameters = command.arguments[0] as? String ?? ""
if let parameters = parseUpdateParameters(parameters: queryParameters) {

plugin?.updateBackgroundJob(id: parameters.id,
notificationFrequency: parameters.notificationFrequency,
notificationFrequencyGrouping: parameters.notificationFrequencyGrouping,
condition: parameters.condition,
value: parameters.value,
notificationHeader: parameters.notificationHeader,
notificationBody: parameters.notificationBody,
isActive: parameters.isActive)
{ success, error in
if let parameters = self.parseUpdateParameters(parameters: queryParameters) {
self.plugin?.updateBackgroundJob(
id: parameters.id,
notificationFrequency: (parameters.notificationFrequency, parameters.notificationFrequencyGrouping),
condition: parameters.condition,
value: parameters.value,
notificationText: (parameters.notificationHeader, parameters.notificationBody),
isActive: parameters.isActive
) { [weak self] success, error in
guard let self = self else { return }

if error != nil {
self.sendResult(result: "", error: error, callBackID: self.callbackId)
}
else if success {
self.sendResult(result: "", error: nil, callBackID: self.callbackId)
}
self.sendResult(result: "", error: !success ? error : nil, callBackID: self.callbackId)
}

}
}

Expand Down Expand Up @@ -125,58 +108,54 @@ class OSHealthFitness: CordovaImplementation {

@objc(getLastRecord:)
func getLastRecord(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId
let variable = command.arguments[0] as? String ?? ""

plugin?.advancedQuery(variable: variable,
startDate: Date.distantPast,
endDate: Date(),
timeUnit: "",
operationType: "MOST_RECENT",
mostRecent:true,
onlyFilledBlocks: false,
timeUnitLength: 1) { success, result, error in
self.plugin?.advancedQuery(
variable: variable,
date: (Date.distantPast, Date()),
timeUnit: "",
operationType: "MOST_RECENT",
mostRecent: true,
onlyFilledBlocks: false,
timeUnitLength: 1
) { [weak self] success, result, error in
guard let self = self else { return }

if error != nil {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
} else if success {
if success {
self.sendResult(result: result, error: nil, callBackID: self.callbackId)
} else {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
}
}

}

@objc(deleteBackgroundJob:)
func deleteBackgroundJob(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId
let id = command.arguments[0] as? String ?? ""
plugin?.deleteBackgroundJobs(id: id) { success, error in
if error != nil {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
} else if success {
self.sendResult(result: "", error: nil, callBackID: self.callbackId)
}

self.plugin?.deleteBackgroundJobs(id: id) { [weak self] error in
guard let self = self else { return }

self.sendResult(result: error == nil ? "" : nil, error: error, callBackID: self.callbackId)
}
}

@objc(listBackgroundJobs:)
func listBackgroundJobs(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
plugin?.listBackgroundJobs() { success, result, error in
if error != nil {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
} else if success {
self.sendResult(result: result, error: nil, callBackID: self.callbackId)
}
}
self.callbackId = command.callbackId

let result = self.plugin?.listBackgroundJobs()
self.sendResult(result: result, error: nil, callBackID: self.callbackId)
}

@objc(setBackgroundJob:)
func setBackgroundJob(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId

let queryParameters = command.arguments[0] as? String ?? ""
if let params = queryParameters.decode(string: queryParameters) as BackgroundJobParameters? {
if let params = queryParameters.decode() as BackgroundJobParameters? {

let variable = params.variable ?? ""
let timeUnitGrouping = params.timeUnitGrouping ?? 0
Expand All @@ -189,34 +168,32 @@ class OSHealthFitness: CordovaImplementation {
let notificationHeader = params.notificationHeader ?? ""
let notificationBody = params.notificationBody ?? ""

plugin?.setBackgroundJob(variable: variable,
timeUnit: timeUnit,
timeUnitGrouping: timeUnitGrouping,
notificationFrequency: notificationFrequency,
notificationFrequencyGrouping: notificationFrequencyGrouping,
jobFrequency: jobFrequency,
condition: condition,
value: value,
notificationHeader: notificationHeader,
notificationBody: notificationBody)
{ success, result, error in
self.plugin?.setBackgroundJob(
variable: variable,
timeUnit: (timeUnit, timeUnitGrouping),
notificationFrequency: (notificationFrequency, notificationFrequencyGrouping),
jobFrequency: jobFrequency,
condition: condition,
value: value,
notificationText: (notificationHeader, notificationBody)
) { [weak self] success, result, error in
guard let self = self else { return }

if error != nil {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
}
else if success {
if success {
self.sendResult(result: result, error: nil, callBackID: self.callbackId)
} else {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
}
}
}
}

@objc(getData:)
func getData(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId
self.callbackId = command.callbackId

let queryParameters = command.arguments[0] as? String ?? ""
if let params = queryParameters.decode(string: queryParameters) as QueryParameters? {
if let params = queryParameters.decode() as QueryParameters? {

let variable = params.variable ?? ""
let startDate = params.startDate ?? ""
Expand All @@ -226,25 +203,23 @@ class OSHealthFitness: CordovaImplementation {
let timeUnitLength = params.timeUnitLength ?? 1
let onlyFilledBlocks = params.advancedQueryReturnType == AdvancedQueryReturnTypeEnum.removeEmptyDataBlocks.rawValue

plugin?.advancedQuery(variable: variable,
startDate: Date(startDate),
endDate: Date(endDate),
timeUnit: timeUnit,
operationType: operationType,
mostRecent: false,
onlyFilledBlocks: onlyFilledBlocks,
timeUnitLength: timeUnitLength) { success, result, error in
self.plugin?.advancedQuery(
variable: variable,
date: (Date(startDate), Date(endDate)),
timeUnit: timeUnit,
operationType: operationType,
mostRecent: false,
onlyFilledBlocks: onlyFilledBlocks,
timeUnitLength: timeUnitLength
) { [weak self] success, result, error in
guard let self = self else { return }

if error != nil {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
}
else if success {
if success {
self.sendResult(result: result, error: nil, callBackID: self.callbackId)
} else {
self.sendResult(result: nil, error: error, callBackID: self.callbackId)
}
}

}

}

}
10 changes: 5 additions & 5 deletions src/ios/frameworks/OSHealthFitnessLib.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>OSHealthFitnessLib.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>OSHealthFitnessLib.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
// swift-module-flags: -target arm64-apple-ios12.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name OSHealthFitnessLib
import BackgroundTasks
import CloudKit
import CoreData
import Foundation
import HealthKit
import NotificationCenter
@_exported import OSHealthFitnessLib
import Swift
import UIKit
import UserNotifications
import UserNotificationsUI
import _Concurrency
public enum HealthKitErrors : Swift.Int, Foundation.CustomNSError, Foundation.LocalizedError {
case variableNotAvailable
Expand Down Expand Up @@ -40,27 +37,32 @@ public enum HealthKitErrors : Swift.Int, Foundation.CustomNSError, Foundation.Lo
}
}
extension Swift.String {
public func decode<T>(string: Swift.String) -> T where T : Swift.Decodable
public func decode<T>() -> T? where T : Swift.Decodable
}
extension Swift.Encodable {
public func encode() -> Swift.String
}
public struct VariableStruct {
public init(allVariables: Swift.String, fitnessVariables: Swift.String, healthVariables: Swift.String, profileVariables: Swift.String, summaryVariables: Swift.String)
}
open class HealthFitnessPlugin {
public init()
public func deleteBackgroundJobs(id: Swift.String?, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func deleteBackgroundJobs(id: Swift.String?, completion: @escaping (Foundation.NSError?) -> Swift.Void)
public func countBackgroundJobsFor(variable: Swift.String) -> Swift.Int
public func listBackgroundJobs(completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
public func listBackgroundJobs() -> Swift.String
public func writeData(variable: Swift.String, value: Swift.Double, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func getLastRecord(variable: Swift.String, mostRecent: Swift.Bool, timeUnitLength: Swift.Int, completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
public func requestPermissions(customPermissions: Swift.String, allVariables: Swift.String, fitnessVariables: Swift.String, healthVariables: Swift.String, profileVariables: Swift.String, summaryVariables: Swift.String, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func setBackgroundJob(variable: Swift.String, timeUnit: Swift.String, timeUnitGrouping: Swift.Int, notificationFrequency: Swift.String, notificationFrequencyGrouping: Swift.Int, jobFrequency: Swift.String, condition: Swift.String, value: Swift.Double, notificationHeader: Swift.String, notificationBody: Swift.String, completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
public func updateBackgroundJob(id: Swift.Int64?, notificationFrequency: Swift.String?, notificationFrequencyGrouping: Swift.Int?, condition: Swift.String?, value: Swift.Double?, notificationHeader: Swift.String?, notificationBody: Swift.String?, isActive: Swift.Bool?, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func advancedQuery(variable: Swift.String, startDate: Foundation.Date, endDate: Foundation.Date, timeUnit: Swift.String, operationType: Swift.String, mostRecent: Swift.Bool, onlyFilledBlocks: Swift.Bool, timeUnitLength: Swift.Int, completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
public func requestPermissions(customPermissions: Swift.String, variable: OSHealthFitnessLib.VariableStruct, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func setBackgroundJob(variable: Swift.String, timeUnit: (name: Swift.String, grouping: Swift.Int), notificationFrequency: (name: Swift.String, grouping: Swift.Int), jobFrequency: Swift.String, condition: Swift.String, value: Swift.Double, notificationText: (header: Swift.String, body: Swift.String), completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
public func updateBackgroundJob(id: Swift.Int64?, notificationFrequency: (name: Swift.String?, grouping: Swift.Int?), condition: Swift.String?, value: Swift.Double?, notificationText: (header: Swift.String?, body: Swift.String?), isActive: Swift.Bool?, completion: @escaping (Swift.Bool, Foundation.NSError?) -> Swift.Void)
public func advancedQuery(variable: Swift.String, date: (start: Foundation.Date, end: Foundation.Date), timeUnit: Swift.String, operationType: Swift.String, mostRecent: Swift.Bool, onlyFilledBlocks: Swift.Bool, timeUnitLength: Swift.Int, completion: @escaping (Swift.Bool, Swift.String?, Foundation.NSError?) -> Swift.Void)
@objc deinit
}
extension Foundation.Date {
public struct ResultStruct {
}
public init(_ dateString: Swift.String)
public static func - (recent: Foundation.Date, previous: Foundation.Date) -> (year: Swift.Int?, month: Swift.Int?, week: Swift.Int?, day: Swift.Int?, hour: Swift.Int?, minute: Swift.Int?, second: Swift.Int?)
public static func - (recent: Foundation.Date, previous: Foundation.Date) -> Foundation.Date.ResultStruct
public func startOfHour() -> Foundation.Date
public func startOfDay() -> Foundation.Date
public func startOfWeek() -> Foundation.Date
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit c1c96ae

Please sign in to comment.