capacitor-plugin-healthapp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for Plugin.
4
+ FOUNDATION_EXPORT double PluginVersionNumber;
5
+
6
+ //! Project version string for Plugin.
7
+ FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
+
@@ -0,0 +1,11 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(HealthAppPlugin, "HealthApp",
7
+ CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(autheriseHealthApp, CAPPluginReturnPromise);
9
+ CAP_PLUGIN_METHOD(getHealthKitData, CAPPluginReturnPromise);
10
+ CAP_PLUGIN_METHOD(getIndividualHealthKitData, CAPPluginReturnPromise);
11
+ )
@@ -0,0 +1,156 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(HealthAppPlugin)
9
+ public class HealthAppPlugin: CAPPlugin {
10
+ private let HealthManager = HealthApp()
11
+
12
+ // @objc func echo(_ call: CAPPluginCall) {
13
+ // let value = call.getString("value") ?? ""
14
+ // call.resolve([
15
+ // "value": implementation.echo(value)
16
+ // ])
17
+ // }
18
+ @objc func autheriseHealthApp(_ call: CAPPluginCall) {
19
+ if(HealthManager.isHealthAvailable()) {
20
+ HealthManager.authorizeHealthKit({ (success) -> Void in
21
+ call.resolve(["value":"Successfully authenticated Health app to this account.if you would like to change data permissions please go to Health app->profile->Apps->ManageMyHealth and then modify data permissions."])
22
+ }, FailureCompletion: { (err) -> Void in
23
+ call.resolve(["value":"Error while authenticating to Health please try again."])
24
+ })
25
+ } else {
26
+ call.resolve(["value":"Health app not available"])
27
+ }
28
+ }
29
+ @objc func getHealthKitData(_ call: CAPPluginCall) {
30
+ let value = call.getString("value") ?? ""
31
+
32
+ let dict = value.toJSON() as? [String:AnyObject]
33
+ let startDate = dict?["startDate"] as! String
34
+ let endDate = dict?["endDate"] as! String
35
+ //let isFirstCall = dict?["isFirstCall"] as! Bool
36
+
37
+ if(HealthManager.isHealthAvailable()) {
38
+ HealthManager.authorizeHealthKit({ (success) -> Void in
39
+ DispatchQueue.global(qos: .background).sync {
40
+ self.HealthManager.getHealthDataValuesFor(strStartDate: startDate, strEndDate: endDate) { (healthValues) in
41
+ call.resolve(["value": ["healthKitData": healthValues]])
42
+
43
+ // self.HealthManager.getHealthValuesUsingAnchorQuery(isFirstCall: isFirstCall) { (healthValues) in
44
+ // //Return healthValues to Capacitor APP
45
+ // call.resolve(["value": ["healthKitData": healthValues]])
46
+ // print("Health app data \(healthValues)")
47
+ }
48
+ }
49
+ }, FailureCompletion: { (err) -> Void in
50
+ print("Health app FailureCompletion \(err)")
51
+ call.resolve(["value":"Error while authenticating to Health App. please try again."])
52
+ })
53
+ } else {
54
+ //HealthKit NOT AVAILABLE
55
+ call.resolve(["value":"Health app not available"])
56
+ }
57
+ }
58
+ @objc func getIndividualHealthKitData(_ call: CAPPluginCall) {
59
+ let value = call.getString("value") ?? ""
60
+
61
+ let dict = value.toJSON() as? [String:AnyObject]
62
+ let startDate = dict?["startDate"] as! String
63
+ let endDate = dict?["endDate"] as! String
64
+ let quantity = dict?["quantityType"] as! String
65
+
66
+ if(HealthManager.isHealthAvailable()) {
67
+ DispatchQueue.global(qos: .background).sync {
68
+ var quantityType:String?
69
+ switch quantity {
70
+ case "Blood Pressure":
71
+ quantityType = "BloodPressureDiastolic"
72
+ break
73
+ case "Respiratory Rate":
74
+ quantityType = "RespiratoryRate"
75
+ break
76
+ case "Blood Oxygen":
77
+ quantityType = "OxygenSaturation"
78
+ break
79
+ case "Height":
80
+ quantityType = "Height"
81
+ break
82
+ case "Heart Rate":
83
+ quantityType = "HeartRate"
84
+ break
85
+ case "Body Temperature":
86
+ quantityType = "BodyTemperature"
87
+ break
88
+ case "Body Mass Index":
89
+ quantityType = "BodyMassIndex"
90
+ break
91
+ case "Weight":
92
+ quantityType = "BodyMass"
93
+ break
94
+ case "Blood Glucose":
95
+ quantityType = "BloodGlucose"
96
+ break
97
+ case "Blood Alcohol Content":
98
+ quantityType = "BloodAlcoholContent"
99
+ break
100
+ case "Alcohol Consumption":
101
+ quantityType = "NumberOfAlcoholicBeverages"
102
+ break
103
+
104
+ default:
105
+ break
106
+ }
107
+ if let type = quantityType{
108
+ if(type == "BloodPressureDiastolic"){
109
+ var data = []
110
+ self.HealthManager.getindividualHealthAppValues(quantityType: "BloodPressureDiastolic", strStartDate: startDate, strEndDate: endDate) { (healthValues) in
111
+ //call.resolve(["value": ["healthKitData": healthValues]])
112
+ if(healthValues.count > 0){
113
+ data.append(healthValues[0])
114
+ }
115
+ if(data.count == 2){
116
+ call.resolve(["value": ["healthKitData": data]])
117
+ }
118
+
119
+ }
120
+ self.HealthManager.getindividualHealthAppValues(quantityType: "BloodPressureSystolic", strStartDate: startDate, strEndDate: endDate) { (healthValues) in
121
+ //call.resolve(["value": ["healthKitData": healthValues]])
122
+ print("BloodPressureSystolic \(healthValues)")
123
+ if(healthValues.count > 0){
124
+ data.append(healthValues[0])
125
+ }
126
+ if(data.count == 2){
127
+ call.resolve(["value": ["healthKitData": data]])
128
+ }
129
+
130
+ }
131
+ }else{
132
+ self.HealthManager.getindividualHealthAppValues(quantityType: type, strStartDate: startDate, strEndDate: endDate) { (healthValues) in
133
+ //call.resolve(["value": ["healthKitData": healthValues]])
134
+ call.resolve(["value": ["healthKitData": healthValues]])
135
+ }
136
+ }
137
+
138
+ }
139
+
140
+ }
141
+ // HealthManager.authorizeHealthKit({ (success) -> Void in
142
+ // DispatchQueue.global(qos: .background).sync {
143
+ // self.HealthManager.getSumquantityHealthValues(quantityType: quantityType, strStartDate: startDate, strEndDate: endDate) { (healthValues) in
144
+ // call.resolve(["value": ["healthKitData": healthValues]])
145
+ // }
146
+ // }
147
+ // }, FailureCompletion: { (err) -> Void in
148
+ // print("Health app FailureCompletion \(err)")
149
+ // })
150
+ } else {
151
+ //HealthKit NOT AVAILABLE
152
+ print("Health app not available")
153
+ call.resolve(["value": ["healthKitData": "No data"]])
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "capacitor-plugin-healthapp",
3
+ "version": "0.0.1",
4
+ "description": "capacitor plugin for healthapp",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Plugin/",
14
+ "CapacitorPluginHealthapp.podspec"
15
+ ],
16
+ "author": "",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/vamsi3293/capacitor-plugin-healthapp.git.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/vamsi3293/capacitor-plugin-healthapp.git/issues"
24
+ },
25
+ "keywords": [
26
+ "capacitor",
27
+ "plugin",
28
+ "native"
29
+ ],
30
+ "scripts": {
31
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
33
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
+ "verify:web": "npm run build",
35
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
+ "eslint": "eslint . --ext ts",
38
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
39
+ "swiftlint": "node-swiftlint",
40
+ "docgen": "docgen --api HealthAppPlugin --output-readme README.md --output-json dist/docs.json",
41
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
42
+ "clean": "rimraf ./dist",
43
+ "watch": "tsc --watch",
44
+ "prepublishOnly": "npm run build"
45
+ },
46
+ "devDependencies": {
47
+ "@capacitor/android": "^5.0.0",
48
+ "@capacitor/core": "^5.0.0",
49
+ "@capacitor/docgen": "^0.0.18",
50
+ "@capacitor/ios": "^5.0.0",
51
+ "@ionic/eslint-config": "^0.3.0",
52
+ "@ionic/prettier-config": "^1.0.1",
53
+ "@ionic/swiftlint-config": "^1.1.2",
54
+ "eslint": "^7.11.0",
55
+ "prettier": "~2.3.0",
56
+ "prettier-plugin-java": "~1.0.2",
57
+ "rimraf": "^3.0.2",
58
+ "rollup": "^2.32.0",
59
+ "swiftlint": "^1.0.1",
60
+ "typescript": "~4.1.5"
61
+ },
62
+ "peerDependencies": {
63
+ "@capacitor/core": "^5.0.0"
64
+ },
65
+ "prettier": "@ionic/prettier-config",
66
+ "swiftlint": "@ionic/swiftlint-config",
67
+ "eslintConfig": {
68
+ "extends": "@ionic/eslint-config/recommended"
69
+ },
70
+ "capacitor": {
71
+ "ios": {
72
+ "src": "ios"
73
+ },
74
+ "android": {
75
+ "src": "android"
76
+ }
77
+ }
78
+ }