react-native-mytatva-rn-sdk 1.2.26 → 1.2.27

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.
@@ -130,20 +130,6 @@
130
130
  glucose.temperature = data.temperature;
131
131
  float algo_k = [[User_Defaults objectForKey:@"algo_k"] floatValue];
132
132
  float algo_r = [[User_Defaults objectForKey:@"algo_r"] floatValue];
133
-
134
- NSString *dateString = data.receiveDateTime;
135
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
136
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
137
- [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
138
- NSDate *date = [dateFormatter dateFromString:dateString];
139
- if (date) {
140
- NSTimeInterval timeMillis = [date timeIntervalSince1970] * 1000; // Convert to milliseconds
141
- NSLog(@"Milliseconds since epoch: %.0f", timeMillis);
142
- NSNumber *numberFromTimeMillis = [NSNumber numberWithDouble:timeMillis]; // Wrap the NSTimeInterval into an NSNumber
143
- } else {
144
- NSLog(@"Invalid date string format");
145
- }
146
-
147
133
 
148
134
  LatestData *d = nil;
149
135
  NSString *localName = data.device.advertise.localName;
@@ -151,24 +137,13 @@
151
137
  if (userBG > 0) {
152
138
  d = [[LatestData alloc] initWithParameters:glucose.dataId.intValue andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andNewBgToGlucoseId:glucose.dataId.intValue andNewBgValue:userBG andName:localName];
153
139
  } else {
154
- d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName ];
140
+ d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
155
141
  }
156
142
  d.algorithm = AlgorithmType_CT4;
157
-
158
-
159
-
160
- NSLog( @"sensorInfosensorInf %f", d.R);
161
-
162
- NSLog( @"sensorInfosensorInfosensorInfosensorInfo %@", d.sensorInfo);
163
-
164
- NSLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, algorithm=%@, year=%@, milles=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.algorithm), @(d.year), @(d.timeMillis));
165
-
166
-
167
-
168
143
 
144
+ KLTLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
169
145
  CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
170
146
 
171
-
172
147
  if (currentGlucose.errorCode == ERROR_CODE_ALGORITHM_DATA) {
173
148
  [self reloadQueryHistoryData];
174
149
 
@@ -178,35 +153,11 @@
178
153
  d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
179
154
  }
180
155
  d.algorithm = AlgorithmType_CT4;
181
-
182
156
 
183
- NSLog(@"ERROR_CODE_ALGORITHM_DATA:dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
157
+ KLTLog(@"ERROR_CODE_ALGORITHM_DATA:dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
184
158
  currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
185
-
186
- NSString *logString = [NSString stringWithFormat:@"glucoseId=%@, Iw=%@, Ib=%@, T=%@,dayCount=%@, hour=%@, minute=%@, milles=%@, GluMG=%@,BGCount=%@, BGICount=%@, errorCode=%@ trend=%@ calibrationStatus=%@, countdownDays=%@, countdownHours=%@, countdownMinutes=%@ ",
187
- @(d.glucoseId),
188
- @(d.Iw),
189
- @(d.Ib),
190
- @(d.T),
191
- @(d.day),
192
- @(d.hour),
193
- @(d.minute),
194
- @(d.timeMillis),
195
- @(currentGlucose.GluMG),
196
- @(currentGlucose.BGCount),
197
- @(currentGlucose.BGICount),
198
- @(currentGlucose.errorCode),
199
- @(currentGlucose.trend),
200
- @(currentGlucose.BGMG),
201
- @(currentGlucose.countdownDays),
202
- @(currentGlucose.countdownHours),
203
- @(currentGlucose.countdownHours)
204
-
205
- ];
206
-
207
159
  }
208
160
 
209
-
210
161
  glucose.errorCode = @(currentGlucose.errorCode);
211
162
  glucose.trend = @(currentGlucose.trend);
212
163
  /* glucose.glu 保存 ADC 算法结果 单位mmol */
@@ -221,29 +172,11 @@
221
172
  data.calibration = @(currentGlucose.BGMG);
222
173
  data.error = @(currentGlucose.errorCode);
223
174
  data.trend = @(currentGlucose.trend);
175
+ data.countdownDays = @(currentGlucose.countdownDays);
176
+ data.countdownHours = @(currentGlucose.countdownHours);
177
+ data.countdownMinutes = @(currentGlucose.countdownMinutes);
224
178
 
225
- NSString *logString = [NSString stringWithFormat:@"glucoseId=%@, Iw=%@, Ib=%@, T=%@,dayCount=%@, hour=%@, minute=%@, milles=%@, GluMG=%@,BGCount=%@, BGICount=%@, errorCode=%@ trend=%@ calibrationStatus=%@, countdownDays=%@, countdownHours=%@, countdownMinutes=%@ ",
226
- @(d.glucoseId),
227
- @(d.Iw),
228
- @(d.Ib),
229
- @(d.T),
230
- @(d.day),
231
- @(d.hour),
232
- @(d.minute),
233
- @(d.timeMillis),
234
- @(currentGlucose.GluMG),
235
- @(currentGlucose.BGCount),
236
- @(currentGlucose.BGICount),
237
- @(currentGlucose.errorCode),
238
- @(currentGlucose.trend),
239
- @(currentGlucose.BGMG),
240
- @(currentGlucose.countdownDays),
241
- @(currentGlucose.countdownHours),
242
- @(currentGlucose.countdownHours)
243
-
244
- ];
245
-
246
-
179
+ [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object:data];
247
180
  [self.appDelegate saveContext];
248
181
  return glucose;
249
182
  }
@@ -334,7 +267,7 @@
334
267
  NSFetchRequest *request = [[NSFetchRequest alloc] init];
335
268
  NSPredicate *predicate;
336
269
  if (needUserBG) {
337
- predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ && userBG > 0 && userBG != NIL AND isDelete == NIL",currentDevice.identifier, currentDevice.initialBeginDate];
270
+ predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ && gluADC > 0 && gluADC != NIL AND isDelete == NIL",currentDevice.identifier, currentDevice.initialBeginDate];
338
271
  } else {
339
272
  predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ AND isDelete == NIL",currentDevice.identifier, currentDevice.initialBeginDate];
340
273
  }
@@ -356,7 +289,7 @@
356
289
  allData = [allData sortedArrayUsingDescriptors:@[
357
290
  [NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]
358
291
  ]];
359
-
292
+
360
293
  return allData;
361
294
  }
362
295
 
@@ -463,7 +396,7 @@
463
396
  ReceiveData *receiveModel = needUserBgs[i];
464
397
  bgToGlucoseIds[i] = receiveModel.glucoseId.intValue;
465
398
  bgValues[i] = roundf(receiveModel.userBG.floatValue * 18);
466
- NSLog(@"newBgToGlucoseIds: bgToGlucoseIds=%@, userBG=%@", receiveModel.glucoseId, receiveModel.userBG);
399
+ KLTLog(@"newBgToGlucoseIds: bgToGlucoseIds=%@, userBG=%@", receiveModel.glucoseId, receiveModel.userBG);
467
400
  }
468
401
  data.newBgToGlucoseIds = bgToGlucoseIds;
469
402
  data.newBgToGlucoseIdsCount = (int)numberOfUserBgs;
@@ -478,7 +411,7 @@
478
411
  data.R = algo_r;
479
412
 
480
413
  CurrentGlucose *currentGlucose = [AlgorithmTools algorithmGlucose:data];
481
- NSLog(@"rerunADCAlgo: algorithm=%@, currentGlucose.errorCode = %@", @(data.algorithm), @(currentGlucose.errorCode));
414
+ KLTLog(@"rerunADCAlgo: algorithm=%@, currentGlucose.errorCode = %@", @(data.algorithm), @(currentGlucose.errorCode));
482
415
  if (Iws != nil) {
483
416
  free(Iws);
484
417
  Iws = nil;
@@ -230,7 +230,7 @@ class API {
230
230
 
231
231
  }
232
232
 
233
- func getStatus(encryptionKey: String = PROD_ENC_KEY,
233
+ /*func getStatus(encryptionKey: String = PROD_ENC_KEY,
234
234
  encryptionIv: String = PROD_ENC_IV) {
235
235
  print("ios token:", TOKEN)
236
236
  let url = URL(string: "https://api-feature2.mytatva.in/api/v8/cgm/status")!
@@ -289,7 +289,7 @@ class API {
289
289
  }
290
290
  task.resume()
291
291
 
292
- }
292
+ }*/
293
293
 
294
294
  // Example date range check function (assumes yyyy-MM-dd format)
295
295
  func isCurrentDateInRange(startDate: String, endDate: String) -> Bool {
@@ -17,7 +17,7 @@ import Foundation
17
17
  @objc public func callForObserveTransmitterUnbindStatus() {
18
18
  let sensorID = UserDefaults.standard.string(forKey: "sensorId") ?? ""
19
19
  if !sensorID.isEmpty {
20
- API.shared.getStatus()
20
+ viewModel.getStatus()
21
21
  }
22
22
  }
23
23
  }
@@ -43,15 +43,16 @@ class FinalViewModel: NSObject {
43
43
  }
44
44
 
45
45
  @objc public func initialize() {
46
-
46
+ //getStatus()
47
47
  startCountDown()
48
48
 
49
49
  if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
50
50
  manager.startScan()
51
+ debouncer.update(with: .disconnected)
51
52
  } else {
52
53
  print("here")
53
54
  //debouncer.update(with: .connected)
54
- //API.shared.sendStatus(status: .connected)
55
+ //API.shared.sendStatus(status: .connected) 计算 算法入参
55
56
  if let last = manager.currentDevice { }
56
57
  else {
57
58
  //self.manager.closeBleSensor()
@@ -61,6 +62,93 @@ class FinalViewModel: NSObject {
61
62
  }
62
63
  }
63
64
  }
65
+ func getStatus(encryptionKey: String = PROD_ENC_KEY,
66
+ encryptionIv: String = PROD_ENC_IV) {
67
+ print("ios token:", TOKEN)
68
+ let url = URL(string: "https://api-feature2.mytatva.in/api/v8/cgm/status")!
69
+ var request = URLRequest(url: url)
70
+ request.httpMethod = "GET"
71
+
72
+ // Set headers
73
+ //request.addValue("application/json", forHTTPHeaderField: "Content-Type")
74
+ request.addValue(PROD_API_KEY, forHTTPHeaderField: "api-key")
75
+ request.addValue(TOKEN, forHTTPHeaderField: "token")
76
+
77
+
78
+ // Set request body
79
+
80
+ // Perform request
81
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
82
+ if let error = error {
83
+ print("Error: \(error)")
84
+ return
85
+ }
86
+ guard let data = data else {
87
+ print("No data received")
88
+ return
89
+ }
90
+ if let responseString = String(data: data, encoding: .utf8) {
91
+ print("===>Server Response: \(responseString)")
92
+ if let decrypted = Crypto.shared.getDecryptedData(cipherText: responseString, encryptionKey: encryptionKey, encryptionIv: encryptionIv) {
93
+ print("===>Decrypted response (for verification): \(decrypted)")
94
+
95
+ if let decrptedData = decrypted.data(using: .utf8) {
96
+ let decoded = try? JSONDecoder().decode(CGMStatusResponse.self, from: decrptedData)
97
+
98
+ guard let sensor = decoded?.data.first,
99
+ !sensor.startDate.isEmpty,
100
+ !sensor.endDate.isEmpty else {
101
+ print("No valid sensor data")
102
+ return
103
+ }
104
+
105
+ let startDateStr = sensor.startDate
106
+ let endDateStr = sensor.endDate
107
+
108
+ print("Start Date: \(startDateStr)")
109
+ print("End Date: \(endDateStr)")
110
+ UserDefaults.standard.set(sensor.sensorId, forKey: "sensorId")
111
+ if self.isCurrentDateInRange(startDate: startDateStr, endDate: endDateStr) {
112
+ print("Current date is in range")
113
+ if ((self.manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
114
+ self.manager.startScan()
115
+ self.debouncer.update(with: .disconnected)
116
+ } else {
117
+ print("here")
118
+ //debouncer.update(with: .connected)
119
+ //API.shared.sendStatus(status: .connected) 计算 算法入参
120
+ if let last = self.manager.currentDevice { }
121
+ else {
122
+ //self.manager.closeBleSensor()
123
+ //manager.startScan()
124
+ //self.debouncer.update(with: .disconnected)
125
+ //debouncer.update(with: .transmitterDisconnectBox)
126
+ }
127
+ }
128
+ // if KLTBluetoothManager.shared().currentDevice.initialEndDate != nil {
129
+ // self.sendStatus(status: .transmitterDisconnect)
130
+ // }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ task.resume()
137
+
138
+ }
139
+
140
+ func isCurrentDateInRange(startDate: String, endDate: String) -> Bool {
141
+ let formatter = DateFormatter()
142
+ formatter.dateFormat = "yyyy-MM-dd"
143
+ guard let start = formatter.date(from: startDate),
144
+ let end = formatter.date(from: endDate) else {
145
+ return false
146
+ }
147
+
148
+ let now = Date()
149
+ return (now >= start) && (now <= end)
150
+ }
151
+
64
152
  func startCountDown() {
65
153
 
66
154
  // Most recently connected device
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mytatva-rn-sdk",
3
- "version": "1.2.26",
3
+ "version": "1.2.27",
4
4
  "description": "a package to inject data into visit health pwa",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",