-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClient.ts
More file actions
161 lines (152 loc) · 7.76 KB
/
Client.ts
File metadata and controls
161 lines (152 loc) · 7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// This file was auto-generated by Fern from our API Definition.
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient.js";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js";
import * as core from "../../../../core/index.js";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.js";
import * as errors from "../../../../errors/index.js";
import * as serializers from "../../../../serialization/index.js";
import * as Corti from "../../../index.js";
export declare namespace CodesClient {
export type Options = BaseClientOptions;
export interface RequestOptions extends BaseRequestOptions {}
}
export class CodesClient {
protected readonly _options: NormalizedClientOptionsWithAuth<CodesClient.Options>;
constructor(options: CodesClient.Options) {
this._options = normalizeClientOptionsWithAuth(options);
}
/**
* Predict medical codes from provided context.<br/><Note>This is a stateless endpoint, designed to predict ICD-10-CM, ICD-10-PCS, ICD-10-UK and CPT codes based on input text string or documentId.<br/><br/>More than one code system may be defined in a single request.<br/><br/>Code prediction requests have two possible values for context:<br/>- `text`: One set of code prediction results will be returned based on all input text defined.<br/>- `documentId`: Code prediction will be based on that defined document only.<br/><br/>The response includes two sets of results:<br/>- `Codes`: Codes predicted by the model.<br/>- `Candidates`: Lower-confidence codes the model considered potentially relevant but excluded from the predicted set.<br/><br/>All predicted code results are based on input context defined in the request only (not other external data or assets associated with an interaction).</Note>
*
* @param {Corti.CodesGeneralPredictRequest} request
* @param {CodesClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Corti.BadRequestError}
* @throws {@link Corti.ForbiddenError}
* @throws {@link Corti.InternalServerError}
* @throws {@link Corti.BadGatewayError}
* @throws {@link Corti.GatewayTimeoutError}
*
* @example
* await client.codes.predict({
* system: ["icd10cm-outpatient", "cpt"],
* context: [{
* type: "text",
* text: "Short arm splint applied in ED for pain control."
* }]
* })
*
* @example
* await client.codes.predict({
* system: ["icd10cm-outpatient"],
* context: [{
* type: "text",
* text: "Patient presents with uncontrolled type 2 diabetes."
* }],
* filter: {
* include: ["E11"],
* exclude: ["exclude"]
* }
* })
*/
public predict(
request: Corti.CodesGeneralPredictRequest,
requestOptions?: CodesClient.RequestOptions,
): core.HttpResponsePromise<Corti.CodesGeneralResponse> {
return core.HttpResponsePromise.fromPromise(this.__predict(request, requestOptions));
}
private async __predict(
request: Corti.CodesGeneralPredictRequest,
requestOptions?: CodesClient.RequestOptions,
): Promise<core.WithRawResponse<Corti.CodesGeneralResponse>> {
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({ "Tenant-Name": requestOptions?.tenantName ?? this._options?.tenantName }),
requestOptions?.headers,
);
const _response = await core.fetcher({
url: core.url.join(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)).base,
"tools/coding/",
),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions?.queryParams,
requestType: "json",
body: serializers.CodesGeneralPredictRequest.jsonOrThrow(request, {
unrecognizedObjectKeys: "strip",
omitUndefined: true,
}),
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: serializers.CodesGeneralResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Corti.BadRequestError(_response.error.body, _response.rawResponse);
case 403:
throw new Corti.ForbiddenError(_response.error.body, _response.rawResponse);
case 500:
throw new Corti.InternalServerError(
serializers.ErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 502:
throw new Corti.BadGatewayError(
serializers.ErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 504:
throw new Corti.GatewayTimeoutError(
serializers.ErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/tools/coding/");
}
}