Skip to content

Commit e114a5a

Browse files
committed
conslidates app into one database
1 parent 2a287d6 commit e114a5a

29 files changed

+266
-284
lines changed

src/__tests__/clients/db/AppointmentRepository.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Appointment Repository', () => {
4242
describe('save', () => {
4343
it('should create an id that is a uuid', async () => {
4444
const newAppointment = await AppointmentRepository.save({
45-
patientId: 'id',
45+
patient: 'id',
4646
} as Appointment)
4747

4848
expect(uuidV4Regex.test(newAppointment.id)).toBeTruthy()
@@ -52,7 +52,7 @@ describe('Appointment Repository', () => {
5252

5353
it('should generate a timestamp for created date and last updated date', async () => {
5454
const newAppointment = await AppointmentRepository.save({
55-
patientId: 'id',
55+
patient: 'id',
5656
} as Appointment)
5757

5858
expect(newAppointment.createdAt).toBeDefined()

src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('AppointmentDetailForm', () => {
6666

6767
expect(patientTypeahead).toHaveLength(1)
6868
expect(patientTypeahead.prop('placeholder')).toEqual('scheduling.appointment.patient')
69-
expect(patientTypeahead.prop('value')).toEqual(expectedAppointment.patientId)
69+
expect(patientTypeahead.prop('value')).toEqual(expectedAppointment.patient)
7070
})
7171

7272
it('should render as start date date time picker', () => {
@@ -149,7 +149,7 @@ describe('AppointmentDetailForm', () => {
149149
describe('layout - not editable', () => {
150150
let wrapper: ReactWrapper
151151
const expectedAppointment = {
152-
patientId: 'patientId',
152+
patient: 'patientId',
153153
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
154154
endDateTime: addMinutes(
155155
roundToNearestMinutes(new Date(), { nearestTo: 15 }),

src/__tests__/scheduling/appointments/Appointments.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('/appointments/edit/:id', () => {
129129
it('should render the edit appointment screen when /appointments/edit/:id is accessed', () => {
130130
const appointment = {
131131
id: '123',
132-
patientId: '456',
132+
patient: '456',
133133
} as Appointment
134134

135135
const patient = {

src/__tests__/scheduling/appointments/ViewAppointments.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('ViewAppointments', () => {
2424
{
2525
id: '123',
2626
rev: '1',
27-
patientId: '1234',
27+
patient: '1234',
2828
startDateTime: new Date().toISOString(),
2929
endDateTime: new Date().toISOString(),
3030
location: 'location',

src/__tests__/scheduling/appointments/appointment-slice.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('appointment slice', () => {
5959

6060
it('should handle the UPDATE_APPOINTMENT_SUCCESS action', () => {
6161
const expectedAppointment = {
62-
patientId: '123',
62+
patient: '123',
6363
startDateTime: new Date().toISOString(),
6464
endDateTime: new Date().toISOString(),
6565
location: 'location',
@@ -130,7 +130,7 @@ describe('appointment slice', () => {
130130
const dispatch = jest.fn()
131131
const getState = jest.fn()
132132
const expectedAppointment = {
133-
patientId: '123',
133+
patient: '123',
134134
startDateTime: new Date().toISOString(),
135135
endDateTime: new Date().toISOString(),
136136
location: 'location',
@@ -150,7 +150,7 @@ describe('appointment slice', () => {
150150
mocked(AppointmentRepository, true).save.mockResolvedValue({ id: '123' } as Appointment)
151151

152152
const expectedAppointment = {
153-
patientId: '123',
153+
patient: '123',
154154
startDateTime: new Date().toISOString(),
155155
endDateTime: new Date().toISOString(),
156156
location: 'location',
@@ -175,7 +175,7 @@ describe('appointment slice', () => {
175175
const getState = jest.fn()
176176

177177
const expectedAppointment = {
178-
patientId: '123',
178+
patient: '123',
179179
startDateTime: new Date().toISOString(),
180180
endDateTime: new Date().toISOString(),
181181
location: 'location',
@@ -218,7 +218,7 @@ describe('appointment slice', () => {
218218
const expectedAppointment: Appointment = {
219219
id: '1',
220220
rev: '1',
221-
patientId: '123',
221+
patient: '123',
222222
startDateTime: new Date().toISOString(),
223223
endDateTime: new Date().toISOString(),
224224
location: 'location',
@@ -333,7 +333,7 @@ describe('appointment slice', () => {
333333
jest.spyOn(AppointmentRepository, 'saveOrUpdate')
334334

335335
const expectedAppointment = {
336-
patientId: 'sliceId9',
336+
patient: 'sliceId9',
337337
startDateTime: new Date().toISOString(),
338338
endDateTime: new Date().toISOString(),
339339
location: 'location',
@@ -355,7 +355,7 @@ describe('appointment slice', () => {
355355
jest.spyOn(AppointmentRepository, 'saveOrUpdate')
356356

357357
const expectedAppointment = {
358-
patientId: 'sliceId10',
358+
patient: 'sliceId10',
359359
startDateTime: new Date().toISOString(),
360360
endDateTime: new Date().toISOString(),
361361
location: 'location',
@@ -377,7 +377,7 @@ describe('appointment slice', () => {
377377
jest.spyOn(AppointmentRepository, 'saveOrUpdate')
378378

379379
const expectedAppointment = {
380-
patientId: 'sliceId11',
380+
patient: 'sliceId11',
381381
startDateTime: new Date().toISOString(),
382382
endDateTime: new Date().toISOString(),
383383
location: 'location',
@@ -403,7 +403,7 @@ describe('appointment slice', () => {
403403
jest.spyOn(AppointmentRepository, 'saveOrUpdate')
404404

405405
const expectedAppointment = {
406-
patientId: 'sliceId12',
406+
patient: 'sliceId12',
407407
startDateTime: new Date().toISOString(),
408408
endDateTime: new Date().toISOString(),
409409
location: 'location',

src/__tests__/scheduling/appointments/appointments-slice.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('appointments slice', () => {
4949
{
5050
id: '1',
5151
rev: '1',
52-
patientId: '123',
52+
patient: '123',
5353
startDateTime: new Date().toISOString(),
5454
endDateTime: new Date().toISOString(),
5555
location: 'location',

src/__tests__/scheduling/appointments/edit/EditAppointment.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const mockStore = createMockStore<RootState, any>([thunk])
2727
describe('Edit Appointment', () => {
2828
const appointment = {
2929
id: '123',
30-
patientId: '456',
30+
patient: '456',
3131
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
3232
endDateTime: addMinutes(roundToNearestMinutes(new Date(), { nearestTo: 15 }), 60).toISOString(),
3333
location: 'location',
@@ -107,7 +107,7 @@ describe('Edit Appointment', () => {
107107
})
108108

109109
expect(AppointmentRepository.find).toHaveBeenCalledWith(appointment.id)
110-
expect(PatientRepository.find).toHaveBeenCalledWith(appointment.patientId)
110+
expect(PatientRepository.find).toHaveBeenCalledWith(appointment.patient)
111111
expect(store.getActions()).toContainEqual(appointmentSlice.fetchAppointmentStart())
112112
expect(store.getActions()).toContainEqual(
113113
appointmentSlice.fetchAppointmentSuccess({ appointment, patient }),

src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('New Appointment', () => {
9191
})
9292

9393
const expectedAppointment = {
94-
patientId: '123',
94+
patient: '123',
9595
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
9696
endDateTime: addMinutes(
9797
roundToNearestMinutes(new Date(), { nearestTo: 15 }),
@@ -105,7 +105,7 @@ describe('New Appointment', () => {
105105
act(() => {
106106
const appointmentDetailForm = wrapper.find(AppointmentDetailForm)
107107
const onFieldChange = appointmentDetailForm.prop('onFieldChange')
108-
onFieldChange('patientId', expectedAppointment.patientId)
108+
onFieldChange('patientId', expectedAppointment.patient)
109109
})
110110

111111
wrapper.update()
@@ -171,7 +171,7 @@ describe('New Appointment', () => {
171171
})
172172

173173
const expectedAppointment = {
174-
patientId: '123',
174+
patient: '123',
175175
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
176176
endDateTime: addMinutes(
177177
roundToNearestMinutes(new Date(), { nearestTo: 15 }),
@@ -185,7 +185,7 @@ describe('New Appointment', () => {
185185
act(() => {
186186
const appointmentDetailForm = wrapper.find(AppointmentDetailForm)
187187
const onFieldChange = appointmentDetailForm.prop('onFieldChange')
188-
onFieldChange('patientId', expectedAppointment.patientId)
188+
onFieldChange('patientId', expectedAppointment.patient)
189189
})
190190
wrapper.update()
191191
const saveButton = wrapper.find(mockedComponents.Button).at(0)

src/clients/db/AppointmentRepository.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import escapeStringRegexp from 'escape-string-regexp'
22

3-
import { localDb } from '../../config/pouchdb'
3+
import { relationalDb } from '../../config/pouchdb'
44
import Appointment from '../../model/Appointment'
55
import Repository from './Repository'
66

77
class AppointmentRepository extends Repository<Appointment> {
88
constructor() {
9-
super(localDb)
9+
super('appointment', relationalDb)
10+
this.db.createIndex({
11+
index: {
12+
fields: ['data.patient', '_id'],
13+
},
14+
})
1015
}
1116

1217
// Fuzzy search for patient appointments. Used for patient appointment search bar
@@ -16,7 +21,7 @@ class AppointmentRepository extends Repository<Appointment> {
1621
selector: {
1722
$and: [
1823
{
19-
patientId,
24+
patient: patientId,
2025
},
2126
{
2227
$or: [

src/clients/db/IncidentRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { localDb } from '../../config/pouchdb'
1+
import { relationalDb } from '../../config/pouchdb'
22
import IncidentFilter from '../../incidents/IncidentFilter'
33
import Incident from '../../model/Incident'
44
import Repository from './Repository'
@@ -8,7 +8,7 @@ interface SearchOptions {
88
}
99
class IncidentRepository extends Repository<Incident> {
1010
constructor() {
11-
super(localDb)
11+
super('incident', relationalDb)
1212
}
1313

1414
async search(options: SearchOptions): Promise<Incident[]> {

0 commit comments

Comments
 (0)