Files
astra-frontend/src/store/modules/medicalCard.js

74 lines
1.9 KiB
JavaScript

import { fetchWrapper } from "@/shared/fetchWrapper";
const state = () => ({
medicalCard: {},
avatar: "",
});
const getters = {
getBasicData(state) {
let registrationAddress =
state.medicalCard?.person?.address?.find((el) => el.registration_flg) ||
{};
let residenceAddress =
state?.medicalCard?.person?.address?.find((el) => el.residence_flg) || {};
let person = state.medicalCard.person;
return {
basicData: {
last_name: person?.last_name,
first_name: person?.first_name,
patronymic: person?.patronymic,
gender: person?.gender,
birth_date: person?.birth_date
? new Date(person?.birth_date)
: new Date(),
photo: person?.photo,
},
registrationAddress: {
region: registrationAddress?.region,
city: registrationAddress?.city,
street: registrationAddress?.street,
house_number: registrationAddress?.house_number,
apartment_number: registrationAddress?.apartment_number,
},
residenceAddress: {
region: residenceAddress?.region,
city: residenceAddress?.city,
street: residenceAddress?.street,
house_number: residenceAddress?.house_number,
apartment_number: residenceAddress?.apartment_number,
},
};
},
getAvatar(state) {
let lastName = state?.medicalCard?.person?.last_name;
let firstName = state?.medicalCard?.person?.first_name;
return lastName?.[0] + firstName?.[0];
},
};
const actions = {
getMedicalCardData({ commit }) {
fetchWrapper
.get(
`medical_card/medical_history/${localStorage.getItem(
"medicalId"
)}/detail/`
)
.then((res) => commit("setMedicalCard", res));
},
};
const mutations = {
setMedicalCard(state, card) {
state.medicalCard = card;
},
};
export default {
state,
getters,
actions,
mutations,
};