UI & API Data Kesehatan warga sisa 3 tabs
This commit is contained in:
139
prisma/migrations/20250624034125_24_jun2025/migration.sql
Normal file
139
prisma/migrations/20250624034125_24_jun2025/migration.sql
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- The primary key for the `DataKematian_Kelahiran` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "DataKematian_Kelahiran" DROP CONSTRAINT "DataKematian_Kelahiran_pkey",
|
||||||
|
ALTER COLUMN "id" DROP DEFAULT,
|
||||||
|
ALTER COLUMN "id" SET DATA TYPE TEXT,
|
||||||
|
ADD CONSTRAINT "DataKematian_Kelahiran_pkey" PRIMARY KEY ("id");
|
||||||
|
DROP SEQUENCE "DataKematian_Kelahiran_id_seq";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ProfilePPID" ADD COLUMN "imageUrl" TEXT;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Puskesmas" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"alamat" TEXT NOT NULL,
|
||||||
|
"jamId" TEXT NOT NULL,
|
||||||
|
"imageId" TEXT NOT NULL,
|
||||||
|
"kontakId" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "Puskesmas_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "JamOperasional" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"workDays" TEXT NOT NULL,
|
||||||
|
"weekDays" TEXT NOT NULL,
|
||||||
|
"holiday" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "JamOperasional_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "KontakPuskesmas" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"kontakPuskesmas" TEXT NOT NULL,
|
||||||
|
"email" TEXT NOT NULL,
|
||||||
|
"facebook" TEXT NOT NULL,
|
||||||
|
"kontakUGD" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "KontakPuskesmas_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "ProgramKesehatan" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"deskripsiSingkat" TEXT NOT NULL,
|
||||||
|
"deskripsi" TEXT NOT NULL,
|
||||||
|
"imageId" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "ProgramKesehatan_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "PenangananDarurat" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"deskripsi" TEXT NOT NULL,
|
||||||
|
"imageId" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "PenangananDarurat_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "KontakDarurat" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"deskripsi" TEXT NOT NULL,
|
||||||
|
"imageId" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "KontakDarurat_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "InfoWabahPenyakit" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"deskripsiSingkat" TEXT NOT NULL,
|
||||||
|
"deskripsiLengkap" TEXT NOT NULL,
|
||||||
|
"imageId" TEXT NOT NULL,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"deletedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
|
||||||
|
CONSTRAINT "InfoWabahPenyakit_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Puskesmas" ADD CONSTRAINT "Puskesmas_jamId_fkey" FOREIGN KEY ("jamId") REFERENCES "JamOperasional"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Puskesmas" ADD CONSTRAINT "Puskesmas_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "FileStorage"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Puskesmas" ADD CONSTRAINT "Puskesmas_kontakId_fkey" FOREIGN KEY ("kontakId") REFERENCES "KontakPuskesmas"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "ProgramKesehatan" ADD CONSTRAINT "ProgramKesehatan_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "FileStorage"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "PenangananDarurat" ADD CONSTRAINT "PenangananDarurat_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "FileStorage"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "KontakDarurat" ADD CONSTRAINT "KontakDarurat_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "FileStorage"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "InfoWabahPenyakit" ADD CONSTRAINT "InfoWabahPenyakit_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "FileStorage"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
12
prisma/migrations/20250624061829_24jun2025_2/migration.sql
Normal file
12
prisma/migrations/20250624061829_24jun2025_2/migration.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- The primary key for the `GrafikKepuasan` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "GrafikKepuasan" DROP CONSTRAINT "GrafikKepuasan_pkey",
|
||||||
|
ALTER COLUMN "id" DROP DEFAULT,
|
||||||
|
ALTER COLUMN "id" SET DATA TYPE TEXT,
|
||||||
|
ADD CONSTRAINT "GrafikKepuasan_pkey" PRIMARY KEY ("id");
|
||||||
|
DROP SEQUENCE "GrafikKepuasan_id_seq";
|
||||||
@@ -624,7 +624,7 @@ model PendaftaranJadwalKegiatan {
|
|||||||
|
|
||||||
// ========================================= PERSENTASE KELAHIRAN & KEMATIAN ========================================= //
|
// ========================================= PERSENTASE KELAHIRAN & KEMATIAN ========================================= //
|
||||||
model DataKematian_Kelahiran {
|
model DataKematian_Kelahiran {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid())
|
||||||
tahun String
|
tahun String
|
||||||
kematianKasar String
|
kematianKasar String
|
||||||
kematianBayi String
|
kematianBayi String
|
||||||
@@ -637,7 +637,7 @@ model DataKematian_Kelahiran {
|
|||||||
|
|
||||||
// ========================================= GRAFIK KEPUASAN ========================================= //
|
// ========================================= GRAFIK KEPUASAN ========================================= //
|
||||||
model GrafikKepuasan {
|
model GrafikKepuasan {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid())
|
||||||
label String
|
label String
|
||||||
jumlah String
|
jumlah String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { z } from "zod";
|
|||||||
|
|
||||||
const templateGrafikKepuasan = z.object({
|
const templateGrafikKepuasan = z.object({
|
||||||
label: z.string().min(2, "Label harus diisi"),
|
label: z.string().min(2, "Label harus diisi"),
|
||||||
jumlah: z.string().min(2, "Jumlah harus diisi"),
|
jumlah: z.string().min(1, "Jumlah harus diisi"),
|
||||||
});
|
});
|
||||||
|
|
||||||
type GrafikKepuasan = Prisma.GrafikKepuasanGetPayload<{
|
type GrafikKepuasan = Prisma.GrafikKepuasanGetPayload<{
|
||||||
@@ -31,24 +31,30 @@ const grafikkepuasan = proxy({
|
|||||||
const err = `[${cek.error.issues
|
const err = `[${cek.error.issues
|
||||||
.map((v) => `${v.path.join(".")}`)
|
.map((v) => `${v.path.join(".")}`)
|
||||||
.join("\n")}] required`;
|
.join("\n")}] required`;
|
||||||
return toast.error(err);
|
toast.error(err);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
grafikkepuasan.create.loading = true;
|
grafikkepuasan.create.loading = true;
|
||||||
const res = await ApiFetch.api.kesehatan.grafikkepuasan["create"].post(
|
const res = await ApiFetch.api.kesehatan.grafikkepuasan["create"].post(grafikkepuasan.create.form);
|
||||||
grafikkepuasan.create.form
|
|
||||||
);
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
grafikkepuasan.create.form = {
|
const id = res.data?.data?.id;
|
||||||
label: "",
|
if (id) {
|
||||||
jumlah: ""
|
toast.success("Success create");
|
||||||
};
|
grafikkepuasan.create.form = {
|
||||||
grafikkepuasan.findMany.load();
|
label: "",
|
||||||
return toast.success("success create");
|
jumlah: "",
|
||||||
|
};
|
||||||
|
grafikkepuasan.findMany.load();
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return toast.error("failed create");
|
toast.error("failed create");
|
||||||
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log((error as Error).message);
|
console.log((error as Error).message);
|
||||||
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
grafikkepuasan.create.loading = false;
|
grafikkepuasan.create.loading = false;
|
||||||
}
|
}
|
||||||
@@ -67,10 +73,110 @@ const grafikkepuasan = proxy({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
findUnique: {
|
||||||
|
data: null as Prisma.GrafikKepuasanGetPayload<{
|
||||||
|
omit: { isActive: true }
|
||||||
|
}> | null,
|
||||||
|
async load(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/kesehatan/grafikkepuasan/${id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
grafikkepuasan.findUnique.data = data.data ?? null;
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch grafikkepuasan:", res.statusText);
|
||||||
|
grafikkepuasan.findUnique.data = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching grafikkepuasan:", error);
|
||||||
|
grafikkepuasan.findUnique.data = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
id: "",
|
||||||
|
form: {...defaultForm},
|
||||||
|
loading: false,
|
||||||
|
async byId() {
|
||||||
|
},
|
||||||
|
async submit() {
|
||||||
|
const id = this.id;
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const cek = templateGrafikKepuasan.safeParse(grafikkepuasan.update.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.loading = true;
|
||||||
|
const response = await fetch(`/api/kesehatan/grafikkepuasan/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.form),
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok || !result?.success) {
|
||||||
|
throw new Error(result?.message || "Gagal update data");
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success("Berhasil update data!");
|
||||||
|
|
||||||
|
// ✅ Optional: refresh list kalau kamu langsung ke halaman list
|
||||||
|
await grafikkepuasan.findMany.load();
|
||||||
|
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error update data:", error);
|
||||||
|
toast.error("Gagal update data grafik kepuasan");
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
loading: false,
|
||||||
|
async byId(id: string) {
|
||||||
|
if (!id) {
|
||||||
|
return toast.warn("ID tidak valid");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
grafikkepuasan.delete.loading = true;
|
||||||
|
|
||||||
|
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (response.ok && result?.success) {
|
||||||
|
toast.success(
|
||||||
|
result.message || "Grafik kepuasan berhasil dihapus"
|
||||||
|
);
|
||||||
|
await grafikkepuasan.findMany.load(); // refresh list
|
||||||
|
} else {
|
||||||
|
toast.error(
|
||||||
|
result?.message || "Gagal menghapus grafik kepuasan"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal delete:", error);
|
||||||
|
toast.error("Terjadi kesalahan saat menghapus grafik kepuasan");
|
||||||
|
} finally {
|
||||||
|
grafikkepuasan.delete.loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const stategrafikKepuasan = proxy({
|
export default grafikkepuasan;
|
||||||
grafikkepuasan,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default stategrafikKepuasan;
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { z } from "zod";
|
|||||||
|
|
||||||
const templatePersentase = z.object({
|
const templatePersentase = z.object({
|
||||||
tahun: z.string().min(4, "Tahun harus diisi"),
|
tahun: z.string().min(4, "Tahun harus diisi"),
|
||||||
kematianKasar: z.string().min(2, "Kematian kasar harus diisi"),
|
kematianKasar: z.string().min(1, "Kematian kasar harus diisi"),
|
||||||
kelahiranKasar: z.string().min(2, "Kelahiran kasar harus diisi"),
|
kelahiranKasar: z.string().min(1, "Kelahiran kasar harus diisi"),
|
||||||
kematianBayi: z.string().min(2, "Kematian bayi harus diisi"),
|
kematianBayi: z.string().min(1, "Kematian bayi harus diisi"),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Persentase = Prisma.DataKematian_KelahiranGetPayload<{
|
type Persentase = Prisma.DataKematian_KelahiranGetPayload<{
|
||||||
@@ -37,26 +37,32 @@ const persentasekelahiran = proxy({
|
|||||||
const err = `[${cek.error.issues
|
const err = `[${cek.error.issues
|
||||||
.map((v) => `${v.path.join(".")}`)
|
.map((v) => `${v.path.join(".")}`)
|
||||||
.join("\n")}] required`;
|
.join("\n")}] required`;
|
||||||
return toast.error(err);
|
toast.error(err);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
persentasekelahiran.create.loading = true;
|
persentasekelahiran.create.loading = true;
|
||||||
const res = await ApiFetch.api.kesehatan.persentasekelahiran[
|
const res = await ApiFetch.api.kesehatan.persentasekelahiran["create"].post(persentasekelahiran.create.form);
|
||||||
"create"
|
|
||||||
].post(persentasekelahiran.create.form);
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
persentasekelahiran.create.form = {
|
const id = res.data?.data?.id;
|
||||||
tahun: "",
|
if (id) {
|
||||||
kematianKasar: "",
|
toast.success("Success create");
|
||||||
kelahiranKasar: "",
|
persentasekelahiran.create.form = {
|
||||||
kematianBayi: "",
|
tahun: "",
|
||||||
};
|
kematianKasar: "",
|
||||||
persentasekelahiran.findMany.load();
|
kelahiranKasar: "",
|
||||||
return toast.success("success create");
|
kematianBayi: "",
|
||||||
|
};
|
||||||
|
persentasekelahiran.findMany.load();
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return toast.error("failed create");
|
toast.error("failed create");
|
||||||
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log((error as Error).message);
|
console.log((error as Error).message);
|
||||||
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
persentasekelahiran.create.loading = false;
|
persentasekelahiran.create.loading = false;
|
||||||
}
|
}
|
||||||
@@ -75,10 +81,111 @@ const persentasekelahiran = proxy({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
findUnique: {
|
||||||
|
data: null as Prisma.DataKematian_KelahiranGetPayload<{
|
||||||
|
omit: { isActive: true };
|
||||||
|
}> | null,
|
||||||
|
async load(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/kesehatan/persentasekelahiran/${id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
persentasekelahiran.findUnique.data = data.data ?? null;
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch persentasekelahiran:", res.statusText);
|
||||||
|
persentasekelahiran.findUnique.data = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching persentasekelahiran:", error);
|
||||||
|
persentasekelahiran.findUnique.data = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
id: "",
|
||||||
|
form: { ...defaultForm },
|
||||||
|
loading: false,
|
||||||
|
async byId() {},
|
||||||
|
async submit() {
|
||||||
|
const id = this.id;
|
||||||
|
if (!id) {
|
||||||
|
toast.warn("ID tidak valid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const cek = templatePersentase.safeParse(persentasekelahiran.update.form);
|
||||||
|
if (!cek.success) {
|
||||||
|
const err = `[${cek.error.issues
|
||||||
|
.map((v) => `${v.path.join(".")}`)
|
||||||
|
.join("\n")}] required`;
|
||||||
|
return toast.error(err);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.loading = true;
|
||||||
|
const response = await fetch(`/api/kesehatan/persentasekelahiran/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.form),
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok || !result?.success) {
|
||||||
|
throw new Error(result?.message || "Gagal update data");
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success("Berhasil update data!");
|
||||||
|
|
||||||
|
// ✅ Optional: refresh list kalau kamu langsung ke halaman list
|
||||||
|
await persentasekelahiran.findMany.load();
|
||||||
|
|
||||||
|
return result.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error update data:", error);
|
||||||
|
toast.error("Gagal update data persentase kelahiran");
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
loading: false,
|
||||||
|
async byId(id: string) {
|
||||||
|
if (!id) return toast.warn("ID tidak valid");
|
||||||
|
|
||||||
|
try {
|
||||||
|
persentasekelahiran.delete.loading = true;
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/kesehatan/persentasekelahiran/del/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (response.ok && result?.success) {
|
||||||
|
toast.success(
|
||||||
|
result.message || "Persentase kelahiran berhasil dihapus"
|
||||||
|
);
|
||||||
|
await persentasekelahiran.findMany.load(); // refresh list
|
||||||
|
} else {
|
||||||
|
toast.error(
|
||||||
|
result?.message || "Gagal menghapus persentase kelahiran"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Gagal delete:", error);
|
||||||
|
toast.error("Terjadi kesalahan saat menghapus persentase kelahiran");
|
||||||
|
} finally {
|
||||||
|
persentasekelahiran.delete.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const statePersentase = proxy({
|
export default persentasekelahiran;
|
||||||
persentasekelahiran,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default statePersentase;
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Stack, Tabs, TabsList, TabsPanel, TabsTab, Title } from '@mantine/core';
|
||||||
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
function LayoutTabs({ children }: { children: React.ReactNode }) {
|
||||||
|
const router = useRouter()
|
||||||
|
const pathname = usePathname()
|
||||||
|
const tabs = [
|
||||||
|
{
|
||||||
|
label: "Presentase Kelahiran & Kematian",
|
||||||
|
value: "presentasekelahiran&kematian",
|
||||||
|
href: "/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Grafik Hasil Kepuasan Masyarakat Terhadap Pelayanan Publik",
|
||||||
|
value: "grafikhasilkepuasan",
|
||||||
|
href: "/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Fasilitas Kesehatan",
|
||||||
|
value: "fasilitaskesehatan",
|
||||||
|
href: "/admin/kesehatan/data-kesehatan-warga/fasilitas_kesehatan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Jadwal Kegiatan",
|
||||||
|
value: "jadwalkegiatan",
|
||||||
|
href: "/admin/kesehatan/data-kesehatan-warga/jadwal_kegiatan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Artikel Kesehatan",
|
||||||
|
value: "artikelkesehatan",
|
||||||
|
href: "/admin/kesehatan/data-kesehatan-warga/artikel_kesehatan"
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const curentTab = tabs.find(tab => tab.href === pathname)
|
||||||
|
const [activeTab, setActiveTab] = useState<string | null>(curentTab?.value || tabs[0].value);
|
||||||
|
|
||||||
|
const handleTabChange = (value: string | null) => {
|
||||||
|
const tab = tabs.find(t => t.value === value)
|
||||||
|
if (tab) {
|
||||||
|
router.push(tab.href)
|
||||||
|
}
|
||||||
|
setActiveTab(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const match = tabs.find(tab => tab.href === pathname)
|
||||||
|
if (match) {
|
||||||
|
setActiveTab(match.value)
|
||||||
|
}
|
||||||
|
}, [pathname])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Title order={3}>Data Kesehatan Warga</Title>
|
||||||
|
<Tabs color={colors['blue-button']} variant='pills' value={activeTab} onChange={handleTabChange}>
|
||||||
|
<TabsList p={"xs"} bg={"#BBC8E7FF"}>
|
||||||
|
{tabs.map((e, i) => (
|
||||||
|
<TabsTab key={i} value={e.value}>{e.label}</TabsTab>
|
||||||
|
))}
|
||||||
|
</TabsList>
|
||||||
|
{tabs.map((e, i) => (
|
||||||
|
<TabsPanel key={i} value={e.value}>
|
||||||
|
{/* Konten dummy, bisa diganti tergantung routing */}
|
||||||
|
<></>
|
||||||
|
</TabsPanel>
|
||||||
|
))}
|
||||||
|
</Tabs>
|
||||||
|
{children}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LayoutTabs;
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
'use client'
|
|
||||||
import stategrafikKepuasan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/grafikKepuasan';
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Button, Group, Paper, Skeleton, Stack, TextInput, Title } from '@mantine/core';
|
|
||||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { Bar, BarChart, Legend, Tooltip, XAxis, YAxis } from 'recharts';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
|
|
||||||
function GrafikHasilKepuasan() {
|
|
||||||
const grafikkepuasan = useProxy(stategrafikKepuasan.grafikkepuasan)
|
|
||||||
const [mounted, setMounted] = useState(false);
|
|
||||||
const isTablet = useMediaQuery('(max-width: 1024px)')
|
|
||||||
const isMobile = useMediaQuery('(max-width: 768px)')
|
|
||||||
const [chartData, setChartData] = useState<any[]>([])
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
await grafikkepuasan.findMany.load();
|
|
||||||
if (grafikkepuasan.findMany.data && grafikkepuasan.findMany.data.length > 0) {
|
|
||||||
setChartData(grafikkepuasan.findMany.data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchData();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMounted(true); // setelah komponen siap di client
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!mounted) {
|
|
||||||
return null; // Jangan render apa-apa dulu sebelum mounted
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack py={10} gap={"xs"}>
|
|
||||||
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title order={4}>Tambah Grafik Hasil Kepuasan</Title>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<TextInput
|
|
||||||
label="Label"
|
|
||||||
placeholder='Masukkan label yang diinginkan'
|
|
||||||
value={grafikkepuasan.create.form.label}
|
|
||||||
onChange={(val) => {
|
|
||||||
grafikkepuasan.create.form.label = val.currentTarget.value
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label="Jumlah Penderita"
|
|
||||||
type='number'
|
|
||||||
placeholder='Masukkan jumlah penderita'
|
|
||||||
value={grafikkepuasan.create.form.jumlah}
|
|
||||||
onChange={(val) => {
|
|
||||||
grafikkepuasan.create.form.jumlah = val.currentTarget.value
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Group>
|
|
||||||
<Button bg={colors['blue-button']} mt={10}
|
|
||||||
onClick={async () => {
|
|
||||||
await grafikkepuasan.create.create();
|
|
||||||
await grafikkepuasan.findMany.load();
|
|
||||||
if (grafikkepuasan.findMany.data) {
|
|
||||||
setChartData(grafikkepuasan.findMany.data);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>Submit</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
{!chartData ? (
|
|
||||||
<Box style={{ width: '100%', minWidth: 300, minHeight: 300 }}>
|
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title py={15} order={4}>Data Hasil Kepuasan</Title>
|
|
||||||
<Skeleton h={400} />
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
<Box style={{ width: '100%', minWidth: 300, minHeight: 300 }}>
|
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title py={15} order={4}>Data Hasil Kepuasan</Title>
|
|
||||||
<BarChart
|
|
||||||
width={isMobile ? 250 : isTablet ? 300 : 350}
|
|
||||||
height={380}
|
|
||||||
data={chartData}
|
|
||||||
>
|
|
||||||
<XAxis dataKey="label" />
|
|
||||||
<YAxis />
|
|
||||||
<Tooltip />
|
|
||||||
<Legend />
|
|
||||||
<Bar dataKey="jumlah" fill={colors['blue-button']} name="Jumlah" />
|
|
||||||
</BarChart>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default GrafikHasilKepuasan;
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
'use client'
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
import statePersentase from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/persentaseKelahiran';
|
|
||||||
import colors from '@/con/colors';
|
|
||||||
import { Box, Button, Group, Paper, Skeleton, Stack, TextInput, Title } from '@mantine/core';
|
|
||||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { Bar, BarChart, Legend, Tooltip, XAxis, YAxis } from 'recharts';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
|
|
||||||
function PersentaseDataKelahiranKematian() {
|
|
||||||
const persentase = useProxy(statePersentase.persentasekelahiran);
|
|
||||||
const [chartData, setChartData] = useState<any[]>([]);
|
|
||||||
const [mounted, setMounted] = useState(false); // untuk memastikan DOM sudah ready
|
|
||||||
const isTablet = useMediaQuery('(max-width: 1024px)')
|
|
||||||
const isMobile = useMediaQuery('(max-width: 768px)')
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMounted(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
await persentase.findMany.load();
|
|
||||||
if (persentase.findMany.data && persentase.findMany.data.length > 0) {
|
|
||||||
setChartData(persentase.findMany.data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchData();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack py={10}>
|
|
||||||
{/* Form Input */}
|
|
||||||
<Box>
|
|
||||||
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title order={4}>Tambah Persentase Data Kelahiran & Kematian</Title>
|
|
||||||
<Stack gap={"xs"}>
|
|
||||||
<TextInput
|
|
||||||
label="Tahun"
|
|
||||||
type="number"
|
|
||||||
value={persentase.create.form.tahun}
|
|
||||||
placeholder="Masukkan tahun"
|
|
||||||
onChange={(val) => {
|
|
||||||
persentase.create.form.tahun = val.currentTarget.value;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label="Kematian Kasar"
|
|
||||||
type="number"
|
|
||||||
value={persentase.create.form.kematianKasar}
|
|
||||||
placeholder="Masukkan kematian kasar"
|
|
||||||
onChange={(val) => {
|
|
||||||
persentase.create.form.kematianKasar = val.currentTarget.value;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label="Kematian Bayi"
|
|
||||||
type="number"
|
|
||||||
value={persentase.create.form.kematianBayi}
|
|
||||||
placeholder="Masukkan kematian bayi"
|
|
||||||
onChange={(val) => {
|
|
||||||
persentase.create.form.kematianBayi = val.currentTarget.value;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label="Kelahiran Kasar"
|
|
||||||
type="number"
|
|
||||||
value={persentase.create.form.kelahiranKasar}
|
|
||||||
placeholder="Masukkan kelahiran kasar"
|
|
||||||
onChange={(val) => {
|
|
||||||
persentase.create.form.kelahiranKasar = val.currentTarget.value;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Group>
|
|
||||||
<Button
|
|
||||||
bg={colors['blue-button']}
|
|
||||||
mt={10}
|
|
||||||
onClick={async () => {
|
|
||||||
await persentase.create.create();
|
|
||||||
await persentase.findMany.load();
|
|
||||||
if (persentase.findMany.data) {
|
|
||||||
setChartData(persentase.findMany.data);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
{/* Chart */}
|
|
||||||
{!mounted && !chartData ? (
|
|
||||||
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title pb={10} order={3}>Data Kelahiran & Kematian</Title>
|
|
||||||
<Skeleton h={400} />
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
|
||||||
<Paper bg={colors['white-1']} p={'md'}>
|
|
||||||
<Title pb={10} order={4}>Data Kelahiran & Kematian</Title>
|
|
||||||
{mounted && chartData.length > 0 && (
|
|
||||||
<BarChart width={isMobile ? 450 : isTablet ? 500 : 550} height={350} data={chartData} >
|
|
||||||
<XAxis dataKey="tahun" />
|
|
||||||
<YAxis />
|
|
||||||
<Tooltip />
|
|
||||||
<Legend />
|
|
||||||
<Bar dataKey="kematianKasar" fill="#f03e3e" name="Kematian Kasar" />
|
|
||||||
<Bar dataKey="kematianBayi" fill="#ff922b" name="Kematian Bayi" />
|
|
||||||
<Bar dataKey="kelahiranKasar" fill="#4dabf7" name="Kelahiran Kasar" />
|
|
||||||
</BarChart>
|
|
||||||
)}
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PersentaseDataKelahiranKematian;
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { Box, Paper, Text } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Paper, Text } from '@mantine/core';
|
||||||
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
|
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
function DoctorSignUI() {
|
function DoctorSignUI() {
|
||||||
const doctorSign = useProxy(stateArtikelKesehatan.doctorSign)
|
const doctorSign = useProxy(stateArtikelKesehatan.doctorSign)
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
|
|
||||||
function FirstAidUI() {
|
function FirstAidUI() {
|
||||||
const firstAidState = useProxy(stateArtikelKesehatan.firstAid)
|
const firstAidState = useProxy(stateArtikelKesehatan.firstAid)
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
import { Box, Paper, Stack, Text } from '@mantine/core';
|
import { Box, Paper, Stack, Text } from '@mantine/core';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
|
||||||
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
|
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
||||||
|
|
||||||
function IntoductionUI() {
|
function IntoductionUI() {
|
||||||
const introduction = useProxy(stateArtikelKesehatan.introduction)
|
const introduction = useProxy(stateArtikelKesehatan.introduction)
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
||||||
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
|
||||||
import React from 'react';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
|
|
||||||
function PreventionUI() {
|
function PreventionUI() {
|
||||||
const preventionState = useProxy(stateArtikelKesehatan.prevention)
|
const preventionState = useProxy(stateArtikelKesehatan.prevention)
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
import stateArtikelKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/artikelKesehatan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
|
||||||
|
|
||||||
function SymptomUI() {
|
function SymptomUI() {
|
||||||
const symptomState = useProxy(stateArtikelKesehatan.symptom)
|
const symptomState = useProxy(stateArtikelKesehatan.symptom)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
'use client'
|
||||||
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
'use client'
|
||||||
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Text } from '@mantine/core';
|
import { Box, Paper, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
|
||||||
|
|
||||||
function FasilitasPendukung() {
|
function FasilitasPendukung() {
|
||||||
const fasilitaspendukungState = useProxy(stateFasilitasKesehatan.fasilitaspendukung)
|
const fasilitaspendukungState = useProxy(stateFasilitasKesehatan.fasilitaspendukung)
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Text } from '@mantine/core';
|
import { Box, Paper, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
||||||
|
|
||||||
function LayananUnggulan() {
|
function LayananUnggulan() {
|
||||||
const informasiumumState = useProxy(stateFasilitasKesehatan.layananunggulan)
|
const informasiumumState = useProxy(stateFasilitasKesehatan.layananunggulan)
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
'use client'
|
||||||
import { Box, Text, Paper } from '@mantine/core';
|
|
||||||
import { useProxy } from 'valtio/utils';
|
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Paper, Text } from '@mantine/core';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
||||||
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
|
|
||||||
function ProsedurPendaftaran() {
|
function ProsedurPendaftaran() {
|
||||||
const prosedurpendaftaranState = useProxy(stateFasilitasKesehatan.prosedurpendaftaran)
|
const prosedurpendaftaranState = useProxy(stateFasilitasKesehatan.prosedurpendaftaran)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
'use client'
|
||||||
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
import stateFasilitasKesehatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/fasilitasKesehatan';
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
import { Box, Paper, Stack, Text, TextInput } from '@mantine/core';
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
|
||||||
|
import grafikkepuasan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/grafikKepuasan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
function EditGrafikHasilKepuasan() {
|
||||||
|
const router = useRouter()
|
||||||
|
const params = useParams() as { id: string }
|
||||||
|
const stateGrafikKepuasan = useProxy(grafikkepuasan)
|
||||||
|
|
||||||
|
const id = params.id
|
||||||
|
|
||||||
|
// Load data saat komponen mount
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) {
|
||||||
|
stateGrafikKepuasan.findUnique.load(id).then(() => {
|
||||||
|
const data = stateGrafikKepuasan.findUnique.data
|
||||||
|
if (data) {
|
||||||
|
stateGrafikKepuasan.update.form = {
|
||||||
|
label: data.label || '',
|
||||||
|
jumlah: data.jumlah || '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [id])
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
// Set the ID before submitting
|
||||||
|
stateGrafikKepuasan.update.id = id;
|
||||||
|
await stateGrafikKepuasan.update.submit();
|
||||||
|
router.push('/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan')
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Paper bg={colors['white-1']} w={{ base: '100%', md: '50%' }} p={'md'}>
|
||||||
|
<Stack>
|
||||||
|
<Title order={3}>Edit Grafik Hasil Kepuasan</Title>
|
||||||
|
<TextInput
|
||||||
|
label="Label"
|
||||||
|
placeholder="masukkan label"
|
||||||
|
value={stateGrafikKepuasan.update.form.label}
|
||||||
|
onChange={(val) => {
|
||||||
|
stateGrafikKepuasan.update.form.label = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Jumlah"
|
||||||
|
type="number"
|
||||||
|
placeholder="masukkan jumlah"
|
||||||
|
value={stateGrafikKepuasan.update.form.jumlah}
|
||||||
|
onChange={(val) => {
|
||||||
|
stateGrafikKepuasan.update.form.jumlah = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
mt={10}
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditGrafikHasilKepuasan;
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
'use client'
|
||||||
|
import grafikkepuasan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/grafikKepuasan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Group, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
function CreateGrafikHasilKepuasanMasyarakat() {
|
||||||
|
const stateGrafikKepuasan = useProxy(grafikkepuasan);
|
||||||
|
const [chartData, setChartData] = useState<any[]>([]);
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
stateGrafikKepuasan.create.form = {
|
||||||
|
label: "",
|
||||||
|
jumlah: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const id = await stateGrafikKepuasan.create.create();
|
||||||
|
if (id) {
|
||||||
|
const idStr = String(id);
|
||||||
|
await stateGrafikKepuasan.findUnique.load(idStr);
|
||||||
|
if (stateGrafikKepuasan.findUnique.data) {
|
||||||
|
setChartData([stateGrafikKepuasan.findUnique.data]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetForm();
|
||||||
|
router.push("/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan");
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title order={4}>Tambah Grafik Hasil Kepuasan Masyarakat</Title>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<TextInput
|
||||||
|
label="Label"
|
||||||
|
type="text"
|
||||||
|
value={stateGrafikKepuasan.create.form.label}
|
||||||
|
placeholder="Masukkan label"
|
||||||
|
onChange={(val) => {
|
||||||
|
stateGrafikKepuasan.create.form.label = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Jumlah"
|
||||||
|
type="number"
|
||||||
|
value={stateGrafikKepuasan.create.form.jumlah}
|
||||||
|
placeholder="Masukkan jumlah"
|
||||||
|
onChange={(val) => {
|
||||||
|
stateGrafikKepuasan.create.form.jumlah = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Group>
|
||||||
|
<Button
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
mt={10}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CreateGrafikHasilKepuasanMasyarakat;
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text, Title } from '@mantine/core';
|
||||||
|
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { IconEdit, IconSearch, IconTrash } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Bar, BarChart, Legend, Tooltip, XAxis, YAxis } from 'recharts';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import JudulListTab from '../../../_com/jusulListTab';
|
||||||
|
import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
import grafikkepuasan from '../../../_state/kesehatan/data_kesehatan_warga/grafikKepuasan';
|
||||||
|
|
||||||
|
function GrafikHasilKepuasanMasyarakat() {
|
||||||
|
type PDKMGrafik = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
jumlah: number;
|
||||||
|
}
|
||||||
|
const stateGrafikKepuasan = useProxy(grafikkepuasan);
|
||||||
|
const [chartData, setChartData] = useState<PDKMGrafik[]>([]);
|
||||||
|
const [mounted, setMounted] = useState(false); // untuk memastikan DOM sudah ready
|
||||||
|
const isTablet = useMediaQuery('(max-width: 1024px)')
|
||||||
|
const isMobile = useMediaQuery('(max-width: 768px)')
|
||||||
|
const [modalHapus, setModalHapus] = useState(false)
|
||||||
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
if (selectedId) {
|
||||||
|
stateGrafikKepuasan.delete.byId(selectedId)
|
||||||
|
setModalHapus(false)
|
||||||
|
setSelectedId(null)
|
||||||
|
|
||||||
|
stateGrafikKepuasan.findMany.load()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
setMounted(true)
|
||||||
|
stateGrafikKepuasan.findMany.load()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
if (stateGrafikKepuasan.findMany.data) {
|
||||||
|
setChartData(stateGrafikKepuasan.findMany.data.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
label: item.label,
|
||||||
|
jumlah: Number(item.jumlah),
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}, [stateGrafikKepuasan.findMany.data]);
|
||||||
|
|
||||||
|
if (!stateGrafikKepuasan.findMany.data) {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Skeleton h={500} />
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
{/* Form Input */}
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<JudulListTab
|
||||||
|
title='List Grafik Hasil Kepuasan Masyarakat'
|
||||||
|
href='/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/create'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={16} />}
|
||||||
|
/>
|
||||||
|
<Table striped withTableBorder withRowBorders>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Label</TableTh>
|
||||||
|
<TableTh>Jumlah</TableTh>
|
||||||
|
<TableTh>Edit</TableTh>
|
||||||
|
<TableTh>Delete</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
{stateGrafikKepuasan.findMany.data?.map((item) => (
|
||||||
|
<TableTr key={item.id}>
|
||||||
|
<TableTd>{item.label}</TableTd>
|
||||||
|
<TableTd>{item.jumlah}</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/${item.id}`)}>
|
||||||
|
<IconEdit size={20} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button
|
||||||
|
color='red'
|
||||||
|
disabled={stateGrafikKepuasan.delete.loading}
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedId(item.id)
|
||||||
|
setModalHapus(true)
|
||||||
|
}}>
|
||||||
|
<IconTrash size={20} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
))}
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
|
||||||
|
{/* Chart */}
|
||||||
|
{!mounted && !chartData ? (
|
||||||
|
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title pb={10} order={3}>Grafik Hasil Kepuasan Masyarakat</Title>
|
||||||
|
<Text c='dimmed'>Belum ada data untuk ditampilkan dalam grafik</Text>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title pb={10} order={4}>Grafik Hasil Kepuasan Masyarakat</Title>
|
||||||
|
{mounted && chartData.length > 0 && (
|
||||||
|
<BarChart width={isMobile ? 450 : isTablet ? 500 : 550} height={350} data={chartData} >
|
||||||
|
<XAxis dataKey="label" />
|
||||||
|
<YAxis />
|
||||||
|
<Tooltip />
|
||||||
|
<Legend />
|
||||||
|
<Bar dataKey="jumlah" fill={colors['blue-button']} name="Jumlah" />
|
||||||
|
</BarChart>
|
||||||
|
)}
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{/* Modal Konfirmasi Hapus */}
|
||||||
|
<ModalKonfirmasiHapus
|
||||||
|
opened={modalHapus}
|
||||||
|
onClose={() => setModalHapus(false)}
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
text='Apakah anda yakin ingin menghapus grafik hasil kepuasan masyarakat ini?'
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GrafikHasilKepuasanMasyarakat;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
'use client'
|
||||||
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text } from '@mantine/core';
|
import { Box, Paper, Stack, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
|
||||||
|
|
||||||
function DeskripsiKegiatan() {
|
function DeskripsiKegiatan() {
|
||||||
const deskripsiKegiatanState = useProxy(stateJadwalKegiatan.deskripsiKegiatan)
|
const deskripsiKegiatanState = useProxy(stateJadwalKegiatan.deskripsiKegiatan)
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
'use client'
|
||||||
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text } from '@mantine/core';
|
import { Box, Paper, Stack, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
|
||||||
|
|
||||||
function DokumenYangDiperlukan() {
|
function DokumenYangDiperlukan() {
|
||||||
const dokumenDiperlukan = useProxy(stateJadwalKegiatan.dokumenjadwalkegiatan)
|
const dokumenDiperlukan = useProxy(stateJadwalKegiatan.dokumenjadwalkegiatan)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
'use client'
|
||||||
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
||||||
import colors from '@/con/colors';
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, TextInput, Title } from '@mantine/core';
|
import { Box, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
'use client'
|
||||||
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text } from '@mantine/core';
|
import { Box, Paper, Stack, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
|
||||||
|
|
||||||
function LayananTersedia() {
|
function LayananTersedia() {
|
||||||
const layananTersediaState = useProxy(stateJadwalKegiatan.layanantersedia)
|
const layananTersediaState = useProxy(stateJadwalKegiatan.layanantersedia)
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
'use client'
|
||||||
|
import colors from '@/con/colors';
|
||||||
import { Box, Paper, Stack, Text } from '@mantine/core';
|
import { Box, Paper, Stack, Text } from '@mantine/core';
|
||||||
import { useProxy } from 'valtio/utils';
|
import { useProxy } from 'valtio/utils';
|
||||||
import { KesehatanEditor } from '../../../_com/kesehatanEditor';
|
import { KesehatanEditor } from '../../_com/kesehatanEditor';
|
||||||
import colors from '@/con/colors';
|
import stateJadwalKegiatan from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/jadwalKegiatan';
|
||||||
|
|
||||||
function SyaratDanKetentuan() {
|
function SyaratDanKetentuan() {
|
||||||
const syaratKetentuan = useProxy(stateJadwalKegiatan.syaratketentuan)
|
const syaratKetentuan = useProxy(stateJadwalKegiatan.syaratketentuan)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import LayoutTabs from "./_lib/layoutTabs"
|
||||||
|
|
||||||
|
|
||||||
|
export default function Layout({children} : {children: React.ReactNode}) {
|
||||||
|
return (
|
||||||
|
<LayoutTabs>
|
||||||
|
{children}
|
||||||
|
</LayoutTabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import colors from '@/con/colors';
|
|
||||||
import { Stack, Tabs, TabsList, TabsPanel, TabsTab, Title } from '@mantine/core';
|
|
||||||
import ArtikelKesehatan from './_ui/artikel_kesehatan/page';
|
|
||||||
import FasilitasKesehatan from './_ui/fasilitas_kesehatan/page';
|
|
||||||
import GrafikHasilKepuasan from './_ui/grafik_hasil_kepuasan/page';
|
|
||||||
import JadwalKegiatan from './_ui/jadwal_kegiatan/page';
|
|
||||||
import PersentaseDataKelahiranKematian from './_ui/persentase_data_kelahiran_kematian/page';
|
|
||||||
|
|
||||||
|
|
||||||
function Page() {
|
|
||||||
return (
|
|
||||||
<Stack>
|
|
||||||
<Title order={3}>Data Kesehatan Warga</Title>
|
|
||||||
<Tabs color={colors['blue-button']} variant='pills' defaultValue={"Persentase Kelahiran & Kematian"}>
|
|
||||||
<TabsList bg={colors['BG-trans']} p={'xs'}>
|
|
||||||
<TabsTab value="Persentase Kelahiran & Kematian">
|
|
||||||
Persentase Kelahiran & Kematian
|
|
||||||
</TabsTab>
|
|
||||||
<TabsTab value="Grafik Hasil Kepuasan">
|
|
||||||
Grafik Hasil Kepuasan
|
|
||||||
</TabsTab>
|
|
||||||
<TabsTab value="Fasilitas Kesehatan">
|
|
||||||
Fasilitas Kesehatan
|
|
||||||
</TabsTab>
|
|
||||||
<TabsTab value="Jadwal Kegiatan">
|
|
||||||
Jadwal Kegiatan
|
|
||||||
</TabsTab>
|
|
||||||
<TabsTab value="Artikel Kesehatan">
|
|
||||||
Artikel Kesehatan
|
|
||||||
</TabsTab>
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<TabsPanel value="Persentase Kelahiran & Kematian">
|
|
||||||
<PersentaseDataKelahiranKematian />
|
|
||||||
</TabsPanel>
|
|
||||||
<TabsPanel value="Grafik Hasil Kepuasan">
|
|
||||||
<GrafikHasilKepuasan/>
|
|
||||||
</TabsPanel>
|
|
||||||
<TabsPanel value="Fasilitas Kesehatan">
|
|
||||||
<FasilitasKesehatan/>
|
|
||||||
</TabsPanel>
|
|
||||||
<TabsPanel value="Jadwal Kegiatan">
|
|
||||||
<JadwalKegiatan/>
|
|
||||||
</TabsPanel>
|
|
||||||
<TabsPanel value="Artikel Kesehatan">
|
|
||||||
<ArtikelKesehatan/>
|
|
||||||
</TabsPanel>
|
|
||||||
|
|
||||||
</Tabs>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Page;
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
'use client'
|
||||||
|
|
||||||
|
import persentasekelahiran from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/persentaseKelahiran';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
function EditPersentaseDataKelahiranKematian() {
|
||||||
|
const router = useRouter()
|
||||||
|
const params = useParams() as { id: string }
|
||||||
|
const statePresentase = useProxy(persentasekelahiran)
|
||||||
|
|
||||||
|
const id = params.id
|
||||||
|
|
||||||
|
// Load data saat komponen mount
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) {
|
||||||
|
statePresentase.findUnique.load(id).then(() => {
|
||||||
|
const data = statePresentase.findUnique.data
|
||||||
|
if (data) {
|
||||||
|
statePresentase.update.form = {
|
||||||
|
tahun: data.tahun || '',
|
||||||
|
kematianKasar: data.kematianKasar || '',
|
||||||
|
kelahiranKasar: data.kelahiranKasar || '',
|
||||||
|
kematianBayi: data.kematianBayi || '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [id])
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
// Set the ID before submitting
|
||||||
|
statePresentase.update.id = id;
|
||||||
|
await statePresentase.update.submit();
|
||||||
|
router.push('/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian')
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Paper bg={colors['white-1']} w={{ base: '100%', md: '50%' }} p={'md'}>
|
||||||
|
<Stack>
|
||||||
|
<Title order={3}>Edit Persentase Data Kelahiran & Kematian</Title>
|
||||||
|
<TextInput
|
||||||
|
label="Tahun"
|
||||||
|
placeholder="masukkan tahun"
|
||||||
|
value={statePresentase.update.form.tahun}
|
||||||
|
onChange={(val) => {
|
||||||
|
statePresentase.update.form.tahun = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kematian Kasar"
|
||||||
|
type="number"
|
||||||
|
placeholder="masukkan kematian kasar"
|
||||||
|
value={statePresentase.update.form.kematianKasar}
|
||||||
|
onChange={(val) => {
|
||||||
|
statePresentase.update.form.kematianKasar = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kematian Bayi"
|
||||||
|
type="number"
|
||||||
|
placeholder="masukkan kematian bayi"
|
||||||
|
value={statePresentase.update.form.kematianBayi}
|
||||||
|
onChange={(val) => {
|
||||||
|
statePresentase.update.form.kematianBayi = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kelahiran Kasar"
|
||||||
|
type="number"
|
||||||
|
placeholder="masukkan kelahiran kasar"
|
||||||
|
value={statePresentase.update.form.kelahiranKasar}
|
||||||
|
onChange={(val) => {
|
||||||
|
statePresentase.update.form.kelahiranKasar = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
mt={10}
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
>
|
||||||
|
Simpan Perubahan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditPersentaseDataKelahiranKematian;
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
'use client'
|
||||||
|
import persentasekelahiran from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/persentaseKelahiran';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Group, Paper, Stack, TextInput, Title } from '@mantine/core';
|
||||||
|
import { IconArrowBack } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
|
||||||
|
function CreatePersentaseDataKelahiranKematian() {
|
||||||
|
const statePersentase = useProxy(persentasekelahiran);
|
||||||
|
const [chartData, setChartData] = useState<any[]>([]);
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
statePersentase.create.form = {
|
||||||
|
tahun: "",
|
||||||
|
kematianBayi: "",
|
||||||
|
kematianKasar: "",
|
||||||
|
kelahiranKasar: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const id = await statePersentase.create.create();
|
||||||
|
if (id) {
|
||||||
|
const idStr = String(id);
|
||||||
|
await statePersentase.findUnique.load(idStr);
|
||||||
|
if (statePersentase.findUnique.data) {
|
||||||
|
setChartData([statePersentase.findUnique.data]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetForm();
|
||||||
|
router.push("/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian");
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={10}>
|
||||||
|
<Button variant="subtle" onClick={() => router.back()}>
|
||||||
|
<IconArrowBack size={20} />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Paper w={{ base: '100%', md: '50%' }} bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title order={4}>Tambah Persentase Data Kelahiran & Kematian</Title>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
<TextInput
|
||||||
|
label="Tahun"
|
||||||
|
type="number"
|
||||||
|
value={statePersentase.create.form.tahun}
|
||||||
|
placeholder="Masukkan tahun"
|
||||||
|
onChange={(val) => {
|
||||||
|
statePersentase.create.form.tahun = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kematian Kasar"
|
||||||
|
type="number"
|
||||||
|
value={statePersentase.create.form.kematianKasar}
|
||||||
|
placeholder="Masukkan kematian kasar"
|
||||||
|
onChange={(val) => {
|
||||||
|
statePersentase.create.form.kematianKasar = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kematian Bayi"
|
||||||
|
type="number"
|
||||||
|
value={statePersentase.create.form.kematianBayi}
|
||||||
|
placeholder="Masukkan kematian bayi"
|
||||||
|
onChange={(val) => {
|
||||||
|
statePersentase.create.form.kematianBayi = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Kelahiran Kasar"
|
||||||
|
type="number"
|
||||||
|
value={statePersentase.create.form.kelahiranKasar}
|
||||||
|
placeholder="Masukkan kelahiran kasar"
|
||||||
|
onChange={(val) => {
|
||||||
|
statePersentase.create.form.kelahiranKasar = val.currentTarget.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Group>
|
||||||
|
<Button
|
||||||
|
bg={colors['blue-button']}
|
||||||
|
mt={10}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CreatePersentaseDataKelahiranKematian;
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
'use client'
|
||||||
|
import persentasekelahiran from '@/app/admin/(dashboard)/_state/kesehatan/data_kesehatan_warga/persentaseKelahiran';
|
||||||
|
import colors from '@/con/colors';
|
||||||
|
import { Box, Button, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Text, Title } from '@mantine/core';
|
||||||
|
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { IconEdit, IconSearch, IconTrash } from '@tabler/icons-react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Bar, BarChart, Legend, Tooltip, XAxis, YAxis } from 'recharts';
|
||||||
|
import { useProxy } from 'valtio/utils';
|
||||||
|
import JudulListTab from '../../../_com/jusulListTab';
|
||||||
|
import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
|
||||||
|
|
||||||
|
function PersentaseDataKelahiranKematian() {
|
||||||
|
type PDKMGrafik = {
|
||||||
|
id: string;
|
||||||
|
tahun: string;
|
||||||
|
kematianKasar: number;
|
||||||
|
kematianBayi: number;
|
||||||
|
kelahiranKasar: number;
|
||||||
|
}
|
||||||
|
const statePersentase = useProxy(persentasekelahiran);
|
||||||
|
const [chartData, setChartData] = useState<PDKMGrafik[]>([]);
|
||||||
|
const [mounted, setMounted] = useState(false); // untuk memastikan DOM sudah ready
|
||||||
|
const isTablet = useMediaQuery('(max-width: 1024px)')
|
||||||
|
const isMobile = useMediaQuery('(max-width: 768px)')
|
||||||
|
const [modalHapus, setModalHapus] = useState(false)
|
||||||
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
if (selectedId) {
|
||||||
|
statePersentase.delete.byId(selectedId)
|
||||||
|
setModalHapus(false)
|
||||||
|
setSelectedId(null)
|
||||||
|
|
||||||
|
statePersentase.findMany.load()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
setMounted(true)
|
||||||
|
statePersentase.findMany.load()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
if (statePersentase.findMany.data) {
|
||||||
|
setChartData(statePersentase.findMany.data.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
tahun: item.tahun,
|
||||||
|
kematianKasar: Number(item.kematianKasar),
|
||||||
|
kematianBayi: Number(item.kematianBayi),
|
||||||
|
kelahiranKasar: Number(item.kelahiranKasar),
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}, [statePersentase.findMany.data]);
|
||||||
|
|
||||||
|
if (!statePersentase.findMany.data) {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Skeleton h={500} />
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack gap={"xs"}>
|
||||||
|
{/* Form Input */}
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<JudulListTab
|
||||||
|
title='List Persentase Data Kelahiran & Kematian'
|
||||||
|
href='/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/create'
|
||||||
|
placeholder='pencarian'
|
||||||
|
searchIcon={<IconSearch size={16} />}
|
||||||
|
/>
|
||||||
|
<Table striped withTableBorder withRowBorders>
|
||||||
|
<TableThead>
|
||||||
|
<TableTr>
|
||||||
|
<TableTh>Tahun</TableTh>
|
||||||
|
<TableTh>Kematian Kasar</TableTh>
|
||||||
|
<TableTh>Kematian Bayi</TableTh>
|
||||||
|
<TableTh>kelahiran Kasar</TableTh>
|
||||||
|
<TableTh>Edit</TableTh>
|
||||||
|
<TableTh>Delete</TableTh>
|
||||||
|
</TableTr>
|
||||||
|
</TableThead>
|
||||||
|
<TableTbody>
|
||||||
|
{statePersentase.findMany.data?.map((item) => (
|
||||||
|
<TableTr key={item.id}>
|
||||||
|
<TableTd>{item.tahun}</TableTd>
|
||||||
|
<TableTd>{item.kematianKasar}</TableTd>
|
||||||
|
<TableTd>{item.kematianBayi}</TableTd>
|
||||||
|
<TableTd>{item.kelahiranKasar}</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/${item.id}`)}>
|
||||||
|
<IconEdit size={20} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
<TableTd>
|
||||||
|
<Button
|
||||||
|
color='red'
|
||||||
|
disabled={statePersentase.delete.loading}
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedId(item.id)
|
||||||
|
setModalHapus(true)
|
||||||
|
}}>
|
||||||
|
<IconTrash size={20} />
|
||||||
|
</Button>
|
||||||
|
</TableTd>
|
||||||
|
</TableTr>
|
||||||
|
))}
|
||||||
|
</TableTbody>
|
||||||
|
</Table>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
|
||||||
|
{/* Chart */}
|
||||||
|
{!mounted && !chartData ? (
|
||||||
|
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title pb={10} order={3}>Data Kelahiran & Kematian</Title>
|
||||||
|
<Text c='dimmed'>Belum ada data untuk ditampilkan dalam grafik</Text>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Box style={{ width: '100%', minWidth: 300, height: 400, minHeight: 300 }}>
|
||||||
|
<Paper bg={colors['white-1']} p={'md'}>
|
||||||
|
<Title pb={10} order={4}>Data Kelahiran & Kematian</Title>
|
||||||
|
{mounted && chartData.length > 0 && (
|
||||||
|
<BarChart width={isMobile ? 450 : isTablet ? 500 : 550} height={350} data={chartData} >
|
||||||
|
<XAxis dataKey="tahun" />
|
||||||
|
<YAxis />
|
||||||
|
<Tooltip />
|
||||||
|
<Legend />
|
||||||
|
<Bar dataKey="kematianKasar" fill="#f03e3e" name="Kematian Kasar" />
|
||||||
|
<Bar dataKey="kematianBayi" fill="#ff922b" name="Kematian Bayi" />
|
||||||
|
<Bar dataKey="kelahiranKasar" fill="#4dabf7" name="Kelahiran Kasar" />
|
||||||
|
</BarChart>
|
||||||
|
)}
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{/* Modal Konfirmasi Hapus */}
|
||||||
|
<ModalKonfirmasiHapus
|
||||||
|
opened={modalHapus}
|
||||||
|
onClose={() => setModalHapus(false)}
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
text='Apakah anda yakin ingin menghapus persentase data kelahiran & kematian ini?'
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PersentaseDataKelahiranKematian;
|
||||||
@@ -141,7 +141,7 @@ export const navBar = [
|
|||||||
{
|
{
|
||||||
id: "Kesehatan_2",
|
id: "Kesehatan_2",
|
||||||
name: "Data Kesehatan Warga",
|
name: "Data Kesehatan Warga",
|
||||||
path: "/admin/kesehatan/data-kesehatan-warga"
|
path: "/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "Kesehatan_3",
|
id: "Kesehatan_3",
|
||||||
|
|||||||
@@ -13,19 +13,23 @@ type FormCreate = Prisma.DokterdanTenagaMedisGetPayload<{
|
|||||||
async function dokterDantenagamedisCreate(context: Context) {
|
async function dokterDantenagamedisCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.dokterdanTenagaMedis.create({
|
const created = await prisma.dokterdanTenagaMedis.create({
|
||||||
data: {
|
data: {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
specialist: body.specialist,
|
specialist: body.specialist,
|
||||||
jadwal: body.jadwal,
|
jadwal: body.jadwal,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
specialist: true,
|
||||||
|
jadwal: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create dokter dan tenaga medis",
|
message: "Success create dokter dan tenaga medis",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default dokterDantenagamedisCreate
|
export default dokterDantenagamedisCreate
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function dokterDantenagamedisDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.dokterdanTenagaMedis.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.dokterdanTenagaMedis.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function dokterDantenagamedisFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split("/");
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "ID is required",
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.dokterdanTenagaMedis.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import dokterDantenagamedisFindMany from "./find-many";
|
import dokterDantenagamedisFindMany from "./find-many";
|
||||||
import dokterDantenagamedisCreate from "./create";
|
import dokterDantenagamedisCreate from "./create";
|
||||||
|
import dokterDantenagamedisFindUnique from "./findUnique";
|
||||||
|
import dokterDantenagamedisUpdate from "./updt";
|
||||||
|
import dokterDantenagamedisDelete from "./del";
|
||||||
|
|
||||||
const DokterDantenagamedis = new Elysia({
|
const DokterDantenagamedis = new Elysia({
|
||||||
prefix: "/dokterdantenagamedis",
|
prefix: "/dokterdantenagamedis",
|
||||||
@@ -14,5 +17,24 @@ const DokterDantenagamedis = new Elysia({
|
|||||||
jadwal: t.String(),
|
jadwal: t.String(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await dokterDantenagamedisFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
|
.put(":/id", dokterDantenagamedisUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
name: t.String(),
|
||||||
|
specialist: t.String(),
|
||||||
|
jadwal: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.delete("/del/:id", dokterDantenagamedisDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
export default DokterDantenagamedis
|
export default DokterDantenagamedis
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function dokterDantenagamedisUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak ditemukan",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { nama, spesialis, jadwal } = context.body as {
|
||||||
|
nama: string;
|
||||||
|
spesialis: string;
|
||||||
|
jadwal: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const existing = await prisma.dokterdanTenagaMedis.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.dokterdanTenagaMedis.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
name: nama,
|
||||||
|
specialist: spesialis,
|
||||||
|
jadwal,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -11,18 +11,19 @@ type FormCreate = Prisma.FasilitasPendukungGetPayload<{
|
|||||||
async function FasilitasPendukungCreate(context: Context){
|
async function FasilitasPendukungCreate(context: Context){
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.fasilitasPendukung.create({
|
const created = await prisma.fasilitasPendukung.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
content: body.content
|
content: body.content
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
content: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create fasilitas pendukung",
|
message: "Success create fasilitas pendukung",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function fasilitasPendukungDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.fasilitasPendukung.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.fasilitasPendukung.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function fasilitasPendukungFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID is required",
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID must be a string",
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.fasilitasPendukung.findUnique({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 })
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,35 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import fasilitasPendukungFindMany from "./find-many";
|
|
||||||
import FasilitasPendukungCreate from "./create";
|
import FasilitasPendukungCreate from "./create";
|
||||||
|
import fasilitasPendukungFindMany from "./find-many";
|
||||||
|
import fasilitasPendukungFindUnique from "./findUnique";
|
||||||
|
import fasilitasPendukungUpdate from "./updt";
|
||||||
|
|
||||||
const FasilitasPendukung = new Elysia({
|
const FasilitasPendukung = new Elysia({
|
||||||
prefix: "/fasilitaspendukung",
|
prefix: "/fasilitaspendukung",
|
||||||
tags: ["Data Kesehatan/Fasilitas Kesehatan/Fasilitas Pendukung"],
|
tags: ["Data Kesehatan/Fasilitas Kesehatan/Fasilitas Pendukung"],
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await fasilitasPendukungFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", fasilitasPendukungFindMany)
|
.get("/find-many", fasilitasPendukungFindMany)
|
||||||
.post("/create", FasilitasPendukungCreate, {
|
.post("/create", FasilitasPendukungCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
content: t.String(),
|
content: t.String(),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
|
.put(":/id", fasilitasPendukungUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
content: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.delete("/del/:id", FasilitasPendukungCreate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
export default FasilitasPendukung;
|
export default FasilitasPendukung;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function fasilitasPendukungUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {content} = context.body as {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.fasilitasPendukung.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.fasilitasPendukung.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
content: content,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,19 +12,23 @@ type FormCreate = Prisma.InformasiUmumGetPayload<{
|
|||||||
async function informasiUmumCreate(context: Context) {
|
async function informasiUmumCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.informasiUmum.create({
|
const created = await prisma.informasiUmum.create({
|
||||||
data: {
|
data: {
|
||||||
fasilitas: body.fasilitas,
|
fasilitas: body.fasilitas,
|
||||||
alamat: body.alamat,
|
alamat: body.alamat,
|
||||||
jamOperasional: body.jamOperasional,
|
jamOperasional: body.jamOperasional,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
fasilitas: true,
|
||||||
|
alamat: true,
|
||||||
|
jamOperasional: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return{
|
return{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create informasi umum",
|
message: "Success create informasi umum",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function informasiumumDelete(context: Context){
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.informasiUmum.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.informasiUmum.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function informasiUmumFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID is required",
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.informasiUmum.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import informasiUmumFindMany from "./find-many";
|
import informasiUmumFindMany from "./find-many";
|
||||||
import informasiUmumCreate from "./create";
|
import informasiUmumCreate from "./create";
|
||||||
|
import informasiUmumFindUnique from "./findUnique";
|
||||||
|
import informasiumumUpdate from "./updt";
|
||||||
|
import informasiumumDelete from "./del";
|
||||||
|
|
||||||
const InformasiUmum = new Elysia({
|
const InformasiUmum = new Elysia({
|
||||||
prefix: "/informasiumum",
|
prefix: "/informasiumum",
|
||||||
tags: ["Data Kesehatan/Fasilitas Kesehatan/Informasi Umum"],
|
tags: ["Data Kesehatan/Fasilitas Kesehatan/Informasi Umum"],
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await informasiUmumFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", informasiUmumFindMany)
|
.get("/find-many", informasiUmumFindMany)
|
||||||
.post("/create", informasiUmumCreate, {
|
.post("/create", informasiUmumCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
@@ -13,6 +20,21 @@ const InformasiUmum = new Elysia({
|
|||||||
alamat: t.String(),
|
alamat: t.String(),
|
||||||
jamOperasional: t.String(),
|
jamOperasional: t.String(),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
|
.put(":/id", informasiumumUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
fasilitas: t.String(),
|
||||||
|
alamat: t.String(),
|
||||||
|
jamOperasional: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.delete("/del/:id", informasiumumDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
export default InformasiUmum;
|
export default InformasiUmum;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function informasiumumUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {fasilitas, alamat, jamOperasional} = context.body as {
|
||||||
|
fasilitas: string;
|
||||||
|
alamat: string;
|
||||||
|
jamOperasional: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.informasiUmum.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.informasiUmum.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
fasilitas: fasilitas,
|
||||||
|
alamat: alamat,
|
||||||
|
jamOperasional: jamOperasional,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,17 +11,19 @@ type FormCreate = Prisma.LayananUnggulanGetPayload<{
|
|||||||
async function layananUnggulanCreate(context: Context) {
|
async function layananUnggulanCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.layananUnggulan.create({
|
const created = await prisma.layananUnggulan.create({
|
||||||
data: {
|
data: {
|
||||||
content: body.content
|
content: body.content
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
content: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create layanan unggulan",
|
message: "Success create layanan unggulan",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function layananUnggulanDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.layananUnggulan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.layananUnggulan.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function layananUnggulanFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID is required",
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID must be a string",
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.layananUnggulan.findUnique({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 })
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,37 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import layananUnggulanCreate from "./create";
|
import layananUnggulanCreate from "./create";
|
||||||
import layananUnggulanFindMany from "./find-many";
|
import layananUnggulanFindMany from "./find-many";
|
||||||
|
import layananUnggulanFindUnique from "./findUnique";
|
||||||
|
import layananUnggulanUpdate from "./updt";
|
||||||
|
import layananUnggulanDelete from "./del";
|
||||||
|
|
||||||
const LayananUnggulan = new Elysia({
|
const LayananUnggulan = new Elysia({
|
||||||
prefix: "/layananunggulan",
|
prefix: "/layananunggulan",
|
||||||
tags: ["Data Kesehatan/Fasilitas Kesehatan/Layanan Unggulan"]
|
tags: ["Data Kesehatan/Fasilitas Kesehatan/Layanan Unggulan"]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await layananUnggulanFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", layananUnggulanFindMany)
|
.get("/find-many", layananUnggulanFindMany)
|
||||||
.post("/create", layananUnggulanCreate, {
|
.post("/create", layananUnggulanCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
content: t.String()
|
content: t.String()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.put("/:id", layananUnggulanUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
content: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.delete("/del/:id", layananUnggulanDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
export default LayananUnggulan
|
export default LayananUnggulan
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function layananUnggulanUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {content} = context.body as {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.layananUnggulan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.layananUnggulan.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
content: content,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,17 +11,19 @@ type FormCreate = Prisma.ProsedurPendaftaranGetPayload<{
|
|||||||
async function prosedurPendaftaranCreate(context: Context) {
|
async function prosedurPendaftaranCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.prosedurPendaftaran.create({
|
const created = await prisma.prosedurPendaftaran.create({
|
||||||
data: {
|
data: {
|
||||||
content: body.content
|
content: body.content
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
content: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return{
|
return{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create prosedur pendaftaran",
|
message: "Success create prosedur pendaftaran",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function prosedurPendaftaranDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.prosedurPendaftaran.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.prosedurPendaftaran.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function prosedurPendaftaranFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak boleh kosong",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.prosedurPendaftaran.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
data: data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,35 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import prosedurPendaftaranFindMany from "./find-many";
|
import prosedurPendaftaranFindMany from "./find-many";
|
||||||
import prosedurPendaftaranCreate from "./create";
|
import prosedurPendaftaranCreate from "./create";
|
||||||
|
import prosedurPendaftaranFindUnique from "./findUnique";
|
||||||
|
import persentaseKelahiranKematianUpdate from "../../persentase_kelahiran_kematian/updt";
|
||||||
|
import prosedurPendaftaranDelete from "./del";
|
||||||
|
|
||||||
const ProsedurPendaftaran = new Elysia({
|
const ProsedurPendaftaran = new Elysia({
|
||||||
prefix: "/prosedurpendaftaran",
|
prefix: "/prosedurpendaftaran",
|
||||||
tags: ["Data Kesehatan/Fasilitas Kesehatan/Prosedur Pendaftaran"],
|
tags: ["Data Kesehatan/Fasilitas Kesehatan/Prosedur Pendaftaran"],
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await prosedurPendaftaranFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", prosedurPendaftaranFindMany)
|
.get("/find-many", prosedurPendaftaranFindMany)
|
||||||
.post("/create", prosedurPendaftaranCreate, {
|
.post("/create", prosedurPendaftaranCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
content: t.String(),
|
content: t.String(),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
|
.put("/:id", persentaseKelahiranKematianUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
content: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.delete("del/:id", prosedurPendaftaranDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
export default ProsedurPendaftaran;
|
export default ProsedurPendaftaran;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function prosedurPendaftaranUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {content} = context.body as {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.prosedurPendaftaran.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.prosedurPendaftaran.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
content: content,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,18 +12,21 @@ type FormCreate = Prisma.TarifDanLayananGetPayload<{
|
|||||||
async function tarifdanlayananCreate(context: Context) {
|
async function tarifdanlayananCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.tarifDanLayanan.create({
|
const created = await prisma.tarifDanLayanan.create({
|
||||||
data: {
|
data: {
|
||||||
layanan: body.layanan,
|
layanan: body.layanan,
|
||||||
tarif: body.tarif,
|
tarif: body.tarif,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
layanan: true,
|
||||||
|
tarif: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create tarif dan layanan",
|
message: "Success create tarif dan layanan",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function tarifDanLayananDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.tarifDanLayanan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.tarifDanLayanan.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function tarifDanLayananFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: 'ID tidak ditemukan',
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: 'ID tidak valid',
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.tarifDanLayanan.findUnique({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: 'Data tidak ditemukan',
|
||||||
|
}, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
data,
|
||||||
|
}, { status: 200 })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching data:', error)
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: 'Terjadi kesalahan saat mengambil data',
|
||||||
|
}, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import tarifdanlayananFindMany from "./find-many";
|
import tarifdanlayananFindMany from "./find-many";
|
||||||
import tarifdanlayananCreate from "./create";
|
import tarifdanlayananCreate from "./create";
|
||||||
|
import tarifDanLayananFindUnique from "./findUnique";
|
||||||
|
import tarifDanLayananUpdate from "./updt";
|
||||||
|
import tarifDanLayananDelete from "./del";
|
||||||
|
|
||||||
|
|
||||||
const TarifDanLayanan = new Elysia({
|
const TarifDanLayanan = new Elysia({
|
||||||
prefix: "/tarifdanlayanan",
|
prefix: "/tarifdanlayanan",
|
||||||
tags: ["Data Kesehatan/Fasilitas Kesehatan/Tarif dan Layanan"]
|
tags: ["Data Kesehatan/Fasilitas Kesehatan/Tarif dan Layanan"]
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await tarifDanLayananFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", tarifdanlayananFindMany)
|
.get("/find-many", tarifdanlayananFindMany)
|
||||||
.post("/create", tarifdanlayananCreate, {
|
.post("/create", tarifdanlayananCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
@@ -14,5 +21,18 @@ const TarifDanLayanan = new Elysia({
|
|||||||
tarif: t.String(),
|
tarif: t.String(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.put("/:id", tarifDanLayananUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
layanan: t.String(),
|
||||||
|
tarif: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.delete("/del/:id", tarifDanLayananDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
export default TarifDanLayanan;
|
export default TarifDanLayanan;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function tarifDanLayananUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { layanan, tarif } = context.body as {
|
||||||
|
layanan: string;
|
||||||
|
tarif: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.tarifDanLayanan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.tarifDanLayanan.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
layanan: layanan,
|
||||||
|
tarif: tarif,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,17 +11,20 @@ type FormCreate = Prisma.GrafikKepuasanGetPayload<{
|
|||||||
export default async function grafikKepuasanCreate(context: Context) {
|
export default async function grafikKepuasanCreate(context: Context) {
|
||||||
const body = context.body as FormCreate;
|
const body = context.body as FormCreate;
|
||||||
|
|
||||||
await prisma.grafikKepuasan.create({
|
const created = await prisma.grafikKepuasan.create({
|
||||||
data: {
|
data: {
|
||||||
label: body.label,
|
label: body.label,
|
||||||
jumlah: body.jumlah,
|
jumlah: body.jumlah,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
label: true,
|
||||||
|
jumlah: true,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create grafik kepuasan",
|
message: "Success create grafik kepuasan",
|
||||||
data: {
|
data: created,
|
||||||
...body,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function grafikKepuasanDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak ditemukan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.grafikKepuasan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.grafikKepuasan.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function grafikKepuasanFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: 'ID tidak boleh kosong',
|
||||||
|
}, {status: 400})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.grafikKepuasan.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import grafikKepuasanCreate from "./create";
|
import grafikKepuasanCreate from "./create";
|
||||||
import grafikKepuasanFindMany from "./find-many";
|
import grafikKepuasanFindMany from "./find-many";
|
||||||
|
import grafikKepuasanFindUnique from "./findUnique";
|
||||||
|
import grafikKepuasanUpdate from "./updt";
|
||||||
|
import grafikKepuasanDelete from "./del";
|
||||||
|
|
||||||
const GrafikKepuasan = new Elysia({
|
const GrafikKepuasan = new Elysia({
|
||||||
prefix: "/grafikkepuasan",
|
prefix: "/grafikkepuasan",
|
||||||
tags: ["Data Kesehatan/Grafik Kepuasan"]
|
tags: ["Data Kesehatan/Grafik Kepuasan"]
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await grafikKepuasanFindUnique(new Request(context.request));
|
||||||
|
return response;
|
||||||
|
})
|
||||||
.get("/find-many", grafikKepuasanFindMany)
|
.get("/find-many", grafikKepuasanFindMany)
|
||||||
.post("/create", grafikKepuasanCreate, {
|
.post("/create", grafikKepuasanCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
@@ -13,4 +20,18 @@ const GrafikKepuasan = new Elysia({
|
|||||||
jumlah: t.String(),
|
jumlah: t.String(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
.put("/:id", grafikKepuasanUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
label: t.String(),
|
||||||
|
jumlah: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.delete("/del/:id", grafikKepuasanDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
export default GrafikKepuasan
|
export default GrafikKepuasan
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function grafikKepuasanUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak ditemukan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {label, jumlah} = context.body as {
|
||||||
|
label: string;
|
||||||
|
jumlah: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.grafikKepuasan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.grafikKepuasan.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
label,
|
||||||
|
jumlah,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,19 +14,24 @@ type FormCreate = Prisma.DataKematian_KelahiranGetPayload<{
|
|||||||
export default async function persentaseKelahiranKematianCreate(context: Context) {
|
export default async function persentaseKelahiranKematianCreate(context: Context) {
|
||||||
const body = context.body as FormCreate
|
const body = context.body as FormCreate
|
||||||
|
|
||||||
await prisma.dataKematian_Kelahiran.create({
|
const created = await prisma.dataKematian_Kelahiran.create({
|
||||||
data: {
|
data: {
|
||||||
tahun: body.tahun,
|
tahun: body.tahun,
|
||||||
kematianKasar: body.kematianKasar,
|
kematianKasar: body.kematianKasar,
|
||||||
kematianBayi: body.kematianBayi,
|
kematianBayi: body.kematianBayi,
|
||||||
kelahiranKasar: body.kelahiranKasar,
|
kelahiranKasar: body.kelahiranKasar,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
tahun: true,
|
||||||
|
kematianKasar: true,
|
||||||
|
kematianBayi: true,
|
||||||
|
kelahiranKasar: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return{
|
return{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success create persentase kelahiran kematian",
|
message: "Success create persentase kelahiran kematian",
|
||||||
data: {
|
data: created
|
||||||
...body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function persentaseKelahiranKematianDelete(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.dataKematian_Kelahiran.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await prisma.dataKematian_Kelahiran.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil dihapus",
|
||||||
|
data: deleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function persentaseKelahiranKematianFindUnique(request: Request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const pathSegments = url.pathname.split('/');
|
||||||
|
const id = pathSegments[pathSegments.length - 1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak boleh kosong",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof id !== 'string') {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "ID tidak valid",
|
||||||
|
}, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.dataKematian_Kelahiran.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengambil data berdasarkan ID",
|
||||||
|
data,
|
||||||
|
}, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return Response.json({
|
||||||
|
success: false,
|
||||||
|
message: "Terjadi kesalahan saat mengambil data",
|
||||||
|
}, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import persentaseKelahiranKematianCreate from "./create";
|
import persentaseKelahiranKematianCreate from "./create";
|
||||||
import persentaseKelahiranKematianFindMany from "./find-many";
|
import persentaseKelahiranKematianFindMany from "./find-many";
|
||||||
|
import persentaseKelahiranKematianFindUnique from "./findUnique";
|
||||||
|
import persentaseKelahiranKematianUpdate from "./updt";
|
||||||
|
import persentaseKelahiranKematianDelete from "./del";
|
||||||
|
|
||||||
const PersentaseKelahiranKematian = new Elysia({
|
const PersentaseKelahiranKematian = new Elysia({
|
||||||
prefix: "/persentasekelahiran",
|
prefix: "/persentasekelahiran",
|
||||||
tags: ["Data Kesehatan/Persentase Kelahiran Kematian"],
|
tags: ["Data Kesehatan/Persentase Kelahiran Kematian"],
|
||||||
})
|
})
|
||||||
|
.get("/:id", async (context) => {
|
||||||
|
const response = await persentaseKelahiranKematianFindUnique(new Request(context.request))
|
||||||
|
return response
|
||||||
|
})
|
||||||
.get("/find-many", persentaseKelahiranKematianFindMany)
|
.get("/find-many", persentaseKelahiranKematianFindMany)
|
||||||
.post("/create", persentaseKelahiranKematianCreate, {
|
.post("/create", persentaseKelahiranKematianCreate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
@@ -15,5 +22,20 @@ const PersentaseKelahiranKematian = new Elysia({
|
|||||||
kelahiranKasar: t.String(),
|
kelahiranKasar: t.String(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
.put("/:id", persentaseKelahiranKematianUpdate, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
body: t.Object({
|
||||||
|
tahun: t.String(),
|
||||||
|
kematianKasar: t.String(),
|
||||||
|
kematianBayi: t.String(),
|
||||||
|
kelahiranKasar: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.delete("/del/:id", persentaseKelahiranKematianDelete, {
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
export default PersentaseKelahiranKematian;
|
export default PersentaseKelahiranKematian;
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export default async function persentaseKelahiranKematianUpdate(context: Context) {
|
||||||
|
const id = context.params?.id;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Id tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {tahun, kematianKasar, kematianBayi, kelahiranKasar} = context.body as {
|
||||||
|
tahun: string;
|
||||||
|
kematianKasar: string;
|
||||||
|
kematianBayi: string;
|
||||||
|
kelahiranKasar: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await prisma.dataKematian_Kelahiran.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Data tidak ditemukan",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await prisma.dataKematian_Kelahiran.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
tahun,
|
||||||
|
kematianKasar,
|
||||||
|
kematianBayi,
|
||||||
|
kelahiranKasar,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Data berhasil diupdate",
|
||||||
|
data: updated,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user