Skip to content

Commit

Permalink
feat: add user and organization service and wrap services
Browse files Browse the repository at this point in the history
  • Loading branch information
DasProffi committed Aug 26, 2024
1 parent db22b83 commit 2eaa01b
Show file tree
Hide file tree
Showing 24 changed files with 658 additions and 235 deletions.
5 changes: 2 additions & 3 deletions tasks/components/cards/TaskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { Card, type CardProps } from '@helpwave/common/components/Card'
import { ProgressIndicator } from '@helpwave/common/components/ProgressIndicator'
import { Span } from '@helpwave/common/components/Span'
import { LockIcon } from 'lucide-react'
import { TaskStatus } from '@helpwave/proto-ts/services/task_svc/v1/task_svc_pb'
import type { Languages } from '@helpwave/common/hooks/useLanguage'
import { useTranslation, type PropsForTranslation } from '@helpwave/common/hooks/useTranslation'
import { Avatar } from '@helpwave/common/components/Avatar'
import type { TaskDTO } from '@/mutations/task_mutations'
import { useUserQuery } from '@/mutations/user_mutations'
import type { TaskDTO } from '@/mutations/types/task'

type TaskCardTranslation = {
assigned: string
Expand Down Expand Up @@ -38,7 +37,7 @@ export const TaskCard = ({
}: PropsForTranslation<TaskCardTranslation, TaskCardProps>) => {
const translation = useTranslation(defaultTaskCardTranslations, overwriteTranslation)
const progress = task.subtasks.length === 0 ? 1 : task.subtasks.filter(value => value.isDone).length / task.subtasks.length
const isOverDue = task.dueDate && task.dueDate < new Date() && task.status !== TaskStatus.TASK_STATUS_DONE
const isOverDue = task.dueDate && task.dueDate < new Date() && task.status !== 'done'

const { data: assignee } = useUserQuery(task.assignee)

Expand Down
4 changes: 2 additions & 2 deletions tasks/components/layout/PatientDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Textarea } from '@helpwave/common/components/user-input/Textarea'
import { ToggleableInput } from '@helpwave/common/components/user-input/ToggleableInput'
import useSaveDelay from '@helpwave/common/hooks/useSaveDelay'
import { LoadingAndErrorComponent } from '@helpwave/common/components/LoadingAndErrorComponent'
import { TaskStatus } from '@helpwave/proto-ts/services/task_svc/v1/task_svc_pb'
import { ColumnTitle } from '../ColumnTitle'
import { TasksKanbanBoard } from './TasksKanbanBoard'
import { WardOverviewContext } from '@/pages/ward/[wardId]'
Expand All @@ -24,6 +23,7 @@ import { PatientDischargeModal } from '@/components/modals/PatientDischargeModal
import { TaskDetailModal } from '@/components/modals/TaskDetailModal'
import { RoomBedSelect } from '@/components/selects/RoomBedSelect'
import { PropertyList } from '@/components/layout/property/PropertyList'
import type { TaskStatus } from '@/mutations/types/task'

type PatientDetailTranslation = {
patientDetails: string,
Expand Down Expand Up @@ -208,7 +208,7 @@ export const PatientDetail = ({
patientId={newPatient.id}
editedTaskId={taskId}
onEditTask={task => {
setInitialTaskStatus(task.status === TaskStatus.TASK_STATUS_DONE ? TaskStatus.TASK_STATUS_TODO : task.status)
setInitialTaskStatus(task.status === 'done' ? 'todo' : task.status)
setTaskId(task.id)
}}
/>
Expand Down
9 changes: 7 additions & 2 deletions tasks/components/layout/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type PatientListTranslation = {
deleteDescriptionText: string,
addPatient: string,
search: string,
bed: string
bed: string,
otherWard: string
}

const defaultPatientListTranslations: Record<Languages, PatientListTranslation> = {
Expand All @@ -56,6 +57,7 @@ const defaultPatientListTranslations: Record<Languages, PatientListTranslation>
addPatient: 'Add Patient',
search: 'Search',
bed: 'Bed',
otherWard: 'Other Ward',
},
de: {
patients: 'Patienten',
Expand All @@ -71,6 +73,7 @@ const defaultPatientListTranslations: Record<Languages, PatientListTranslation>
addPatient: 'Patient hinzufügen',
search: 'Suchen',
bed: 'Bett',
otherWard: 'Andere Station',
}
}

Expand Down Expand Up @@ -120,7 +123,9 @@ export const PatientList = ({
const [dischargingPatient, setDischargingPatient] = useState<PatientMinimalDTO>()
const [deletePatient, setDeletePatient] = useState<PatientMinimalDTO>()

const activeLabelText = (patient: PatientWithBedAndRoomDTO) => `${patient.room.name} - ${patient.bed.name}`
const activeLabelText = (patient: PatientWithBedAndRoomDTO) => patient.room.wardId === wardId
? `${patient.room.name} - ${patient.bed.name}`
: translation.otherWard

const filteredActive = !data ? [] : MultiSearchWithMapping(search, data.active, value => [value.name, activeLabelText(value)])
const filteredUnassigned = !data ? [] : SimpleSearchWithMapping(search, data.unassigned, value => value.name)
Expand Down
19 changes: 9 additions & 10 deletions tasks/components/layout/TaskDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { LoadingAndErrorComponent } from '@helpwave/common/components/LoadingAnd
import { ConfirmDialog } from '@helpwave/common/components/modals/ConfirmDialog'
import { ModalHeader } from '@helpwave/common/components/modals/Modal'
import { formatDateTime } from '@helpwave/common/util/date'
import { TaskStatus } from '@helpwave/proto-ts/services/task_svc/v1/task_svc_pb'
import { TaskTemplateListColumn } from '../TaskTemplateListColumn'
import { SubtaskView } from '../SubtaskView'
import { TaskVisibilitySelect } from '@/components/selects/TaskVisibilitySelect'
Expand All @@ -27,7 +26,6 @@ import {
} from '@/mutations/task_template_mutations'
import { useAuth } from '@/hooks/useAuth'
import {
emptyTask,
useAssignTaskToUserMutation,
useSubTaskAddMutation,
useTaskCreateMutation,
Expand All @@ -37,11 +35,12 @@ import {
useTaskToInProgressMutation,
useTaskToToDoMutation,
useTaskUpdateMutation,
useUnassignTaskToUserMutation,
type TaskDTO
useUnassignTaskToUserMutation
} from '@/mutations/task_mutations'
import { type WardWithOrganizationIdDTO, useWardQuery } from '@/mutations/ward_mutations'
import { AssigneeSelect } from '@/components/selects/AssigneeSelect'
import type { TaskDTO, TaskStatus } from '@/mutations/types/task'
import { emptyTask } from '@/mutations/types/task'

type TaskDetailViewTranslation = {
close: string,
Expand Down Expand Up @@ -224,17 +223,17 @@ const TaskDetailViewSidebar = ({
<label><Span type="labelMedium">{translation.status}</Span></label>
<TaskStatusSelect
value={task.status}
removeOptions={isCreating ? [TaskStatus.TASK_STATUS_DONE] : []}
removeOptions={isCreating ? ['done'] : []}
onChange={(status) => {
if (!isCreating) {
switch (status) {
case TaskStatus.TASK_STATUS_TODO:
case 'todo':
toToDoMutation.mutate(task.id)
break
case TaskStatus.TASK_STATUS_IN_PROGRESS:
case 'inProgress':
toInProgressMutation.mutate(task.id)
break
case TaskStatus.TASK_STATUS_DONE:
case 'done':
toDoneMutation.mutate(task.id)
break
default:
Expand Down Expand Up @@ -322,7 +321,7 @@ export const TaskDetailView = ({

const [task, setTask] = useState<TaskDTO>({
...emptyTask,
status: initialStatus ?? TaskStatus.TASK_STATUS_TODO
status: initialStatus ?? 'todo'
})

const addSubtaskMutation = useSubTaskAddMutation(taskId)
Expand Down Expand Up @@ -375,7 +374,7 @@ export const TaskDetailView = ({
<Button color="negative" onClick={() => setIsShowingDeleteDialog(true)}>
{translation.delete}
</Button>
{task.status !== TaskStatus.TASK_STATUS_DONE && (
{task.status !== 'done' && (
<Button color="positive" onClick={() => {
toDoneMutation.mutate(task.id)
onClose()
Expand Down
10 changes: 5 additions & 5 deletions tasks/components/selects/TaskStatusSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Select, type SelectProps } from '@helpwave/common/components/user-input/Select'
import { useTranslation, type PropsForTranslation } from '@helpwave/common/hooks/useTranslation'
import { TaskStatus } from '@helpwave/proto-ts/services/task_svc/v1/task_svc_pb'
import type { TaskStatus } from '@/mutations/types/task'

type TaskStatusSelectTranslation = {
unscheduled: string,
Expand Down Expand Up @@ -43,10 +43,10 @@ export const TaskStatusSelect = ({
...selectProps
}: PropsForTranslation<TaskStatusSelectTranslation, TaskStatusSelectProps>) => {
const translation = useTranslation(defaultTaskStatusSelectTranslation, overwriteTranslation)
const defaultOptions = [
{ value: TaskStatus.TASK_STATUS_TODO, label: translation.unscheduled },
{ value: TaskStatus.TASK_STATUS_IN_PROGRESS, label: translation.inProgress },
{ value: TaskStatus.TASK_STATUS_DONE, label: translation.done }
const defaultOptions: {value: TaskStatus, label: string}[] = [
{ value: 'todo', label: translation.unscheduled },
{ value: 'inProgress', label: translation.inProgress },
{ value: 'done', label: translation.done }
]

const filteredOptions = defaultOptions.filter(defaultValue => !removeOptions?.find(value2 => value2 === defaultValue.value))
Expand Down
16 changes: 8 additions & 8 deletions tasks/mutations/bed_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { roomOverviewsQueryKey, roomsQueryKey } from './room_mutations'
import type { PatientDTO, PatientMinimalDTO, PatientWithTasksNumberDTO } from './patient_mutations'
import { wardsQueryKey } from './ward_mutations'
import { bedService, getAuthenticatedGrpcMetadata } from '@/utils/grpc'
import { APIServices, getAuthenticatedGrpcMetadata } from '@/utils/grpc'

export type BedMinimalDTO = {
id: string,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const useBedQuery = (bedId: string | undefined) => {
if (bedId) {
req.setId(bedId)
}
const res = await bedService.getBed(req, getAuthenticatedGrpcMetadata())
const res = await APIServices.bed.getBed(req, getAuthenticatedGrpcMetadata())

const bed: BedWithRoomId = {
id: res.getId(),
Expand All @@ -79,7 +79,7 @@ export const useBedCreateMutation = () => {
const req = new CreateBedRequest()
req.setRoomId(bed.roomId)
req.setName(bed.name)
const res = await bedService.createBed(req, getAuthenticatedGrpcMetadata())
const res = await APIServices.bed.createBed(req, getAuthenticatedGrpcMetadata())

if (!res.toObject()) {
console.log('error in BedCreate')
Expand All @@ -88,7 +88,7 @@ export const useBedCreateMutation = () => {
return { id: res.getId(), name: bed.name }
},
onSuccess: () => {
queryClient.refetchQueries([bedService]).then()
queryClient.refetchQueries([bedQueryKey]).then()
queryClient.refetchQueries([roomsQueryKey, roomOverviewsQueryKey]).then()
queryClient.refetchQueries([wardsQueryKey]).then()
},
Expand All @@ -104,7 +104,7 @@ export const useBedUpdateMutation = () => {
req.setName(bed.name)
req.setRoomId(bed.roomId)

const res = await bedService.updateBed(req, getAuthenticatedGrpcMetadata())
const res = await APIServices.bed.updateBed(req, getAuthenticatedGrpcMetadata())

const obj = res.toObject() // TODO: what is the type of this?

Expand All @@ -115,7 +115,7 @@ export const useBedUpdateMutation = () => {
return obj
},
onSuccess: () => {
queryClient.refetchQueries([bedService]).then()
queryClient.refetchQueries([APIServices.bed]).then()
queryClient.refetchQueries([roomsQueryKey, roomOverviewsQueryKey]).then()
},
})
Expand All @@ -128,7 +128,7 @@ export const useBedDeleteMutation = () => {
const req = new DeleteBedRequest()
req.setId(bedId)

const res = await bedService.deleteBed(req, getAuthenticatedGrpcMetadata())
const res = await APIServices.bed.deleteBed(req, getAuthenticatedGrpcMetadata())

const obj = res.toObject() // TODO: what is the type of this?

Expand All @@ -139,7 +139,7 @@ export const useBedDeleteMutation = () => {
return obj
},
onSuccess: () => {
queryClient.refetchQueries([bedService]).then()
queryClient.refetchQueries([APIServices.bed]).then()
queryClient.refetchQueries([roomsQueryKey, roomOverviewsQueryKey]).then()
queryClient.refetchQueries([wardsQueryKey]).then()
},
Expand Down
35 changes: 28 additions & 7 deletions tasks/mutations/offline/services/bed_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type {
GetBedsByRoomRequest,
GetBedsRequest,
UpdateBedRequest
,
GetBedByPatientResponse

} from '@helpwave/proto-ts/services/task_svc/v1/bed_svc_pb'
import {
BulkCreateBedsResponse,
Expand All @@ -19,11 +18,15 @@ import {
GetBedsByRoomResponse,
GetBedsResponse,
UpdateBedResponse
,
GetBedByPatientResponse
} from '@helpwave/proto-ts/services/task_svc/v1/bed_svc_pb'
import { BedServicePromiseClient } from '@helpwave/proto-ts/services/task_svc/v1/bed_svc_grpc_web_pb'
import { range } from '@helpwave/common/util/array'
import { OfflineValueStore } from '@/mutations/offline/value_store'
import type { BedWithRoomId } from '@/mutations/bed_mutations'
import { PatientOfflineService } from '@/mutations/offline/services/patient_service'
import { RoomOfflineService } from '@/mutations/offline/services/room_service'

export const BedOfflineService = {
find: (id: string): BedWithRoomId | undefined => {
Expand Down Expand Up @@ -63,7 +66,10 @@ export const BedOfflineService = {
delete: (id: string) => {
const valueStore: OfflineValueStore = OfflineValueStore.getInstance()
valueStore.beds = valueStore.beds.filter(value => value.id !== id)
// TODO cascade and unassign patients
const patient = PatientOfflineService.findByBed(id)
if (patient) {
PatientOfflineService.unassignBed(patient.id)
}
}
}

Expand Down Expand Up @@ -105,10 +111,25 @@ export class BedOfflineServicePromiseClient extends BedServicePromiseClient {
.setBedsList(list)
}

async getBedByPatient(__: GetBedByPatientRequest, _?: Metadata): Promise<GetBedByPatientResponse> {
// const patientId = request.getPatientId()
throw Error('Not implemented') // TODO implement
// return new GetBedByPatientResponse()
async getBedByPatient(request: GetBedByPatientRequest, _?: Metadata): Promise<GetBedByPatientResponse> {
const patient = PatientOfflineService.find(request.getPatientId())
if (!patient) {
throw Error(`GetBedByPatient: Could not find patient with id ${request.getPatientId()}`)
}
if (!patient.bedId) {
return new GetBedByPatientResponse()
}
const bed = BedOfflineService.find(patient.bedId)
if (!bed) {
return new GetBedByPatientResponse()
}
const room = RoomOfflineService.findRoom(bed.roomId)
if (!room) {
return new GetBedByPatientResponse()
}
return new GetBedByPatientResponse()
.setBed(new GetBedByPatientResponse.Bed().setId(bed.id).setName(bed.name))
.setRoom(new GetBedByPatientResponse.Room().setId(room.id).setName(room.id).setWardId(room.wardId))
}

async createBed(request: CreateBedRequest, _?: Metadata): Promise<CreateBedResponse> {
Expand Down
Loading

0 comments on commit 2eaa01b

Please sign in to comment.