@tryvital/vital-node 2.1.2 → 2.1.5
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.
- package/client/Sleep.ts +15 -1
- package/client/lib/utils.ts +13 -0
- package/client/models/lab_tests_model.ts +1 -4
- package/client/models/sleep_models.ts +1 -1
- package/dist/client/Sleep.js +23 -5
- package/dist/client/lib/utils.d.ts +1 -0
- package/dist/client/lib/utils.js +8 -0
- package/dist/client/models/lab_tests_model.d.ts +1 -4
- package/dist/client/models/sleep_models.d.ts +1 -1
- package/package.json +2 -2
package/client/Sleep.ts
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
2
|
+
|
2
3
|
import {
|
3
4
|
ClientSleepResponse,
|
4
5
|
ClientSleepStreamResponse,
|
5
6
|
} from './models/sleep_models';
|
6
7
|
import { ClientSleepRawResponse } from './models/raw_response';
|
8
|
+
import { utils } from './lib/utils';
|
7
9
|
|
8
10
|
export class SleepApi {
|
9
11
|
baseURL: string;
|
10
12
|
client: AxiosInstance;
|
13
|
+
|
11
14
|
constructor(baseURL: string, axios: AxiosInstance) {
|
12
15
|
this.baseURL = baseURL;
|
13
16
|
this.client = axios;
|
@@ -35,12 +38,23 @@ export class SleepApi {
|
|
35
38
|
endDate?: Date,
|
36
39
|
provider?: string
|
37
40
|
): Promise<ClientSleepResponse> {
|
41
|
+
if (utils.getDayDiff(startDate, endDate) > 7) {
|
42
|
+
console.warn('WARNING: calling getSleepWithStream for more than 7 days can significantly increase the latency of the request. Please consider reducing the number of days requested.');
|
43
|
+
}
|
44
|
+
|
38
45
|
const resp = await this.client.get(
|
39
|
-
this.baseURL.concat(`/summary/sleep/${userId}
|
46
|
+
this.baseURL.concat(`/summary/sleep/${userId}`),
|
40
47
|
{
|
41
48
|
params: { start_date: startDate, end_date: endDate, provider },
|
42
49
|
}
|
43
50
|
);
|
51
|
+
|
52
|
+
let response = resp.data as ClientSleepResponse;
|
53
|
+
for (let i = 0; i < response.sleep.length; i++) {
|
54
|
+
const stream = await this.getStream(response.sleep[i].id);
|
55
|
+
response.sleep[i].sleep_stream = stream;
|
56
|
+
}
|
57
|
+
|
44
58
|
return resp.data;
|
45
59
|
}
|
46
60
|
|
package/client/lib/utils.ts
CHANGED
@@ -31,4 +31,17 @@ export const utils = {
|
|
31
31
|
}
|
32
32
|
return result === 0;
|
33
33
|
},
|
34
|
+
|
35
|
+
// Get the difference in days between two dates.
|
36
|
+
getDayDiff: (startDate: Date, endDate?: Date): number => {
|
37
|
+
if (!endDate) {
|
38
|
+
endDate = new Date();
|
39
|
+
}
|
40
|
+
|
41
|
+
const msInDay = 24 * 60 * 60 * 1000;
|
42
|
+
|
43
|
+
return Math.round(
|
44
|
+
Math.abs(endDate.getTime() - startDate.getTime()) / msInDay,
|
45
|
+
);
|
46
|
+
}
|
34
47
|
};
|
@@ -20,10 +20,6 @@ export interface Physician {
|
|
20
20
|
first_name: string;
|
21
21
|
last_name: string;
|
22
22
|
npi: string;
|
23
|
-
email?: string;
|
24
|
-
licensed_states?: string[];
|
25
|
-
created_at?: string;
|
26
|
-
updated_at?: string;
|
27
23
|
}
|
28
24
|
|
29
25
|
export interface Marker {
|
@@ -54,6 +50,7 @@ export interface Order {
|
|
54
50
|
team_id: string;
|
55
51
|
patient_details: PatientDetails;
|
56
52
|
patient_address: PatientAdress;
|
53
|
+
physician: Physician
|
57
54
|
lab_test: Testkit;
|
58
55
|
// TODO CHECK WHAT DETAILS IS
|
59
56
|
details: Object;
|
package/dist/client/Sleep.js
CHANGED
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
37
|
};
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
39
|
exports.SleepApi = void 0;
|
40
|
+
var utils_1 = require("./lib/utils");
|
40
41
|
var SleepApi = /** @class */ (function () {
|
41
42
|
function SleepApi(baseURL, axios) {
|
42
43
|
this.baseURL = baseURL;
|
@@ -60,15 +61,32 @@ var SleepApi = /** @class */ (function () {
|
|
60
61
|
};
|
61
62
|
SleepApi.prototype.getSleepWithStream = function (userId, startDate, endDate, provider) {
|
62
63
|
return __awaiter(this, void 0, void 0, function () {
|
63
|
-
var resp;
|
64
|
+
var resp, response, i, stream;
|
64
65
|
return __generator(this, function (_a) {
|
65
66
|
switch (_a.label) {
|
66
|
-
case 0:
|
67
|
-
|
68
|
-
|
67
|
+
case 0:
|
68
|
+
if (utils_1.utils.getDayDiff(startDate, endDate) > 7) {
|
69
|
+
console.warn('WARNING: calling getSleepWithStream for more than 7 days can significantly increase the latency of the request. Please consider reducing the number of days requested.');
|
70
|
+
}
|
71
|
+
return [4 /*yield*/, this.client.get(this.baseURL.concat("/summary/sleep/" + userId), {
|
72
|
+
params: { start_date: startDate, end_date: endDate, provider: provider },
|
73
|
+
})];
|
69
74
|
case 1:
|
70
75
|
resp = _a.sent();
|
71
|
-
|
76
|
+
response = resp.data;
|
77
|
+
i = 0;
|
78
|
+
_a.label = 2;
|
79
|
+
case 2:
|
80
|
+
if (!(i < response.sleep.length)) return [3 /*break*/, 5];
|
81
|
+
return [4 /*yield*/, this.getStream(response.sleep[i].id)];
|
82
|
+
case 3:
|
83
|
+
stream = _a.sent();
|
84
|
+
response.sleep[i].sleep_stream = stream;
|
85
|
+
_a.label = 4;
|
86
|
+
case 4:
|
87
|
+
i++;
|
88
|
+
return [3 /*break*/, 2];
|
89
|
+
case 5: return [2 /*return*/, resp.data];
|
72
90
|
}
|
73
91
|
});
|
74
92
|
});
|
@@ -4,4 +4,5 @@ export declare const utils: {
|
|
4
4
|
* Secure compare, from https://github.com/freewil/scmp
|
5
5
|
*/
|
6
6
|
secureCompare: (in_a: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, in_b: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>) => boolean;
|
7
|
+
getDayDiff: (startDate: Date, endDate?: Date) => number;
|
7
8
|
};
|
package/dist/client/lib/utils.js
CHANGED
@@ -26,4 +26,12 @@ exports.utils = {
|
|
26
26
|
}
|
27
27
|
return result === 0;
|
28
28
|
},
|
29
|
+
// Get the difference in days between two dates.
|
30
|
+
getDayDiff: function (startDate, endDate) {
|
31
|
+
if (!endDate) {
|
32
|
+
endDate = new Date();
|
33
|
+
}
|
34
|
+
var msInDay = 24 * 60 * 60 * 1000;
|
35
|
+
return Math.round(Math.abs(endDate.getTime() - startDate.getTime()) / msInDay);
|
36
|
+
}
|
29
37
|
};
|
@@ -18,10 +18,6 @@ export interface Physician {
|
|
18
18
|
first_name: string;
|
19
19
|
last_name: string;
|
20
20
|
npi: string;
|
21
|
-
email?: string;
|
22
|
-
licensed_states?: string[];
|
23
|
-
created_at?: string;
|
24
|
-
updated_at?: string;
|
25
21
|
}
|
26
22
|
export interface Marker {
|
27
23
|
name: string;
|
@@ -48,6 +44,7 @@ export interface Order {
|
|
48
44
|
team_id: string;
|
49
45
|
patient_details: PatientDetails;
|
50
46
|
patient_address: PatientAdress;
|
47
|
+
physician: Physician;
|
51
48
|
lab_test: Testkit;
|
52
49
|
details: Object;
|
53
50
|
created_at: string;
|
package/package.json
CHANGED