WIP Настроил отправление данных с формы создания медицинской карты
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
:currentStep="currentStep",
|
||||
:next-step="nextStep",
|
||||
:prev-step="prevStep",
|
||||
:finish="finishCreateCard",
|
||||
finishLabel="Создать медицинскую карту",
|
||||
flat
|
||||
)
|
||||
@@ -23,6 +24,7 @@ import BaseSelect from "@/components/base/BaseSelect";
|
||||
import MedicalBaseData from "@/pages/medicalCard/components/MedicalBaseData";
|
||||
import MedicalIdentityDocuments from "@/pages/medicalCard/components/MedicalIdentityDocuments";
|
||||
import MedicalPolicyDocuments from "@/pages/medicalCard/components/MedicalPolicyDocuments";
|
||||
import { requestMedicalCardData } from "@/pages/clients/utils/wrapperClientForm";
|
||||
import { fetchWrapper } from "@/shared/fetchWrapper.js";
|
||||
import BaseStepperQuasar from "@/components/base/BaseStepperQuasar";
|
||||
|
||||
@@ -81,17 +83,31 @@ export default {
|
||||
prevStep() {
|
||||
this.currentStep -= 1;
|
||||
},
|
||||
finish() {},
|
||||
finishCreateCard() {
|
||||
requestMedicalCardData(this.clientData, this.sourceСlientDetail).then(
|
||||
() =>
|
||||
fetchWrapper.post(`medical_card/medical_history/create/`, {
|
||||
person: this.sourceСlientDetail.id,
|
||||
organization: "3883e8f5-cede-4645-97a3-6d1511e63d10",
|
||||
agreement: false,
|
||||
})
|
||||
);
|
||||
},
|
||||
fetchClientDetail() {
|
||||
fetchWrapper
|
||||
.get(`/general/person/${this.selectedClientId}/detail/`)
|
||||
.get(`general/person/${this.selectedClientId}/detail/`)
|
||||
.then((detail) => this.saveClientDetail(detail));
|
||||
},
|
||||
saveClientDetail(detail) {
|
||||
this.sourceСlientDetail = detail;
|
||||
this.clientData = {
|
||||
id: detail.id,
|
||||
address: detail.address,
|
||||
registration_address: detail.address.find(
|
||||
(address) => address.registration_flg
|
||||
)?.join_address,
|
||||
temporary_address: detail.address.find(
|
||||
(address) => address.temporary_registration_flg
|
||||
)?.join_address,
|
||||
benefit_code: detail.benefit_code,
|
||||
birth_date: detail.birth_date ? new Date(detail.birth_date) : null,
|
||||
//contacts: detail.contacts,
|
||||
@@ -103,6 +119,9 @@ export default {
|
||||
special_mark: detail.special_mark,
|
||||
phone: detail.contacts.find((el) => el.kind === "PHONE")?.username,
|
||||
email: detail.contacts.find((el) => el.kind === "EMAIL")?.username,
|
||||
confidant_name: "",
|
||||
confidant_phone: "",
|
||||
policy: "OMS",
|
||||
};
|
||||
this.saveClientIdentityDoc(detail.identity_documents);
|
||||
this.saveCLientPolicy(detail.insurance_policy);
|
||||
@@ -133,7 +152,7 @@ export default {
|
||||
let identityDoc = data.find((el) => el.kind === "PASSPORT");
|
||||
this.clientData.identity_documents = {
|
||||
kind: "PASSPORT",
|
||||
number:
|
||||
series_number:
|
||||
identityDoc?.series && identityDoc?.number
|
||||
? `${identityDoc?.series} ${identityDoc?.number}`
|
||||
: "",
|
||||
|
||||
202
src/pages/clients/utils/wrapperClientForm.js
Normal file
202
src/pages/clients/utils/wrapperClientForm.js
Normal file
@@ -0,0 +1,202 @@
|
||||
import { fetchWrapper } from "@/shared/fetchWrapper";
|
||||
import moment from "moment/moment";
|
||||
|
||||
export async function updatePerson(data, initialData) {
|
||||
const dataPerson = {
|
||||
full_name: data.full_name,
|
||||
birth_date: moment(data.birth_date).format("YYYY-MM-DD"),
|
||||
insurance_number: data.insurance_number,
|
||||
gender: data.gender,
|
||||
benefit_code: data.benefit_code,
|
||||
};
|
||||
const notEmptyData = {};
|
||||
Object.keys(dataPerson).forEach((key) => {
|
||||
if (dataPerson[key] && initialData[key] !== dataPerson[key]) {
|
||||
notEmptyData[key] = dataPerson[key];
|
||||
}
|
||||
});
|
||||
return Object.keys(notEmptyData).length
|
||||
? fetchWrapper
|
||||
.post(`general/person/${data.id}/update/`, notEmptyData)
|
||||
.then((res) => res)
|
||||
: Promise.resolve();
|
||||
}
|
||||
|
||||
export async function requestAddress(data, initialData) {
|
||||
const registrationInit = initialData.address.find(
|
||||
(add) => add.registration_flg
|
||||
);
|
||||
const temporaryInit = initialData.address.find(
|
||||
(add) => add.temporary_registration_flg
|
||||
);
|
||||
let resultRequestRegistration = Promise.resolve();
|
||||
let resultRequestTemporary = Promise.resolve();
|
||||
if (!registrationInit && data.registration_address) {
|
||||
resultRequestRegistration = fetchWrapper.post(`general/address/create/`, {
|
||||
person: data.id,
|
||||
full_address: data.registration_address,
|
||||
registration_flg: true,
|
||||
});
|
||||
}
|
||||
if (
|
||||
registrationInit &&
|
||||
registrationInit.join_address !== data.registration_address
|
||||
) {
|
||||
resultRequestRegistration = fetchWrapper.post(
|
||||
`general/address/${registrationInit.id}/update/`,
|
||||
{
|
||||
full_address: data.registration_address,
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!temporaryInit && data.temporary_address) {
|
||||
resultRequestTemporary = fetchWrapper.post(`general/address/create/`, {
|
||||
person: data.id,
|
||||
full_address: data.temporary_address,
|
||||
temporary_registration_flg: true,
|
||||
});
|
||||
}
|
||||
if (temporaryInit && temporaryInit.join_address !== data.temporary_address) {
|
||||
resultRequestTemporary = fetchWrapper.post(
|
||||
`general/address/${registrationInit.id}/update/`,
|
||||
{
|
||||
full_address: data.temporary_address,
|
||||
}
|
||||
);
|
||||
}
|
||||
return Promise.all([resultRequestRegistration, resultRequestTemporary]);
|
||||
}
|
||||
|
||||
export async function requestContacts(data, dataInit) {
|
||||
const phoneInit = dataInit.contacts.find((el) => el.kind === "PHONE");
|
||||
const emailInit = dataInit.contacts.find((el) => el.kind === "EMAIL");
|
||||
let resultRequestPhone = Promise.resolve();
|
||||
let resultRequestEmail = Promise.resolve();
|
||||
if (!phoneInit && data.phone) {
|
||||
resultRequestPhone = fetchWrapper.post(`general/contact/create/`, {
|
||||
person: data.id,
|
||||
username: data.phone,
|
||||
kind: "PHONE",
|
||||
});
|
||||
}
|
||||
if (phoneInit && phoneInit?.username !== data.phone) {
|
||||
resultRequestPhone = fetchWrapper.post(
|
||||
`general/contact/${phoneInit.id}/update/`,
|
||||
{
|
||||
person: data.id,
|
||||
username: data.phone,
|
||||
kind: "PHONE",
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!emailInit && data.email) {
|
||||
resultRequestEmail = fetchWrapper.post(`general/contact/create/`, {
|
||||
person: data.id,
|
||||
username: data.email,
|
||||
kind: "EMAIL",
|
||||
});
|
||||
}
|
||||
if (emailInit && emailInit?.username !== data.email) {
|
||||
resultRequestEmail = fetchWrapper.post(
|
||||
`general/contact/${emailInit.id}/update/`,
|
||||
{
|
||||
person: data.id,
|
||||
username: data.email,
|
||||
kind: "EMAIL",
|
||||
}
|
||||
);
|
||||
}
|
||||
return Promise.all([resultRequestPhone, resultRequestEmail]);
|
||||
}
|
||||
|
||||
export async function requestIdentityDoc(data, dataInit) {
|
||||
let identityInit = dataInit.identity_documents.find(
|
||||
(doc) => doc.kind === "PASSPORT"
|
||||
);
|
||||
identityInit = {
|
||||
...identityInit,
|
||||
series_number:
|
||||
identityInit?.series && identityInit?.number
|
||||
? `${identityInit.series} ${identityInit.number}`
|
||||
: "",
|
||||
};
|
||||
const dataIdentity = {
|
||||
...data.identity_documents,
|
||||
issued_by_date: moment(data.identity_documents.issued_by_date).format(
|
||||
"YYYY-MM-DD"
|
||||
),
|
||||
};
|
||||
const notEmptyIdentityDoc = {};
|
||||
Object.keys(dataIdentity).forEach((key) => {
|
||||
if (dataIdentity[key] && dataIdentity[key] !== identityInit[key]) {
|
||||
notEmptyIdentityDoc[key] = dataIdentity[key];
|
||||
}
|
||||
});
|
||||
if (Object.keys(notEmptyIdentityDoc).length) {
|
||||
if (!identityInit) {
|
||||
return fetchWrapper.post(`general/identity_document/create/`, {
|
||||
...notEmptyIdentityDoc,
|
||||
person: dataInit.id,
|
||||
});
|
||||
} else {
|
||||
return fetchWrapper.post(
|
||||
`general/identity_document/${identityInit.id}/update/`,
|
||||
{
|
||||
...notEmptyIdentityDoc,
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestPolicy(data, dataInit) {
|
||||
const policyInit =
|
||||
data.policy === "OMS"
|
||||
? dataInit.insurance_policy.find((el) => el.title === "OMS")
|
||||
: dataInit.insurance_policy.find((el) => el.title === "DMS");
|
||||
const dataPolicy = data.policy === "OMS" ? data.OMSPolicy : data.DMSPolicy;
|
||||
const dataRequest = {
|
||||
organization: dataPolicy.organization,
|
||||
series: dataPolicy.number.split(" ")[0],
|
||||
number: dataPolicy.number.split(" ")[1],
|
||||
};
|
||||
const notEmptyPolicy = {};
|
||||
Object.keys(dataRequest).forEach((key) => {
|
||||
if (!policyInit && dataRequest[key]) {
|
||||
notEmptyPolicy[key] = dataRequest[key];
|
||||
}
|
||||
if (policyInit && policyInit[key] !== dataRequest[key]) {
|
||||
notEmptyPolicy[key] = dataRequest[key];
|
||||
}
|
||||
});
|
||||
if (Object.keys(notEmptyPolicy).length) {
|
||||
if (!policyInit) {
|
||||
return fetchWrapper.post(`general/insurance_policy/create/`, {
|
||||
...notEmptyPolicy,
|
||||
title: data.policy,
|
||||
person: data.id,
|
||||
});
|
||||
} else {
|
||||
return fetchWrapper.post(
|
||||
`general/insurance_policy/${policyInit.id}/update/`,
|
||||
{
|
||||
...notEmptyPolicy,
|
||||
title: data.policy,
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
export async function requestMedicalCardData(data, init) {
|
||||
return Promise.all([
|
||||
updatePerson(data, init),
|
||||
requestAddress(data, init),
|
||||
requestContacts(data, init),
|
||||
requestIdentityDoc(data, init),
|
||||
requestPolicy(data, init),
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user