Fakultas Ilmu Komputer UI

Commit d2215d0f authored by Irwanto's avatar Irwanto
Browse files

Merge branch 'irwanto/fix-monitoring-case-creation' into 'staging'

Fix monitoring case creation on investigation data edit

See merge request !27
parents 1404b8da e0c6189f
Pipeline #43930 passed with stages
in 13 minutes and 44 seconds
......@@ -133,6 +133,11 @@ it('create investigation case succesful', async () => {
const refNeededField = instance.root.find(elem => elem.props.name === "Apakah Perlu Rujukan?");
expect(refNeededField).toBeTruthy();
act(() => {
refNeededField.props.onClick(true);
})
const medicalRefField = instance.root.find(elem => elem.props.name === "Fasilitas Kesehatan Rujukan");
expect(medicalRefField).toBeTruthy();
......
......@@ -23,6 +23,7 @@ const ContactInvestigationFormStep4 = () => {
}
}
const [form, setField] = useFormState(fieldsFormat);
const [show, setShow] = useState(true);
const [isLoading, setIsLoading] = useState<boolean>(false);
const global = useContext(AppContext);
const { services: { main } } = useContext(AppContext);
......@@ -97,7 +98,8 @@ const ContactInvestigationFormStep4 = () => {
}
/>
<Gap axis={Gap.Axis.Vertical} gap={24}></Gap>
<Field
{ form.fields.is_referral_needed.value == true &&
<Field
name="Kecamatan Rujukan"
isRequired={false}
type={Field.Type.Dropdown}
......@@ -105,20 +107,24 @@ const ContactInvestigationFormStep4 = () => {
value={form.fields.medical_facility_district.value}
placeholder="Pilih Kecamatan"
updateValue={(val) => updateDistrict(val)}
/>
/>
}
{ form.fields.is_referral_needed.value == true &&
<Field
name="Fasilitas Kesehatan Rujukan"
isRequired={false}
type={Field.Type.Dropdown}
values={
FASKES_VALUES.filter(obj => {
return obj.label.includes(form.fields.medical_facility_district.value);
})
}
value={form.fields.medical_facility_reference.value}
placeholder="Pilih Fasilitas Kesehatan"
updateValue={(val) => onFormChange('medical_facility_reference', val)}
/>
name="Fasilitas Kesehatan Rujukan"
isRequired={false}
type={Field.Type.Dropdown}
values={
FASKES_VALUES.filter(obj => {
return obj.label.includes(form.fields.medical_facility_district.value);
})
}
value={form.fields.medical_facility_reference.value}
placeholder="Pilih Fasilitas Kesehatan"
updateValue={(val) => onFormChange('medical_facility_reference', val)}
/>
}
<Box axis={Box.Axis.Horizontal}>
<Button
id="previous"
......@@ -167,6 +173,18 @@ const ContactInvestigationFormStep4 = () => {
await main.createMonitoringCase({
"investigation_case": investigationResponse.data.id,
})
} else if (formData.is_edit && form.fields.is_referral_needed.value) {
const monitoringResponse = await main.findMonitoringCase(investigationResponse.data.id);
if (monitoringResponse.data.count == 0) {
await main.createMonitoringCase({
"investigation_case": investigationResponse.data.id,
})
}
} else if (formData.is_edit && !form.fields.is_referral_needed.value) {
const monitoringResponse = await main.findMonitoringCase(investigationResponse.data.id);
if (monitoringResponse.data.count == 1) {
await main.deleteMonitoringCase(monitoringResponse.data.results[0].id);
}
}
setIsLoading(false);
......
......@@ -61,6 +61,7 @@ export default function useMainService(token: string) {
// User
async function login(body: LoginFormType) {
console.log(API_MAIN_URL)
return fetchWithoutAuthentication(END_POINTS.LOGIN, Method.POST, body);
}
......@@ -244,6 +245,22 @@ export default function useMainService(token: string) {
return fetchWithAuthentication(endpoint, Method.PUT, body);
}
async function findMonitoringCase(id: string) {
const endpoint = END_POINTS.MONITORING_CASES([
null,
`?investigation_case__id=${id}`,
]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET)
}
async function deleteMonitoringCase(id: string) {
const endpoint = END_POINTS.MONITORING_CASES([
null,
id,
]);
return fetchWithAuthentication(endpoint, Method.DELETE)
}
return {
// Authentication
login,
......@@ -266,6 +283,8 @@ export default function useMainService(token: string) {
listMonitoringCases,
filterMonitoringCase,
updateMonitoringCase,
findMonitoringCase,
deleteMonitoringCase,
searchMonitoringCase,
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment