Skip to content

Commit

Permalink
Disable multiple buttons for discharged patients (ohcnetwork#7730)
Browse files Browse the repository at this point in the history
* UPDATE: reverted formatting changes to other files

* UPDATE: requested code changes
  • Loading branch information
alanansari authored May 7, 2024
1 parent d5d9ee9 commit d807434
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DefaultLogUpdateCard = ({ round, ...props }: Props) => {
</ButtonV2>
<ButtonV2
variant="secondary"
disabled={!!props.consultationData?.discharge_date}
border
ghost
size="small"
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Facility/Investigations/InvestigationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const TestRow = ({ data, i, onChange, showForm, value, isChanged }: any) => {
export const InvestigationTable = ({
title,
data,
isDischargedPatient,
handleValueChange,
changedFields,
handleUpdateCancel,
Expand Down Expand Up @@ -94,6 +95,7 @@ export const InvestigationTable = ({
Print Report
</ButtonV2>
<ButtonV2
disabled={isDischargedPatient}
variant="primary"
className="my-2 mr-2"
onClick={() => {
Expand Down
6 changes: 6 additions & 0 deletions src/Components/Facility/Investigations/ShowInvestigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export default function ShowInvestigation(props: any) {
},
);

const { data: consultation } = useQuery(routes.getConsultation, {
pathParams: { id: consultationId },
prefetch: !!consultationId,
});

const handleValueChange = (value: any, name: string) => {
const changedFields = { ...state.changedFields };
set(changedFields, name, value);
Expand Down Expand Up @@ -151,6 +156,7 @@ export default function ShowInvestigation(props: any) {
<InvestigationTable
title={`ID: ${sessionId}`}
data={state.initialValues}
isDischargedPatient={!!consultation?.discharge_date}
changedFields={state.changedFields}
handleValueChange={handleValueChange}
handleUpdateCancel={handleUpdateCancel}
Expand Down
19 changes: 17 additions & 2 deletions src/Components/Patient/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { VoiceRecorder } from "../../Utils/VoiceRecorder";
import Pagination from "../Common/Pagination";
import { RESULTS_PER_PAGE_LIMIT } from "../../Common/constants";
import imageCompression from "browser-image-compression";
import { formatDateTime } from "../../Utils/utils";
import { classNames, formatDateTime } from "../../Utils/utils";
import { useTranslation } from "react-i18next";
import HeadedTabs from "../Common/HeadedTabs";
import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2";
Expand Down Expand Up @@ -258,6 +258,11 @@ export const FileUpload = (props: FileUploadProps) => {
prefetch: !!patientId,
});

const { data: consultation } = useQuery(routes.getConsultation, {
pathParams: { id: consultationId },
prefetch: !!consultationId,
});

const captureImage = () => {
setPreviewImage(webRef.current.getScreenshot());
const canvas = webRef.current.getCanvas();
Expand Down Expand Up @@ -1526,6 +1531,7 @@ export const FileUpload = (props: FileUploadProps) => {
)}
<div className="flex flex-col items-center gap-4 md:flex-row md:flex-wrap lg:flex-nowrap">
<VoiceRecorder
isDisabled={!!consultation?.discharge_date}
createAudioBlob={createAudioBlob}
confirmAudioBlobExists={confirmAudioBlobExists}
reset={resetRecording}
Expand Down Expand Up @@ -1586,7 +1592,14 @@ export const FileUpload = (props: FileUploadProps) => {
<AuthorizedChild authorizeFor={NonReadOnlyUsers}>
{({ isAuthorized }) =>
isAuthorized ? (
<label className="button-size-default button-shape-square button-primary-default inline-flex h-min w-full cursor-pointer items-center justify-center gap-2 whitespace-pre font-medium outline-offset-1 transition-all duration-200 ease-in-out disabled:cursor-not-allowed disabled:bg-gray-200 disabled:text-gray-500">
<label
className={classNames(
consultation?.discharge_date
? "cursor-not-allowed bg-gray-200 text-gray-500"
: "button-primary-default cursor-pointer transition-all duration-200 ease-in-out",
"button-size-default button-shape-square inline-flex h-min w-full items-center justify-center gap-2 whitespace-pre font-medium outline-offset-1",
)}
>
<CareIcon
icon="l-file-upload-alt"
className="text-lg"
Expand All @@ -1599,6 +1612,7 @@ export const FileUpload = (props: FileUploadProps) => {
type="file"
accept="image/*,video/*,audio/*,text/plain,text/csv,application/rtf,application/msword,application/vnd.oasis.opendocument.text,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet,application/pdf"
hidden
disabled={!!consultation?.discharge_date}
/>
</label>
) : (
Expand All @@ -1607,6 +1621,7 @@ export const FileUpload = (props: FileUploadProps) => {
}
</AuthorizedChild>
<ButtonV2
disabled={!!consultation?.discharge_date}
onClick={() => setModalOpenForCamera(true)}
className="w-full"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/VoiceRecorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useTranslation } from "react-i18next";
export const VoiceRecorder = (props: any) => {
const { t } = useTranslation();
const {
isDisabled,
createAudioBlob,
confirmAudioBlobExists,
reset,
Expand Down Expand Up @@ -75,6 +76,7 @@ export const VoiceRecorder = (props: any) => {
{!audioURL && (
<ButtonV2
id="record-audio"
disabled={isDisabled}
onClick={startRecording}
authorizeFor={NonReadOnlyUsers}
className="w-full md:w-fit"
Expand Down

0 comments on commit d807434

Please sign in to comment.