Skip to content

Commit

Permalink
Merge branch 'develop' into issue#2738
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon authored Apr 20, 2023
2 parents ecb54fc + db7b9b2 commit 832b944
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 118 deletions.
13 changes: 2 additions & 11 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function AssetFilter(props: any) {
const [qParams, _] = useQueryParams();

useEffect(() => {
console.log(facility);
setFacilityId(facility?.id ? facility?.id : "");
setLocationId(location?.id ? location?.id : "");
}, [facility, location]);
Expand All @@ -62,17 +61,9 @@ function AssetFilter(props: any) {
const fetchFacility = useCallback(
async (status: statusType) => {
if (facilityId) {
const [facilityData]: any = await Promise.all([
dispatch(getAnyFacility(facilityId)),
]);
const facilityData: any = await dispatch(getAnyFacility(facilityId));
if (!status.aborted) {
if (!facilityData?.data)
Notification.Error({
msg: "Something went wrong..!",
});
else {
setFacility(facilityData.data);
}
setFacility(facilityData?.data);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Common/ConfirmDialogV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ConfirmDialogV2 = ({
onClose={onClose}
title={title}
description={
<span className={`font-medium text-${variant || "secondary"}-500`}>
<span className={`font-medium text-${variant || "secondary"}-600`}>
{description}
</span>
}
Expand Down
42 changes: 29 additions & 13 deletions src/Components/Facility/AddLocationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const AddLocationForm = (props: LocationFormProps) => {
const [description, setDescription] = useState("");
const [facilityName, setFacilityName] = useState("");
const [locationName, setLocationName] = useState("");

const [errors, setErrors] = useState<any>({
name: "",
description: "",
});
const headerText = !locationId ? "Add Location" : "Update Location";
const buttonText = !locationId ? "Add Location" : "Update Location";

Expand All @@ -56,6 +59,10 @@ export const AddLocationForm = (props: LocationFormProps) => {
}, [dispatchAction, facilityId, locationId]);

const handleSubmit = async (e: React.SyntheticEvent) => {
setErrors({
name: "",
description: "",
});
e.preventDefault();
setIsLoading(true);
const data = {
Expand All @@ -69,17 +76,26 @@ export const AddLocationForm = (props: LocationFormProps) => {
: createFacilityAssetLocation(data, facilityId)
);
setIsLoading(false);
if (res && (res.status === 201 || res.status === 200)) {
const notificationMessage = locationId
? "Location updated successfully"
: "Location created successfully";
if (res) {
if (res.status === 201 || res.status === 200) {
const notificationMessage = locationId
? "Location updated successfully"
: "Location created successfully";

navigate(`/facility/${facilityId}/location`, {
replace: true,
});
Notification.Success({
msg: notificationMessage,
});
navigate(`/facility/${facilityId}/location`, {
replace: true,
});
Notification.Success({
msg: notificationMessage,
});
} else if (res.status === 400) {
Object.keys(res.data).forEach((key) => {
setErrors((prevState: any) => ({
...prevState,
[key]: res.data[key],
}));
});
}
}
};

Expand Down Expand Up @@ -115,7 +131,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
required
value={name}
onChange={(e) => setName(e.value)}
error=""
error={errors.name}
/>
</div>
<div>
Expand All @@ -125,7 +141,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
label="Description"
value={description}
onChange={(e) => setDescription(e.value)}
error=""
error={errors.description}
/>
</div>
</div>
Expand Down
22 changes: 10 additions & 12 deletions src/Components/Facility/ConsultationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ export const ConsultationDetails = (props: any) => {
label="Discharge Date"
name="discharge_date"
value={moment(preDischargeForm.discharge_date).toDate()}
min={moment(consultationData.admission_date).toDate()}
min={moment(
consultationData.admission_date ||
consultationData.created_date
).toDate()}
disableFuture={true}
required
onChange={handleDateChange}
Expand Down Expand Up @@ -601,7 +604,10 @@ export const ConsultationDetails = (props: any) => {
label="Date of Discharge"
name="discharge_date"
value={moment(preDischargeForm.discharge_date).toDate()}
min={moment(consultationData.admission_date).toDate()}
min={moment(
consultationData.admission_date ||
consultationData.created_date
).toDate()}
disableFuture={true}
required
onChange={handleDateChange}
Expand Down Expand Up @@ -913,7 +919,7 @@ export const ConsultationDetails = (props: any) => {
{consultationData.discharge_reason === "REC" && (
<div className="grid gap-4">
<div>
Date {" - "}
Discharge Date {" - "}
<span className="font-semibold">
{consultationData.discharge_date
? formatDate(consultationData.discharge_date)
Expand Down Expand Up @@ -991,14 +997,6 @@ export const ConsultationDetails = (props: any) => {
)}
{consultationData.discharge_reason === "EXP" && (
<div className="grid gap-4">
<div>
Discharge Date {" - "}
<span className="font-semibold">
{consultationData.discharge_date
? formatDate(consultationData.discharge_date)
: "--:--"}
</span>
</div>
<div>
Date of Death {" - "}
<span className="font-semibold">
Expand Down Expand Up @@ -1027,7 +1025,7 @@ export const ConsultationDetails = (props: any) => {
) && (
<div className="grid gap-4">
<div>
Date {" - "}
Discharge Date {" - "}
<span className="font-semibold">
{consultationData.discharge_date
? formatDate(consultationData.discharge_date)
Expand Down
29 changes: 24 additions & 5 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type FormDetails = {
prn_prescription: PRNPrescriptionType[];
investigation: InvestigationType[];
is_telemedicine: BooleanStrings;
action: string;
action?: string;
assigned_to: string;
assigned_to_object: UserModel | null;
special_instruction: string;
Expand Down Expand Up @@ -141,7 +141,8 @@ type FormDetails = {

type Action =
| { type: "set_form"; form: FormDetails }
| { type: "set_error"; errors: FormDetails };
| { type: "set_error"; errors: FormDetails }
| { type: "set_form_field"; field: keyof FormDetails; value: any };

const initForm: FormDetails = {
symptoms: [],
Expand Down Expand Up @@ -174,7 +175,7 @@ const initForm: FormDetails = {
prn_prescription: [],
investigation: [],
is_telemedicine: "false",
action: "PENDING",
action: undefined,
assigned_to: "",
assigned_to_object: null,
special_instruction: "",
Expand Down Expand Up @@ -224,7 +225,7 @@ const consultationFormReducer = (state = initialState, action: Action) => {
case "set_form": {
return {
...state,
form: action.form,
form: { ...state.form, ...action.form },
};
}
case "set_error": {
Expand All @@ -233,6 +234,15 @@ const consultationFormReducer = (state = initialState, action: Action) => {
errors: action.errors,
};
}
case "set_form_field": {
return {
...state,
form: {
...state.form,
[action.field]: action.value,
},
};
}
}
};

Expand Down Expand Up @@ -330,6 +340,14 @@ export const ConsultationForm = (props: any) => {
if (res.data) {
setPatientName(res.data.name);
setFacilityName(res.data.facility_object.name);
if (isUpdate) {
dispatch({
type: "set_form_field",
field: "action",
value: TELEMEDICINE_ACTIONS.find((a) => a.id === res.data.action)
?.text,
});
}
}
} else {
setPatientName("");
Expand Down Expand Up @@ -1578,13 +1596,14 @@ export const ConsultationForm = (props: any) => {
{...selectField("review_interval")}
label="Review After"
options={REVIEW_AT_CHOICES}
position="above"
/>
</div>
<div className="flex-1" ref={fieldRef["action"]}>
<SelectFormField
{...field("action")}
label="Action"
required
position="above"
options={TELEMEDICINE_ACTIONS}
optionLabel={(option) => option.desc}
optionValue={(option) => option.text}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const LocationRow = (props: LocationRowProps) => {
>
<div className="px-4 lg:w-3/4">
<div className="lg:flex items-baseline w-full">
<p className="text-xl capitalize break-words lg:w-1/4 lg:mr-4">
{name}
</p>
<p className="text-xl break-words lg:w-1/4 lg:mr-4">{name}</p>
<p className="text-sm break-all lg:w-3/4">{description}</p>
</div>
</div>
Expand Down
59 changes: 37 additions & 22 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,44 @@ export default function PatientInfoCard(props: {
);
})}
</div>
<div className="flex gap-4 text-sm mt-3 px-3 py-1 font-medium bg-cyan-300">
<div>
{
CONSULTATION_SUGGESTION.find(
(suggestion) => suggestion.id === consultation?.suggestion
)?.text
}{" "}
on{" "}
{consultation?.suggestion === "A"
? moment(consultation?.admission_date).format("DD/MM/YYYY")
: consultation?.suggestion === "DD"
? moment(consultation?.death_datetime).format("DD/MM/YYYY")
: moment(consultation?.created_date).format("DD/MM/YYYY")}
{patient.is_active === false && (
<div className="flex gap-4 text-sm mt-3 px-3 py-1 font-medium bg-cyan-300">
<div>
<span>
{
CONSULTATION_SUGGESTION.find(
(suggestion) =>
suggestion.id === consultation?.suggestion
)?.text
}{" "}
on{" "}
{consultation?.suggestion === "A"
? moment(consultation?.admission_date).format(
"DD/MM/YYYY"
)
: moment(consultation?.created_date).format("DD/MM/YYYY")}
,
{consultation?.discharge_reason === "EXP" ? (
<span>
{" "}
Expired on{" "}
{moment(consultation?.death_datetime).format(
"DD/MM/YYYY"
)}
</span>
) : (
<span>
{" "}
Discharged on{" "}
{moment(consultation?.discharge_date).format(
"DD/MM/YYYY"
)}
</span>
)}
</span>
</div>
</div>
{patient.is_active === false &&
consultation?.suggestion !== "OP" &&
consultation?.suggestion !== "DD" && (
<div>
Discharged on{" "}
{moment(consultation?.discharge_date).format("DD/MM/YYYY")}
</div>
)}
</div>
)}
</div>
</div>

Expand Down
Loading

0 comments on commit 832b944

Please sign in to comment.