Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1084 adopt tasks service APIs #1085

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7e932ad
Merge branch 'main' into issue/1054-Integrate_CRUD_endpoints_properties
DasProffi Jun 19, 2024
0de6355
Merge branch 'main' into issue/1054-Integrate_CRUD_endpoints_properties
DasProffi Jun 25, 2024
f4ad244
chore: draft for property service
DasProffi Jul 6, 2024
c5c59db
chore: update types and parsing
DasProffi Jul 8, 2024
db22b83
feat: implement offline service
DasProffi Aug 26, 2024
2eaa01b
feat: add user and organization service and wrap services
DasProffi Aug 26, 2024
e653890
Merge branch 'main' into issue/1054-Integrate_CRUD_endpoints_properties
DasProffi Aug 30, 2024
3436cee
fix: fix lint error
DasProffi Aug 30, 2024
34439ba
chore: draft for API services package
DasProffi Aug 30, 2024
ef481d9
chore: move services to its one package
DasProffi Aug 31, 2024
815d58a
fix: fix build errors
DasProffi Aug 31, 2024
478658c
fix: fix ci
DasProffi Aug 31, 2024
dd7dcb1
chore: remove unused env variable and add documentation of api-services
DasProffi Aug 31, 2024
ee9671a
feat: draft for usage of tasks api service
DasProffi Sep 2, 2024
dbeadc0
chore: update and reduce some task mutations
DasProffi Sep 3, 2024
2531784
feat: use new tasks api
DasProffi Sep 5, 2024
d51acd6
Merge remote-tracking branch 'origin/integration/properties' into iss…
DasProffi Sep 19, 2024
5e8c089
fix: fix issues from merge
DasProffi Sep 19, 2024
e0957a8
fix: update api version
MaxSchaefer Sep 20, 2024
e88f376
Merge branch 'issue/1082-API_services_package' into issue/1084-Adopt-…
DasProffi Sep 23, 2024
10281b2
fix: update tasks api changes
DasProffi Sep 23, 2024
19d4725
Merge branch 'main' into issue/1084-Adopt-tasks-service-APIs
DasProffi Oct 1, 2024
7a1a170
fix: fix merge errors
DasProffi Oct 1, 2024
ea69ecf
feat: update to tasks api
DasProffi Oct 1, 2024
ff4ff57
fix: fix usage of localstorage
DasProffi Oct 2, 2024
1748cb1
Merge branch 'main' into issue/1084-Adopt-tasks-service-APIs
DasProffi Oct 20, 2024
bc323fc
fix: fix usage of removed hook
DasProffi Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api-services/config/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAPIServiceConfig } from './config'

export const APIServiceUrls = {
tasks: `${getAPIServiceConfig().apiUrl}/task-svc`,
tasks: `${getAPIServiceConfig().apiUrl}/tasks-svc`,
users: `${getAPIServiceConfig().apiUrl}/user-svc`,
property: `${getAPIServiceConfig().apiUrl}/property-svc`
}
2 changes: 1 addition & 1 deletion api-services/mutations/tasks/bed_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DeleteBedRequest,
GetBedRequest,
UpdateBedRequest
} from '@helpwave/proto-ts/services/task_svc/v1/bed_svc_pb'
} from '@helpwave/proto-ts/services/tasks_svc/v1/bed_svc_pb'
import { QueryKeys } from '../query_keys'
import { APIServices } from '../../services'
import { getAuthenticatedGrpcMetadata } from '../../authentication/grpc_metadata'
Expand Down
98 changes: 41 additions & 57 deletions api-services/mutations/tasks/patient_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
CreatePatientRequest,
DischargePatientRequest,
GetPatientDetailsRequest,
UpdatePatientRequest,
GetPatientsByWardRequest,
AssignBedRequest,
UnassignBedRequest,
GetPatientAssignmentByWardRequest,
GetPatientListRequest,
DeletePatientRequest,
ReadmitPatientRequest,
GetRecentPatientsRequest
} from '@helpwave/proto-ts/services/task_svc/v1/patient_svc_pb'
GetRecentPatientsRequest,
GetPatientDetailsRequest,
GetPatientsByWardRequest,
GetPatientAssignmentByWardRequest,
GetPatientListRequest
} from '@helpwave/proto-ts/services/tasks_svc/v1/patient_svc_pb'
import { noop } from '@helpwave/common/util/noop'
import { APIServices } from '../../services'
import { getAuthenticatedGrpcMetadata } from '../../authentication/grpc_metadata'
Expand All @@ -29,7 +28,7 @@ import type { BedWithPatientId } from '../../types/tasks/bed'
import type { RoomWithMinimalBedAndPatient } from '../../types/tasks/room'
import { roomOverviewsQueryKey } from './room_mutations'

export const usePatientDetailsQuery = (patientId: string | undefined) => {
export const usePatientDetailsQuery = (patientId?: string) => {
return useQuery({
queryKey: [QueryKeys.patients, patientId],
enabled: !!patientId,
Expand Down Expand Up @@ -127,23 +126,15 @@ export const usePatientAssignmentByWardQuery = (wardId: string) => {
})
}

export const usePatientListQuery = (organisationId?: string, wardId?: string) => {
export const usePatientListQuery = (wardId?: string) => {
return useQuery({
queryKey: [QueryKeys.patients, 'patientList', wardId],
enabled: !!organisationId,
queryFn: async () => {
const req = new GetPatientListRequest()
if (!organisationId) {
return {
active: [],
discharged: [],
unassigned: []
}
}
if (wardId) {
req.setWardId(wardId)
}
const res = await APIServices.patient.getPatientList(req, getAuthenticatedGrpcMetadata(organisationId))
const res = await APIServices.patient.getPatientList(req, getAuthenticatedGrpcMetadata())

const patientList: PatientListDTO = {
active: res.getActiveList().map(value => {
Expand Down Expand Up @@ -206,14 +197,8 @@ export const useRecentPatientsQuery = () => {
id: patient.getId(),
name: patient.getHumanReadableIdentifier(),
wardId,
bed: bed ? {
id: bed.getId(),
name: bed.getName()
} : undefined,
room: room ? {
id: room.getId(),
name: room.getId()
} : undefined
bed: bed ? { id: bed.getId(), name: bed.getName() } : undefined,
room: room ? { id: room.getId(), name: room.getId() } : undefined
})
}

Expand All @@ -222,25 +207,22 @@ export const useRecentPatientsQuery = () => {
})
}

export const usePatientCreateMutation = (organisationId: string) => {
export const usePatientCreateMutation = () => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (patient: PatientDTO) => {
const req = new CreatePatientRequest()
.setNotes(patient.note)
.setHumanReadableIdentifier(patient.name)
const res = await APIServices.patient.createPatient(req, getAuthenticatedGrpcMetadata(organisationId))
req.setNotes(patient.note)
req.setHumanReadableIdentifier(patient.name)
const res = await APIServices.patient.createPatient(req, getAuthenticatedGrpcMetadata())

const id = res.getId()

if (!id) {
throw new Error('create room failed')
}

return {
...patient,
id
}
return { ...patient, id }
},
onSuccess: () => {
queryClient.refetchQueries([QueryKeys.rooms]).catch(reason => console.error(reason))
Expand Down Expand Up @@ -273,29 +255,6 @@ export const usePatientUpdateMutation = () => {
})
}

export const usePatientDischargeMutation = (callback: () => void = noop) => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (patientId: string) => {
const req = new DischargePatientRequest()
req.setId(patientId)

const res = await APIServices.patient.dischargePatient(req, getAuthenticatedGrpcMetadata())

if (!res.toObject()) {
throw new Error('error in PatientDischarge')
}

callback()
return res.toObject()
},
onSuccess: () => {
queryClient.refetchQueries([QueryKeys.rooms, roomOverviewsQueryKey]).catch(reason => console.error(reason))
queryClient.refetchQueries([QueryKeys.patients]).catch(reason => console.error(reason))
}
})
}

export const useAssignBedMutation = (callback: (bed: BedWithPatientId) => void = noop) => {
const queryClient = useQueryClient()
return useMutation({
Expand Down Expand Up @@ -343,6 +302,7 @@ export const useUnassignMutation = (callback: () => void = noop) => {
})
}

/* TODO wait for backend decision on this
export const useDeletePatientMutation = () => {
const queryClient = useQueryClient()
return useMutation({
Expand All @@ -360,6 +320,30 @@ export const useDeletePatientMutation = () => {
}
})
}
*/

export const usePatientDischargeMutation = (callback: () => void = noop) => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (patientId: string) => {
const req = new DischargePatientRequest()
req.setId(patientId)

const res = await APIServices.patient.dischargePatient(req, getAuthenticatedGrpcMetadata())

if (!res.toObject()) {
throw new Error('error in PatientDischarge')
}

callback()
return res.toObject()
},
onSuccess: () => {
queryClient.refetchQueries([QueryKeys.rooms, roomOverviewsQueryKey]).catch(reason => console.error(reason))
queryClient.refetchQueries([QueryKeys.patients]).catch(reason => console.error(reason))
}
})
}

export const useReadmitPatientMutation = (callback: (patientId: string) => void = noop) => {
const queryClient = useQueryClient()
Expand Down
2 changes: 1 addition & 1 deletion api-services/mutations/tasks/room_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
GetRoomOverviewsByWardRequest,
GetRoomRequest,
UpdateRoomRequest
} from '@helpwave/proto-ts/services/task_svc/v1/room_svc_pb'
} from '@helpwave/proto-ts/services/tasks_svc/v1/room_svc_pb'
import { noop } from '@helpwave/common/util/noop'
import type { RoomDTO, RoomMinimalDTO, RoomOverviewDTO } from '../../types/tasks/room'
import { APIServices } from '../../services'
Expand Down
Loading
Loading