Skip to content

Commit

Permalink
added consent type update option to fix migration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Jun 6, 2024
1 parent 38587ca commit 17dccab
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
55 changes: 55 additions & 0 deletions src/Components/Patient/PatientConsentRecordBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import CareIcon from "../../CAREUI/icons/CareIcon";
import ButtonV2 from "../Common/components/ButtonV2";
import useAuthUser from "../../Common/hooks/useAuthUser";
import { PatientConsentModel } from "../Facility/models";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import { useEffect, useState } from "react";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";

export default function PatientConsentRecordBlockGroup(props: {
consentRecord: PatientConsentModel;
consultationId: string;
previewFile: (file: FileUploadModel, file_associating_id: string) => void;
archiveFile: (
file: FileUploadModel,
Expand All @@ -28,6 +33,7 @@ export default function PatientConsentRecordBlockGroup(props: {
editFile,
files,
showArchive,
consultationId,
} = props;

const authUser = useAuthUser();
Expand All @@ -36,6 +42,25 @@ export default function PatientConsentRecordBlockGroup(props: {
const consentPCS = CONSENT_PATIENT_CODE_STATUS_CHOICES.find(
(c) => c.id === consentRecord.patient_code_status,
);
const [patientCodeStatus, setPatientCodeStatus] = useState(1);

const handlePCSUpdate = async (status: number) => {
const res = await request(routes.partialUpdateConsent, {
pathParams: {
id: consentRecord.id,
consultationId: consultationId,
},
body: {
patient_code_status: status,
},
});
if (res.data) window.location.reload();
};

useEffect(() => {
if (consentRecord.patient_code_status !== null)
setPatientCodeStatus(consentRecord.patient_code_status);
}, [consentRecord]);

return (
<div
Expand All @@ -48,6 +73,36 @@ export default function PatientConsentRecordBlockGroup(props: {
</h4>
</div>
</div>
{consentRecord.type === 2 && consentRecord.patient_code_status === 0 && (
<div className="flex gap-2">
<SelectFormField
name="patient_code_status"
className="flex-1"
onChange={(e) => {
console.log(e.value);
setPatientCodeStatus(e.value);
}}
value={
CONSENT_PATIENT_CODE_STATUS_CHOICES.find(
(c) => c.id === patientCodeStatus,
)?.id
}
optionValue={(option: any) => option.id}
optionLabel={(option: any) => option.text}
options={CONSENT_PATIENT_CODE_STATUS_CHOICES}
required
error="Please select a patient code status type"
/>
<ButtonV2
onClick={() => {
handlePCSUpdate(patientCodeStatus);
}}
className="h-[46px]"
>
Update
</ButtonV2>
</div>
)}
{files?.map((file: FileUploadModel, i: number) => (
<div
key={i}
Expand Down
19 changes: 13 additions & 6 deletions src/Components/Patient/PatientConsentRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export default function PatientConsentRecords(props: {
patient_code_status: 4,
});

const refetchAll = () => {
refetch();
refetchFiles();
refetchArchivedFiles();
};

const fileUpload = useFileUpload({
type: "CONSENT_RECORD",
allowedExtensions: ["pdf", "jpg", "jpeg", "png"],
Expand All @@ -42,14 +48,10 @@ export default function PatientConsentRecords(props: {
const fileManager = useFileManager({
type: "CONSENT_RECORD",
onArchive: async () => {
refetch();
refetchFiles();
refetchArchivedFiles();
refetchAll();
},
onEdit: async () => {
refetch();
refetchFiles();
refetchArchivedFiles();
refetchAll();
},
});

Expand Down Expand Up @@ -243,6 +245,10 @@ export default function PatientConsentRecords(props: {
}
}}
loading={!!fileUpload.progress}
disabled={
newConsent.type === 2 &&
newConsent.patient_code_status === 0
}
className="flex-1"
>
<CareIcon icon="l-check" className="mr-2" />
Expand Down Expand Up @@ -289,6 +295,7 @@ export default function PatientConsentRecords(props: {
{consentRecords?.map((record, index) => (
<PatientConsentRecordBlockGroup
key={index}
consultationId={consultationId}
consentRecord={record}
previewFile={fileManager.viewFile}
archiveFile={fileManager.archiveFile}
Expand Down

0 comments on commit 17dccab

Please sign in to comment.