Skip to content

Commit

Permalink
feat: allow looking at discharged patients (#951)
Browse files Browse the repository at this point in the history
* feat: allow looking at discharged patients

* chore: rename mutation variable

Co-authored-by: Max Schäfer <[email protected]>

* fix: rename all variable usages

---------

Co-authored-by: Max Schäfer <[email protected]>
  • Loading branch information
DasProffi and MaxSchaefer authored Apr 1, 2024
1 parent bc5fe34 commit 41499b1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 49 additions & 13 deletions tasks/components/layout/PatientDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
usePatientDischargeMutation,
usePatientUpdateMutation,
useUnassignMutation,
type PatientDetailsDTO
type PatientDetailsDTO, useReadmitPatientMutation
} from '@/mutations/patient_mutations'
import { PatientDischargeModal } from '@/components/modals/PatientDischargeModal'
import { TaskDetailModal } from '@/components/modals/TaskDetailModal'
Expand All @@ -31,7 +31,8 @@ type PatientDetailTranslation = {
dischargeConfirmText: string,
dischargePatient: string,
saved: string,
unassign: string
unassign: string,
readmit: string
}

const defaultPatientDetailTranslations: Record<Languages, PatientDetailTranslation> = {
Expand All @@ -42,7 +43,8 @@ const defaultPatientDetailTranslations: Record<Languages, PatientDetailTranslati
dischargeConfirmText: 'Do you really want to discharge the patient?',
dischargePatient: 'Discharge Patient',
saved: 'Saved',
unassign: 'Unassign'
unassign: 'Unassign',
readmit: 'Readmit'
},
de: {
patientDetails: 'Details',
Expand All @@ -51,7 +53,8 @@ const defaultPatientDetailTranslations: Record<Languages, PatientDetailTranslati
dischargeConfirmText: 'Willst du den Patienten wirklich entlassen?',
dischargePatient: 'Patienten entlassen',
saved: 'Gespeichert',
unassign: 'Zuweisung aufheben'
unassign: 'Zuweisung aufheben',
readmit: 'Wiederzuweisen'
}
}

Expand All @@ -75,9 +78,14 @@ export const PatientDetail = ({
const context = useContext(WardOverviewContext)

const updateMutation = usePatientUpdateMutation()
const readmitMutation = useReadmitPatientMutation()
const dischargeMutation = usePatientDischargeMutation(() => context.updateContext({ wardId: context.state.wardId }))
const unassignMutation = useUnassignMutation(() => context.updateContext({ wardId: context.state.wardId }))
const { data, isError, isLoading } = usePatientDetailsQuery(context.state.patientId)
const {
data,
isError,
isLoading
} = usePatientDetailsQuery(context.state.patientId)

const [newPatient, setNewPatient] = useState<PatientDetailsDTO>(patient)
const [taskId, setTaskId] = useState<string>()
Expand All @@ -97,7 +105,10 @@ export const PatientDetail = ({
setIsSubmitting(false)
})

const { restartTimer, clearUpdateTimer } = useSaveDelay(setIsShowingSavedNotification, 3000)
const {
restartTimer,
clearUpdateTimer
} = useSaveDelay(setIsShowingSavedNotification, 3000)

const changeSavedValue = (patient: PatientDetailsDTO) => {
setNewPatient(patient)
Expand Down Expand Up @@ -154,16 +165,26 @@ export const PatientDetail = ({
className={tw('text-lg font-semibold')}
id="humanReadableIdentifier"
value={newPatient.name}
onChange={name => changeSavedValue({ ...newPatient, name })}
onChange={name => changeSavedValue({
...newPatient,
name
})}
/>
</div>
<RoomBedSelect
initialRoomAndBed={{ roomId: context.state.roomId ?? '', bedId: context.state.bedId ?? '' }}
initialRoomAndBed={{
roomId: context.state.roomId ?? '',
bedId: context.state.bedId ?? ''
}}
wardId={context.state.wardId}
onChange={(roomBedDropdownIds) => {
if (roomBedDropdownIds.bedId && context.state.patientId) {
readmitMutation.mutate(newPatient.id)
context.updateContext({ ...context.state, ...roomBedDropdownIds })
assignBedMutation.mutate({ id: roomBedDropdownIds.bedId, patientId: context.state.patientId })
assignBedMutation.mutate({
id: roomBedDropdownIds.bedId,
patientId: context.state.patientId
})
}
}}
isSubmitting={isSubmitting}
Expand All @@ -173,7 +194,10 @@ export const PatientDetail = ({
<Textarea
headline={translation.notes}
value={newPatient.note}
onChange={text => changeSavedValue({ ...newPatient, note: text })}
onChange={text => changeSavedValue({
...newPatient,
note: text
})}
/>
</div>
</div>
Expand All @@ -189,9 +213,21 @@ export const PatientDetail = ({
/>
)}
<div className={tw('flex flex-row justify-end mt-8 gap-x-4')}>
<Button color="warn" onClick={() => unassignMutation.mutate(newPatient.id)}>{translation.unassign}</Button>
<Button color="negative"
onClick={() => setIsShowingDischargeDialog(true)}>{translation.dischargePatient}</Button>
{!newPatient.discharged ?
(
<>
<Button color="warn" onClick={() => unassignMutation.mutate(newPatient.id)}>
{translation.unassign}
</Button>
<Button color="negative" onClick={() => setIsShowingDischargeDialog(true)} >
{translation.dischargePatient}
</Button>
</>
) : (
<Button color="positive" onClick={() => readmitMutation.mutate(newPatient.id)} >
{translation.readmit}
</Button>
)}
<Button color="accent" onClick={() => {
clearUpdateTimer(true)
updateMutation.mutate(newPatient)
Expand Down
4 changes: 4 additions & 0 deletions tasks/components/layout/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export const PatientList = ({
<div
key={patient.id}
className={tw('flex flex-row pt-2 border-b-2 justify-between items-center')}
onClick={() => updateContext({
wardId: context.wardId,
patientId: patient.id
})}
>
<Span className={tw('font-space font-bold')}>{patient.name}</Span>
<div className={tw('flex flex-row gap-x-4')}>
Expand Down
9 changes: 6 additions & 3 deletions tasks/mutations/patient_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
GetRecentPatientsRequest
} from '@helpwave/proto-ts/proto/services/task_svc/v1/patient_svc_pb'
import { noop } from '@helpwave/common/util/noop'
import { patientService, getAuthenticatedGrpcMetadata } from '../utils/grpc'
import type { TaskDTO, TaskMinimalDTO } from './task_mutations'
import type { BedWithPatientId } from './bed_mutations'
import { patientService, getAuthenticatedGrpcMetadata } from '@/utils/grpc'
import { roomOverviewsQueryKey, roomsQueryKey, type RoomWithMinimalBedAndPatient } from '@/mutations/room_mutations'

export type PatientMinimalDTO = {
Expand Down Expand Up @@ -78,14 +78,16 @@ export type PatientWithBedIdDTO = PatientMinimalDTO & {

export type PatientDetailsDTO = PatientMinimalDTO & {
note: string,
tasks: TaskDTO[]
tasks: TaskDTO[],
discharged: boolean
}

export const emptyPatientDetails: PatientDetailsDTO = {
id: '',
name: '',
note: '',
tasks: []
tasks: [],
discharged: false
}

const patientsQueryKey = 'patients'
Expand Down Expand Up @@ -118,6 +120,7 @@ export const usePatientDetailsQuery = (patientId: string | undefined) => {
id: res.getId(),
note: res.getNotes(),
name: res.getName(),
discharged: res.getIsDischarged(),
tasks: res.getTasksList().map(task => ({
id: task.getId(),
name: task.getName(),
Expand Down
2 changes: 1 addition & 1 deletion tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@dnd-kit/sortable": "7.0.2",
"@headlessui/react": "1.7.18",
"@helpwave/common": "workspace:*",
"@helpwave/proto-ts": "0.37.0-bc90f4d.0",
"@helpwave/proto-ts": "0.40.1-2bb3d30.0",
"@radix-ui/react-checkbox": "1.0.4",
"@tanstack/react-query": "4.36.1",
"@tanstack/react-query-devtools": "5.28.8",
Expand Down

0 comments on commit 41499b1

Please sign in to comment.