Files
astra-frontend/src/pages/oldMedicalCard/utils/wrapperMedicalCard.js

227 lines
6.4 KiB
JavaScript

import { fetchWrapper } from "@/shared/fetchWrapper";
import moment from "moment";
export function requestCreateMedicalCard(entry, key, id) {
const url = `medical_card/${key}/create/`;
let arrayValue;
if (["tonometry", "dental_bite", "dmf_index"].includes(key)) {
arrayValue = entry.split(",");
}
switch (key) {
case "complaints":
case "medications_taken":
case "disease_progress":
case "visual_examination":
case "diagnostic_findings":
case "survey_plan":
case "treatment_plan":
case "treatment_protocol":
return fetchWrapper.post(url, {
title: entry,
description: entry,
medical_history: id,
});
case "thermometry":
return fetchWrapper.post(url, {
title: entry,
temperature: Number(entry),
medical_history: id,
});
case "tonometry":
return fetchWrapper.post(url, {
title: entry,
sys: Number(arrayValue[0]),
dia: Number(arrayValue[1]),
pul: Number(arrayValue[2]),
medical_history: id,
});
case "dental_bite":
return fetchWrapper.post(url, {
custom: arrayValue[0],
physiological: arrayValue[1],
abnormal: arrayValue[2],
medical_history: id,
});
case "dmf_index":
return fetchWrapper.post(url, {
caries: Number(arrayValue[0]),
filling: Number(arrayValue[1]),
remote: Number(arrayValue[2]),
medical_history: id,
});
case "clinical_diagnosis":
return fetchWrapper.post(url, {
title: entry,
description: "string",
medical_history: id,
icd10: id,
});
case "dental_formula":
return fetchWrapper.post(url, {
...entry,
tooth_mobility: entry.tooth_mobility ? entry.tooth_mobility.label : "",
tooth_number: entry.tooth_number,
medical_history: id,
});
case "registration_address":
return fetchWrapper.post(`general/address/create/`, {
...entry,
person: id,
registration_flg: true,
});
case "temporary_address":
return fetchWrapper.post(`general/address/create/`, {
...entry,
person: id,
temporary_registration_flg: true,
});
case "identity_document":
return fetchWrapper.post(`general/identity_document/create/`, {
...entry,
person: id,
});
case "insurance_policy":
return fetchWrapper.post(`general/insurance_policy/create/`, {
...entry,
title: "string",
person: id,
});
}
}
export function requestUpdateMedicalCard(entry, key, id) {
const url = `medical_card/${key}/${id}/update/`;
let arrayValue;
if (["tonometry", "dental_bite", "dmf_index"].includes(key)) {
arrayValue = entry.split(",");
}
switch (key) {
case "complaints":
case "medications_taken":
case "disease_progress":
case "visual_examination":
case "diagnostic_findings":
case "survey_plan":
case "treatment_plan":
case "treatment_protocol":
return fetchWrapper.post(url, {
title: entry,
description: entry,
});
case "thermometry":
return fetchWrapper.post(url, {
title: entry,
temperature: Number(entry),
});
case "tonometry":
return fetchWrapper.post(url, {
title: entry,
sys: Number(arrayValue[0]),
dia: Number(arrayValue[1]),
pul: Number(arrayValue[2]),
});
case "dental_bite":
return fetchWrapper.post(url, {
custom: entry,
physiological: entry,
abnormal: entry,
});
case "dmf_index":
return fetchWrapper.post(url, {
caries: Number(entry),
filling: Number(entry),
remote: Number(entry),
});
case "clinical_diagnosis":
return fetchWrapper.post(url, {
title: entry,
description: "string",
icd10: id,
});
case "dental_formula":
return fetchWrapper.post(url, {
...entry,
tooth_mobility: entry.tooth_mobility ? entry.tooth_mobility.label : "",
tooth_number: entry.tooth_number,
});
case "registration_address":
return fetchWrapper.post(`general/address/${id}/update/`, {
...entry,
registration_flg: true,
});
case "temporary_address":
return fetchWrapper.post(`general/address/${id}/update/`, {
...entry,
temporary_registration_flg: true,
});
case "identity_document":
return fetchWrapper.post(`general/identity_document/${id}/update/`, {
...entry,
});
case "insurance_policy":
return fetchWrapper.post(`general/insurance_policy/${id}/update/`, {
...entry,
title: "string",
});
case "person":
return fetchWrapper.post(`general/person/${id}/update/`, {
...entry,
});
}
}
export function getRequestDataPerson(person, dental) {
const dataPersonRequest = {
identity_document: {
issued_by_org: person.issued_by_org,
issued_by_org_code: person.issued_by_org_code,
issued_by_date: moment(person.issued_by_date).format("YYYY-MM-DD"),
number: person.number_series.split(" ")[1],
series: person.number_series.split(" ")[0],
},
registration_address: {
full_address: person.registration_address,
},
temporary_address: {
full_address: person.temporary_address,
},
insurance_policy: {
series: person.policy_series,
number: person.policy_number,
organization: person.policy_organization,
},
person: {
insurance_number: person.insurance_number,
benefit_code: person.benefit_code,
allergic: dental.allergic,
},
agreement: {
agreement: person.agreement,
},
};
return dataPersonRequest;
}
export function getDentalEntiesValue(data, key) {
switch (key) {
case "complaints":
case "medications_taken":
case "disease_progress":
case "visual_examination":
case "diagnostic_findings":
case "survey_plan":
case "treatment_plan":
case "treatment_protocol":
case "clinical_diagnosis":
return data?.description;
case "thermometry":
return `${data?.temperature}`;
case "tonometry":
return `${data?.sys},${data?.dia},${data?.pul}`;
case "dental_bite":
return `${data?.custom},${data?.physiological},${data?.abnormal}`;
case "dmf_index":
return data["index_calculation"];
case "hygiene_index":
return data["index_calculation"];
}
}