254 lines
5.2 KiB
TypeScript
254 lines
5.2 KiB
TypeScript
import { request } from "./http";
|
|
|
|
export interface Intervention {
|
|
id?: number;
|
|
client_id: number;
|
|
deceased_id: number;
|
|
order_giver?: string;
|
|
location_id?: number;
|
|
type?: string;
|
|
scheduled_at?: string;
|
|
duration_min?: number;
|
|
status?: string;
|
|
assigned_practitioner_id?: number;
|
|
attachments_count?: number;
|
|
notes?: string;
|
|
created_by?: number;
|
|
// Relations
|
|
client?: any;
|
|
deceased?: any;
|
|
practitioner?: any;
|
|
location?: any;
|
|
// Timestamps
|
|
created_at?: string;
|
|
updated_at?: string;
|
|
}
|
|
|
|
export interface InterventionListResponse {
|
|
data: Intervention[];
|
|
meta?: {
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
}
|
|
|
|
export interface InterventionResponse {
|
|
data: Intervention;
|
|
}
|
|
|
|
export interface CreateInterventionPayload {
|
|
client_id: number;
|
|
deceased_id: number;
|
|
order_giver?: string;
|
|
location_id?: number;
|
|
type?: string;
|
|
scheduled_at?: string;
|
|
duration_min?: number;
|
|
status?: string;
|
|
assigned_practitioner_id?: number;
|
|
notes?: string;
|
|
created_by?: number;
|
|
}
|
|
|
|
export interface UpdateInterventionPayload
|
|
extends Partial<CreateInterventionPayload> {
|
|
id: number;
|
|
}
|
|
|
|
export const InterventionService = {
|
|
/**
|
|
* Get all interventions with pagination and filters
|
|
*/
|
|
async getAllInterventions(params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
search?: string;
|
|
deceased_id?: number;
|
|
client_id?: number;
|
|
status?: string;
|
|
scheduled_at?: string;
|
|
sort_by?: string;
|
|
sort_order?: "asc" | "desc";
|
|
}): Promise<InterventionListResponse> {
|
|
const response = await request<InterventionListResponse>({
|
|
url: "/api/interventions",
|
|
method: "get",
|
|
params,
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Get a specific intervention by ID
|
|
*/
|
|
async getIntervention(id: number): Promise<Intervention> {
|
|
const response = await request<Intervention>({
|
|
url: `/api/interventions/${id}`,
|
|
method: "get",
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Create a new intervention
|
|
*/
|
|
async createIntervention(
|
|
payload: CreateInterventionPayload
|
|
): Promise<Intervention> {
|
|
const response = await request<Intervention>({
|
|
url: "/api/interventions",
|
|
method: "post",
|
|
data: payload,
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Update an existing intervention
|
|
*/
|
|
async updateIntervention(
|
|
payload: UpdateInterventionPayload
|
|
): Promise<Intervention> {
|
|
const { id, ...updateData } = payload;
|
|
|
|
const response = await request<Intervention>({
|
|
url: `/api/interventions/${id}`,
|
|
method: "put",
|
|
data: updateData,
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Delete an intervention
|
|
*/
|
|
async deleteIntervention(
|
|
id: number
|
|
): Promise<{ success: boolean; message: string }> {
|
|
const response = await request<{ success: boolean; message: string }>({
|
|
url: `/api/interventions/${id}`,
|
|
method: "delete",
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Get interventions by deceased ID
|
|
*/
|
|
async getInterventionsByDeceased(
|
|
deceasedId: number,
|
|
params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
}
|
|
): Promise<InterventionListResponse> {
|
|
const response = await request<InterventionListResponse>({
|
|
url: `/api/deceased/${deceasedId}/interventions`,
|
|
method: "get",
|
|
params,
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Get interventions by client ID
|
|
*/
|
|
async getInterventionsByClient(
|
|
clientId: number,
|
|
params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
}
|
|
): Promise<InterventionListResponse> {
|
|
const response = await request<InterventionListResponse>({
|
|
url: `/api/clients/${clientId}/interventions`,
|
|
method: "get",
|
|
params,
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Search interventions by various criteria
|
|
*/
|
|
async searchInterventions(
|
|
query: string,
|
|
params?: {
|
|
exact_match?: boolean;
|
|
}
|
|
): Promise<Intervention[]> {
|
|
const response = await request<{
|
|
data: Intervention[];
|
|
count: number;
|
|
message: string;
|
|
}>({
|
|
url: "/api/interventions/search",
|
|
method: "get",
|
|
params: {
|
|
search: query,
|
|
exact_match: params?.exact_match || false,
|
|
},
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* Update intervention status
|
|
*/
|
|
async updateInterventionStatus(
|
|
id: number,
|
|
status: string
|
|
): Promise<Intervention> {
|
|
const response = await request<Intervention>({
|
|
url: `/api/interventions/${id}/status`,
|
|
method: "patch",
|
|
data: { status },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Assign practitioner to intervention
|
|
*/
|
|
async assignPractitioner(
|
|
id: number,
|
|
practitionerId: number
|
|
): Promise<Intervention> {
|
|
const response = await request<Intervention>({
|
|
url: `/api/interventions/${id}/assign`,
|
|
method: "patch",
|
|
data: { assigned_practitioner_id: practitionerId },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
|
|
/**
|
|
* Get interventions by month
|
|
*/
|
|
async getInterventionsByMonth(
|
|
year: number,
|
|
month: number
|
|
): Promise<InterventionListResponse> {
|
|
const response = await request<InterventionListResponse>({
|
|
url: "/api/interventions/by-month",
|
|
method: "get",
|
|
params: { year, month },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
};
|
|
|
|
export default InterventionService;
|