@rinse-dental/open-dental 0.0.6 → 0.1.0

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.
@@ -1,26 +1,205 @@
1
+ import axios from "axios";
1
2
  import HttpClient from "../utils/httpClient";
2
- import { Patient } from "../utils/types";
3
+ import {
4
+ Patient,
5
+ PatientSummary,
6
+ GetPatientsParams,
7
+ CreatePatientParams,
8
+ UpdatePatientParams,
9
+ } from "../types/patientTypes";
3
10
 
4
- export interface IPatients {
5
- getPatient(params: { PatNum: number }): Promise<Patient>;
6
- getPatients(): Promise<Patient[]>;
7
- }
8
-
9
- export default class Patients implements IPatients {
11
+ export default class Patients {
10
12
  private httpClient: HttpClient;
11
13
 
12
14
  constructor(httpClient: HttpClient) {
13
15
  this.httpClient = httpClient;
14
16
  }
15
17
 
16
- public async getPatient(params: { PatNum: number }): Promise<Patient> {
17
- if (!params.PatNum) {
18
- throw new Error("PatNum is required.");
18
+ /**
19
+ * Fetch a single patient by their ID.
20
+ * @param {number} PatNum - The ID of the patient.
21
+ * @returns {Promise<Patient>} - The patient data.
22
+ * @throws {Error} - If `PatNum` is not valid or the API returns an error.
23
+ */
24
+ public async getPatient(PatNum: number): Promise<Patient> {
25
+ if (!PatNum || typeof PatNum !== "number") {
26
+ throw new Error("Invalid parameter: PatNum must be a valid number.");
27
+ }
28
+
29
+ return await this.httpClient.get<Patient>(`/patients/${PatNum}`);
30
+ }
31
+
32
+ /**
33
+ * Fetch multiple patients with optional filtering and pagination.
34
+ * @param {Object} params - Filtering and pagination parameters.
35
+ * @param {string} [params.LName] - Filter by last name (case-insensitive, partial match).
36
+ * @param {string} [params.FName] - Filter by first name (case-insensitive, partial match).
37
+ * @param {string} [params.Phone] - Filter by phone number.
38
+ * @param {string} [params.Address] - Filter by primary address.
39
+ * @param {'true' | 'false'} [params.hideInactive] - Exclude inactive patients.
40
+ * @param {string} [params.City] - Filter by city.
41
+ * @param {string} [params.State] - Filter by state.
42
+ * @param {string} [params.SSN] - Filter by Social Security Number.
43
+ * @param {string} [params.ChartNumber] - Filter by chart number.
44
+ * @param {'true' | 'false'} [params.guarOnly] - Limit results to guarantors only.
45
+ * @param {'true' | 'false'} [params.showArchived] - Include archived patients.
46
+ * @param {string} [params.Birthdate] - Filter by birthdate in "yyyy-MM-dd" format.
47
+ * @param {number} [params.SiteNum] - Filter by site number.
48
+ * @param {string} [params.SubscriberId] - Filter by subscriber ID.
49
+ * @param {string} [params.Email] - Filter by email address.
50
+ * @param {string} [params.Country] - Filter by country.
51
+ * @param {number} [params.ClinicNum] - Filter by clinic number (comma-separated list).
52
+ * @param {string} [params.clinicAbbr] - Filter by clinic abbreviation.
53
+ * @param {string} [params.invoiceNumber] - Filter by invoice number.
54
+ * @param {number} [params.Offset] - Pagination offset.
55
+ * @returns {Promise<PatientSummary[]>} - A list of summarized patient data.
56
+ * @throws {Error} - If the API returns an error.
57
+ */
58
+ public async getPatients({
59
+ LName,
60
+ FName,
61
+ Phone,
62
+ Address,
63
+ hideInactive,
64
+ City,
65
+ State,
66
+ SSN,
67
+ ChartNumber,
68
+ guarOnly,
69
+ showArchived,
70
+ Birthdate,
71
+ SiteNum,
72
+ SubscriberId,
73
+ Email,
74
+ Country,
75
+ ClinicNum,
76
+ clinicAbbr,
77
+ invoiceNumber,
78
+ Offset,
79
+ }: GetPatientsParams = {}): Promise<PatientSummary[]> {
80
+
81
+ return await this.httpClient.get<PatientSummary[]>("/patients", {
82
+ LName,
83
+ FName,
84
+ Phone,
85
+ Address,
86
+ hideInactive,
87
+ City,
88
+ State,
89
+ SSN,
90
+ ChartNumber,
91
+ guarOnly,
92
+ showArchived,
93
+ Birthdate,
94
+ SiteNum,
95
+ SubscriberId,
96
+ Email,
97
+ Country,
98
+ ClinicNum,
99
+ clinicAbbr,
100
+ invoiceNumber,
101
+ Offset,
102
+ });
103
+
19
104
  }
20
- return this.httpClient.get<Patient>(`/patients/${params.PatNum}`);
105
+
106
+ /**
107
+ * Create a new patient.
108
+ * @param {Object} data - The data for the new patient.
109
+ * @param {string} data.LName - Required: Last name.
110
+ * @param {string} data.FName - Required: First name.
111
+ * @param {string} [data.MiddleI] - Optional: Middle initial.
112
+ * @param {string} [data.Preferred] - Optional: Preferred name.
113
+ * @param {'Patient' | 'NonPatient' | 'Inactive' | 'Archived' | 'Deceased' | 'Prospective'} [data.PatStatus="Patient"] - Optional: Patient status. Default is "Patient".
114
+ * @param {'Male' | 'Female' | 'Unknown' | 'Other'} [data.Gender] - Optional: Gender.
115
+ * @param {'Single' | 'Married' | 'Child' | 'Widowed' | 'Divorced'} [data.Position] - Optional: Marital status.
116
+ * @param {string} [data.Birthdate] - Optional: Birthdate in "yyyy-MM-dd" format.
117
+ * @param {string} [data.SSN] - Optional: Social Security Number.
118
+ * @param {string} [data.Address] - Optional: Primary address.
119
+ * @param {string} [data.Address2] - Optional: Secondary address.
120
+ * @param {string} [data.City] - Optional: City.
121
+ * @param {string} [data.State] - Optional: State.
122
+ * @param {string} [data.Zip] - Optional: ZIP code.
123
+ * @param {string} [data.HmPhone] - Optional: Home phone number.
124
+ * @param {string} [data.WkPhone] - Optional: Work phone number.
125
+ * @param {string} [data.WirelessPhone] - Optional: Mobile phone number.
126
+ * @param {number} [data.Guarantor] - Optional: Guarantor's PatNum.
127
+ * @param {string} [data.Email] - Optional: Email address.
128
+ * @param {number} [data.PriProv] - Optional: Primary provider number.
129
+ * @param {number} [data.SecProv] - Optional: Secondary provider number.
130
+ * @param {string} [data.BillingType] - Optional: Billing type description.
131
+ * @param {string} [data.FamFinUrgNote] - Optional: Family financial urgent note.
132
+ * @returns {Promise<Patient>} - The created patient.
133
+ * @throws {Error} - If the data is invalid or the API returns an error.
134
+ */
135
+ public async createPatient({
136
+ LName,
137
+ FName,
138
+ ...optionalData
139
+ }: CreatePatientParams): Promise<Patient> {
140
+ if (!LName || !FName) {
141
+ throw new Error("Invalid data: LName and FName are required.");
142
+ }
143
+ return await this.httpClient.post<Patient>("/patients", {
144
+ LName,
145
+ FName,
146
+ ...optionalData,
147
+ });
21
148
  }
22
149
 
23
- public async getPatients(): Promise<Patient[]> {
24
- return this.httpClient.get<Patient[]>("/patients");
150
+ /**
151
+ * Update an existing patient.
152
+ * @param {number} PatNum - Required: The unique identifier of the patient to update.
153
+ * @param {Object} data - Required: The updated patient data.
154
+ * @param {string} [data.LName] - Optional: Last name.
155
+ * @param {string} [data.FName] - Optional: First name.
156
+ * @param {string} [data.MiddleI] - Optional: Middle initial.
157
+ * @param {string} [data.Preferred] - Optional: Preferred name.
158
+ * @param {'Patient' | 'NonPatient' | 'Inactive' | 'Archived' | 'Deceased' | 'Prospective'} [data.PatStatus] - Optional: Patient status.
159
+ * @param {'Male' | 'Female' | 'Unknown' | 'Other'} [data.Gender] - Optional: Gender.
160
+ * @param {'Single' | 'Married' | 'Child' | 'Widowed' | 'Divorced'} [data.Position] - Optional: Marital status.
161
+ * @param {string} [data.Birthdate] - Optional: Birthdate in "yyyy-MM-dd" format.
162
+ * @param {string} [data.SSN] - Optional: Social Security Number.
163
+ * @param {string} [data.Address] - Optional: Primary address.
164
+ * @param {string} [data.Address2] - Optional: Secondary address.
165
+ * @param {string} [data.City] - Optional: City.
166
+ * @param {string} [data.State] - Optional: State.
167
+ * @param {string} [data.Zip] - Optional: ZIP code.
168
+ * @param {string} [data.HmPhone] - Optional: Home phone number.
169
+ * @param {string} [data.WkPhone] - Optional: Work phone number.
170
+ * @param {string} [data.WirelessPhone] - Optional: Mobile phone number.
171
+ * @param {number} [data.Guarantor] - Optional: Guarantor's PatNum.
172
+ * @param {string} [data.Email] - Optional: Email address.
173
+ * @param {number} [data.PriProv] - Optional: Primary provider number.
174
+ * @param {number} [data.SecProv] - Optional: Secondary provider number.
175
+ * @param {string} [data.BillingType] - Optional: Billing type description.
176
+ * @param {string} [data.FamFinUrgNote] - Optional: Family financial urgent note.
177
+ * @param {string} [data.ChartNumber] - Optional: Chart number.
178
+ * @param {string} [data.DateFirstVisit] - Optional: Date of first visit in "yyyy-MM-dd" format.
179
+ * @param {number} [data.ClinicNum] - Optional: Clinic number.
180
+ * @param {string} [data.Ward] - Optional: Ward.
181
+ * @param {'None' | 'Email' | 'TextMessage' | 'PhoneCall' | 'Mail'} [data.PreferConfirmMethod] - Optional: Preferred confirmation method.
182
+ * @param {'None' | 'Email' | 'TextMessage' | 'PhoneCall' | 'Mail'} [data.PreferContactMethod] - Optional: Preferred contact method.
183
+ * @param {'None' | 'Email' | 'TextMessage' | 'PhoneCall' | 'Mail'} [data.PreferRecallMethod] - Optional: Preferred recall method.
184
+ * @param {string} [data.Language] - Optional: Language code in ISO 639-2 format.
185
+ * @param {string} [data.AdmitDate] - Optional: Admission date in "yyyy-MM-dd" format.
186
+ * @param {number} [data.SuperFamily] - Optional: Super family number.
187
+ * @param {'Unknown' | 'Yes' | 'No'} [data.TxtMsgOk] - Optional: Text message consent.
188
+ * @returns {Promise<Patient>} - The updated patient.
189
+ * @throws {Error} - If the parameters are invalid or the API returns an error.
190
+ */
191
+ public async updatePatient(PatNum: number, data: UpdatePatientParams): Promise<Patient> {
192
+ // Validate required parameters
193
+ if (!PatNum || typeof PatNum !== "number") {
194
+ throw new Error("Invalid parameter: PatNum must be a valid number.");
195
+ }
196
+
197
+ if (!data || Object.keys(data).length === 0) {
198
+ throw new Error("Invalid data: Update data cannot be empty.");
199
+ }
200
+
201
+ return await this.httpClient.put<Patient>(`/patients/${PatNum}`, data);
202
+
25
203
  }
204
+
26
205
  }
@@ -0,0 +1,230 @@
1
+ import HttpClient from "../utils/httpClient";
2
+ import {
3
+ ProcedureLog,
4
+ createProcedureLogParams,
5
+ updateProcedureLogParams,
6
+ InsuranceHistory,
7
+ getInsuranceHistoryParams,
8
+ postInsuranceHistoryParams,
9
+ } from "../types/procedurelogTypes";
10
+
11
+ export default class ProcedureLogs {
12
+ private httpClient: HttpClient;
13
+
14
+ constructor(httpClient: HttpClient) {
15
+ this.httpClient = httpClient;
16
+ }
17
+
18
+ /**
19
+ * Fetch a specific procedure log entry by its ID.
20
+ * @param {number} ProcNum - Required: The unique identifier of the procedure log.
21
+ * @returns {Promise<ProcedureLog>} - The procedure log details.
22
+ * @throws {Error} - If `ProcNum` is not valid or the API returns an error.
23
+ */
24
+ public async getProcedureLog(ProcNum: number): Promise<ProcedureLog> {
25
+ if (!ProcNum || typeof ProcNum !== "number") {
26
+ throw new Error("Invalid parameter: ProcNum must be a valid number.");
27
+ }
28
+
29
+ return this.httpClient.get<ProcedureLog>(`/procedurelogs/${ProcNum}`);
30
+ }
31
+
32
+ /**
33
+ * Create a new procedure log entry.
34
+ * @param {Object} params - The details of the procedure log to create.
35
+ * @param {number} params.PatNum - Required: Patient number.
36
+ * @param {string} params.ProcDate - Required: Procedure date in "yyyy-MM-dd" format.
37
+ * @param {'TP' | 'C' | 'EO'} params.ProcStatus - Required: Procedure status.
38
+ * @param {string} params.procCode - Required: Procedure code (D code).
39
+ * @param {number} [params.AptNum] - Optional: Associated appointment number.
40
+ * @param {number} [params.ProcFee] - Optional: Fee for the procedure.
41
+ * @param {Surf} [Surf] - Optional: Tooth surface or treatment area. Options include:
42
+ * - "B/F" (Buccal/Facial)
43
+ * - "V" (Vestibular)
44
+ * - "M" (Mesial)
45
+ * - "O/I" (Occlusal/Incisal)
46
+ * - "D" (Distal)
47
+ * - "L" (Lingual)
48
+ * - "UL" (Upper Left Quadrant)
49
+ * - "UR" (Upper Right Quadrant)
50
+ * - "LR" (Lower Right Quadrant)
51
+ * - "LL" (Lower Left Quadrant)
52
+ * - "1" (Sextant 1)
53
+ * - "2" (Sextant 2)
54
+ * - "3" (Sextant 3)
55
+ * - "4" (Sextant 4)
56
+ * - "5" (Sextant 5)
57
+ * - "6" (Sextant 6)
58
+ * - "U" (Upper Arch)
59
+ * - "L" (Lower Arch)
60
+ * @param {string} [params.ToothNum] - Optional: Tooth number.
61
+ * @param {string} [params.ToothRange] - Optional: Tooth range.
62
+ * @param {number} [params.Priority] - Optional: Priority code.
63
+ * @param {number} [params.ProvNum] - Optional: Provider number.
64
+ * @param {string} [params.Dx] - Optional: Diagnosis code.
65
+ * @param {number} [params.PlannedAptNum] - Optional: Planned appointment number.
66
+ * @param {number} [params.ClinicNum] - Optional: Clinic number.
67
+ * @returns {Promise<ProcedureLog>} - The created procedure log.
68
+ * @throws {Error} - If required fields are missing or the API returns an error.
69
+ */
70
+ public async createProcedureLog({
71
+ PatNum,
72
+ ProcDate,
73
+ ProcStatus,
74
+ procCode,
75
+ ...optionalData
76
+ }: createProcedureLogParams): Promise<ProcedureLog> {
77
+ if (!PatNum || !ProcDate || !ProcStatus || !procCode) {
78
+ throw new Error("Invalid data: PatNum, ProcDate, ProcStatus, and procCode are required.");
79
+ }
80
+
81
+ return this.httpClient.post<ProcedureLog>("/procedurelogs", {
82
+ PatNum,
83
+ ProcDate,
84
+ ProcStatus,
85
+ procCode,
86
+ ...optionalData,
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Update an existing procedure log entry.
92
+ * @param {number} ProcNum - Required: The unique identifier of the procedure log to update.
93
+ * @param {Object} params - The updated details of the procedure log.
94
+ * @param {string} [params.ProcDate] - Optional: Updated procedure date in "yyyy-MM-dd" format.
95
+ * @param {number} [params.AptNum] - Optional: Updated associated appointment number.
96
+ * @param {number} [params.ProcFee] - Optional: Updated fee for the procedure.
97
+ * @param {number} [params.Priority] - Optional: Updated priority code.
98
+ * @param {'TP' | 'C' | 'EO'} [params.ProcStatus] - Optional: Updated procedure status.
99
+ * @param {string} [params.procCode] - Optional: Updated procedure code (D code).
100
+ * @param {Surf} [Surf] - Optional: Tooth surface or treatment area. Options include:
101
+ * - "B/F" (Buccal/Facial)
102
+ * - "V" (Vestibular)
103
+ * - "M" (Mesial)
104
+ * - "O/I" (Occlusal/Incisal)
105
+ * - "D" (Distal)
106
+ * - "L" (Lingual)
107
+ * - "UL" (Upper Left Quadrant)
108
+ * - "UR" (Upper Right Quadrant)
109
+ * - "LR" (Lower Right Quadrant)
110
+ * - "LL" (Lower Left Quadrant)
111
+ * - "1" (Sextant 1)
112
+ * - "2" (Sextant 2)
113
+ * - "3" (Sextant 3)
114
+ * - "4" (Sextant 4)
115
+ * - "5" (Sextant 5)
116
+ * - "6" (Sextant 6)
117
+ * - "U" (Upper Arch)
118
+ * - "L" (Lower Arch)
119
+ * @param {string} [params.ToothNum] - Optional: Updated tooth number.
120
+ * @param {string} [params.ToothRange] - Optional: Updated tooth range.
121
+ * @param {number} [params.ProvNum] - Optional: Updated provider number.
122
+ * @param {string} [params.Dx] - Optional: Updated diagnosis code.
123
+ * @param {number} [params.PlannedAptNum] - Optional: Updated planned appointment number.
124
+ * @param {number} [params.ClinicNum] - Optional: Updated clinic number.
125
+ * @returns {Promise<ProcedureLog>} - The updated procedure log.
126
+ * @throws {Error} - If required fields are missing or the API returns an error.
127
+ */
128
+ public async updateProcedureLog(
129
+ ProcNum: number,
130
+ {
131
+ ProcDate,
132
+ AptNum,
133
+ ProcFee,
134
+ Priority,
135
+ ProcStatus,
136
+ procCode,
137
+ Surf,
138
+ ToothNum,
139
+ ToothRange,
140
+ ProvNum,
141
+ Dx,
142
+ PlannedAptNum,
143
+ ClinicNum,
144
+ }: updateProcedureLogParams
145
+ ): Promise<ProcedureLog> {
146
+ if (!ProcNum || typeof ProcNum !== "number") {
147
+ throw new Error("Invalid parameter: ProcNum must be a valid number.");
148
+ }
149
+
150
+ return this.httpClient.put<ProcedureLog>(`/procedurelogs/${ProcNum}`, {
151
+ ProcDate,
152
+ AptNum,
153
+ ProcFee,
154
+ Priority,
155
+ ProcStatus,
156
+ procCode,
157
+ Surf,
158
+ ToothNum,
159
+ ToothRange,
160
+ ProvNum,
161
+ Dx,
162
+ PlannedAptNum,
163
+ ClinicNum,
164
+ });
165
+ }
166
+
167
+ /**
168
+ * Delete a procedure log entry.
169
+ * @param {number} ProcNum - Required: The unique identifier of the procedure log to delete.
170
+ * @returns {Promise<void>} - Resolves when the procedure log is deleted.
171
+ * @throws {Error} - If `ProcNum` is not valid or the API returns an error.
172
+ */
173
+ public async deleteProcedureLog(ProcNum: number): Promise<void> {
174
+ if (!ProcNum || typeof ProcNum !== "number") {
175
+ throw new Error("Invalid parameter: ProcNum must be a valid number.");
176
+ }
177
+
178
+ return this.httpClient.delete<void>(`/procedurelogs/${ProcNum}`);
179
+ }
180
+
181
+ /**
182
+ * Fetch insurance history for a patient.
183
+ * @param {number} PatNum - Required: The patient number.
184
+ * @param {number} InsSubNum - Required: The insurance subscription number.
185
+ * @returns {Promise<InsuranceHistory[]>} - The insurance history details.
186
+ * @throws {Error} - If required fields are missing or the API returns an error.
187
+ */
188
+ public async getInsuranceHistory({
189
+ PatNum,
190
+ InsSubNum,
191
+ }: getInsuranceHistoryParams): Promise<InsuranceHistory[]> {
192
+ if (!PatNum || !InsSubNum) {
193
+ throw new Error("Invalid parameters: PatNum and InsSubNum are required.");
194
+ }
195
+
196
+ return this.httpClient.get<InsuranceHistory[]>("/procedurelogs/insurancehistory", {
197
+ PatNum,
198
+ InsSubNum,
199
+ });
200
+ }
201
+
202
+ /**
203
+ * Add an insurance history entry.
204
+ * @param {number} PatNum - Required: The patient number.
205
+ * @param {number} InsSubNum - Required: The insurance subscription number.
206
+ * @param {"InsHistBWCodes" | "InsHistPanoCodes" | "InsHistExamCodes" | "InsHistProphyCodes" | "InsHistPerioURCodes" | "InsHistPerioULCodes" | "InsHistPerioLRCodes" | "InsHistPerioLLCodes" | "InsHistPerioMaintCodes" | "InsHistDebridementCodes"} insHistPrefName - Required: The insurance history category name.
207
+ * @param {string} ProcDate - Required: Procedure date in "yyyy-MM-dd" format.
208
+ * @returns {Promise<InsuranceHistory>} - The created insurance history entry.
209
+ * @throws {Error} - If required fields are missing or the API returns an error.
210
+ */
211
+ public async postInsuranceHistory({
212
+ PatNum,
213
+ InsSubNum,
214
+ insHistPrefName,
215
+ ProcDate,
216
+ }: postInsuranceHistoryParams): Promise<InsuranceHistory> {
217
+ if (!PatNum || !InsSubNum || !insHistPrefName || !ProcDate) {
218
+ throw new Error(
219
+ "Invalid data: PatNum, InsSubNum, insHistPrefName, and ProcDate are required."
220
+ );
221
+ }
222
+
223
+ return this.httpClient.post<InsuranceHistory>("/procedurelogs/insurancehistory", {
224
+ PatNum,
225
+ InsSubNum,
226
+ insHistPrefName,
227
+ ProcDate,
228
+ });
229
+ }
230
+ }
package/src/openDental.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import HttpClient from "./utils/httpClient";
2
- import Patients, { IPatients } from "./api/patients";
3
- import Appointments, { IAppointments } from "./api/appointments";
2
+ import Patients from "./api/patients";
3
+ import Appointments from "./api/appointments";
4
4
 
5
5
  class OpenDental {
6
6
  private static httpClient: HttpClient;
@@ -22,7 +22,7 @@ class OpenDental {
22
22
  /**
23
23
  * Create a new instance of the Patients API.
24
24
  */
25
- public static Patients(): IPatients {
25
+ public static Patients() {
26
26
  if (!this.httpClient) {
27
27
  throw new Error("OpenDental not initialized. Call OpenDental.initialize() first.");
28
28
  }
@@ -32,7 +32,7 @@ class OpenDental {
32
32
  /**
33
33
  * Create a new instance of the Appointments API.
34
34
  */
35
- public static Appointments(): IAppointments {
35
+ public static Appointments() {
36
36
  if (!this.httpClient) {
37
37
  throw new Error("OpenDental not initialized. Call OpenDental.initialize() first.");
38
38
  }