Step F8:药品管理(IMP)
This commit is contained in:
@@ -3,6 +3,7 @@ import { ElMessage } from "element-plus";
|
||||
import router from "../router";
|
||||
import { getToken, clearToken } from "../utils/auth";
|
||||
import type { ApiError } from "../types/api";
|
||||
import { useStudyStore } from "../store/study";
|
||||
|
||||
const instance: AxiosInstance = axios.create({
|
||||
baseURL: "/",
|
||||
@@ -23,6 +24,16 @@ instance.interceptors.response.use(
|
||||
async (error: AxiosError<ApiError>) => {
|
||||
const status = error.response?.status;
|
||||
const data = error.response?.data;
|
||||
// 如果当前项目不存在或已失效,清理项目并跳到项目列表
|
||||
if (status === 404 && typeof data?.message === "string" && data.message.toLowerCase().includes("study")) {
|
||||
try {
|
||||
const studyStore = useStudyStore();
|
||||
studyStore.clearCurrentStudy();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
router.push("/studies");
|
||||
}
|
||||
if (status === 401) {
|
||||
clearToken();
|
||||
ElMessage.error(data?.message || "登录已过期,请重新登录");
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { apiGet, apiPatch, apiPost } from "./axios";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export interface ImpBatch {
|
||||
id: string;
|
||||
study_id: string;
|
||||
product_id: string;
|
||||
batch_no: string;
|
||||
expiry_date?: string | null;
|
||||
manufacture_date?: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const fetchImpBatches = (
|
||||
studyId: string,
|
||||
params?: Record<string, any>
|
||||
): Promise<AxiosResponse<ApiListResponse<ImpBatch>>> =>
|
||||
apiGet(`/api/v1/studies/${studyId}/imp/batches/`, { params });
|
||||
|
||||
export const createImpBatch = (
|
||||
studyId: string,
|
||||
payload: Record<string, any>
|
||||
): Promise<AxiosResponse<ImpBatch>> =>
|
||||
apiPost(`/api/v1/studies/${studyId}/imp/batches/`, payload);
|
||||
|
||||
export const updateImpBatch = (
|
||||
studyId: string,
|
||||
batchId: string,
|
||||
payload: Record<string, any>
|
||||
): Promise<AxiosResponse<ImpBatch>> =>
|
||||
apiPatch(`/api/v1/studies/${studyId}/imp/batches/${batchId}`, payload);
|
||||
@@ -0,0 +1,16 @@
|
||||
import { apiGet } from "./axios";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export interface ImpInventoryRow {
|
||||
site_id: string;
|
||||
batch_id: string;
|
||||
quantity_on_hand: number;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const fetchImpInventory = (
|
||||
studyId: string,
|
||||
params?: Record<string, any>
|
||||
): Promise<AxiosResponse<ApiListResponse<ImpInventoryRow>>> =>
|
||||
apiGet(`/api/v1/studies/${studyId}/imp/inventory/`, { params });
|
||||
@@ -0,0 +1,34 @@
|
||||
import { apiGet, apiPatch, apiPost } from "./axios";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export interface ImpProduct {
|
||||
id: string;
|
||||
study_id: string;
|
||||
name: string;
|
||||
form?: string | null;
|
||||
strength?: string | null;
|
||||
unit: string;
|
||||
description?: string | null;
|
||||
is_active: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const fetchImpProducts = (
|
||||
studyId: string
|
||||
): Promise<AxiosResponse<ApiListResponse<ImpProduct>>> =>
|
||||
apiGet(`/api/v1/studies/${studyId}/imp/products/`);
|
||||
|
||||
export const createImpProduct = (
|
||||
studyId: string,
|
||||
payload: Record<string, any>
|
||||
): Promise<AxiosResponse<ImpProduct>> =>
|
||||
apiPost(`/api/v1/studies/${studyId}/imp/products/`, payload);
|
||||
|
||||
export const updateImpProduct = (
|
||||
studyId: string,
|
||||
productId: string,
|
||||
payload: Record<string, any>
|
||||
): Promise<AxiosResponse<ImpProduct>> =>
|
||||
apiPatch(`/api/v1/studies/${studyId}/imp/products/${productId}`, payload);
|
||||
@@ -0,0 +1,30 @@
|
||||
import { apiGet, apiPost } from "./axios";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export interface ImpTransaction {
|
||||
id: string;
|
||||
study_id: string;
|
||||
site_id: string;
|
||||
batch_id: string;
|
||||
subject_id?: string | null;
|
||||
tx_type: string;
|
||||
quantity: number;
|
||||
tx_date: string;
|
||||
reference?: string | null;
|
||||
notes?: string | null;
|
||||
created_by: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export const fetchImpTransactions = (
|
||||
studyId: string,
|
||||
params?: Record<string, any>
|
||||
): Promise<AxiosResponse<ApiListResponse<ImpTransaction>>> =>
|
||||
apiGet(`/api/v1/studies/${studyId}/imp/transactions/`, { params });
|
||||
|
||||
export const createImpTransaction = (
|
||||
studyId: string,
|
||||
payload: Record<string, any>
|
||||
): Promise<AxiosResponse<ImpTransaction>> =>
|
||||
apiPost(`/api/v1/studies/${studyId}/imp/transactions/`, payload);
|
||||
Reference in New Issue
Block a user