diff --git a/project/app/Http/Controllers/PengukuranBalitaController.php b/project/app/Http/Controllers/PengukuranBalitaController.php
index c6b92cd..611850d 100644
--- a/project/app/Http/Controllers/PengukuranBalitaController.php
+++ b/project/app/Http/Controllers/PengukuranBalitaController.php
@@ -160,21 +160,24 @@ public function cetakPdf(Request $request, $id)
}
// PengukuranBalitaController.php
- public function getLastPengukuran($id)
+ public function getLastPengukuran($id)
{
$last = PengukuranBalita::where('balita_id', $id)
->orderBy('tanggal', 'desc')
- ->first();
+ ->take(5)
+ ->get();
- if ($last) {
+ if ($last->isNotEmpty()) {
return response()->json([
- 'found' => true,
- 'tanggal' => $last->tanggal,
- 'usia_saat_ukur' => $last->usia_saat_ukur,
- 'berat_badan' => $last->berat_badan,
- 'tinggi_badan' => $last->tinggi_badan,
- 'lingkar_kepala' => $last->lingkar_kepala,
- 'hasil' => $last->hasil ?? null, // jika ada kolom ini
+ 'found' => true,
+ 'data' => $last->map(fn($item) => [
+ 'tanggal' => $item->tanggal,
+ 'usia' => $item->usia_saat_ukur,
+ 'berat_badan' => $item->berat_badan,
+ 'tinggi_badan' => $item->tinggi_badan,
+ 'lingkar_kepala' => $item->lingkar_kepala,
+ 'hasil' => $item->hasil ?? '-',
+ ])
]);
}
diff --git a/project/app/Http/Controllers/PengukuranIbuHamilController.php b/project/app/Http/Controllers/PengukuranIbuHamilController.php
index de49e24..1bcb670 100644
--- a/project/app/Http/Controllers/PengukuranIbuHamilController.php
+++ b/project/app/Http/Controllers/PengukuranIbuHamilController.php
@@ -160,17 +160,20 @@ public function getLastPengukuran($id)
{
$last = PengukuranIbuHamil::where('ibu_hamil_id', $id)
->orderBy('tanggal', 'desc')
- ->first();
+ ->take(5)
+ ->get();
- if ($last) {
+ if ($last->isNotEmpty()) {
return response()->json([
- 'found' => true,
- 'tanggal' => $last->tanggal,
- 'usia_kehamilan' => $last->usia_kehamilan,
- 'berat_badan' => $last->berat_badan,
- 'tinggi_badan' => $last->tinggi_badan,
- 'lila' => $last->lila,
- 'status_gizi' => $last->status_gizi ?? null, // tambah ini
+ 'found' => true,
+ 'data' => $last->map(fn($item) => [
+ 'tanggal' => $item->tanggal,
+ 'usia_kehamilan' => $item->usia_kehamilan,
+ 'berat_badan' => $item->berat_badan,
+ 'tinggi_badan' => $item->tinggi_badan,
+ 'lila' => $item->lila,
+ 'status_gizi' => $item->status_gizi ?? '-',
+ ])
]);
}
diff --git a/project/resources/views/pengukuran_balita/create.blade.php b/project/resources/views/pengukuran_balita/create.blade.php
index 60596e0..1c5b4b9 100644
--- a/project/resources/views/pengukuran_balita/create.blade.php
+++ b/project/resources/views/pengukuran_balita/create.blade.php
@@ -99,49 +99,30 @@
+
{{-- History Pengukuran Terakhir --}}
-
-
+
+
- Pengukuran Terakhir
-
+ Riwayat 5 Pengukuran Terakhir
-
-
-
-
-
-
Tinggi Badan
-
-
-
cm
-
-
-
-
-
Lingkar Kepala
-
-
-
cm
-
-
-
- {{-- Tampilkan status gizi jika ada --}}
-
-
-
+
+
+
+
+ | Tanggal |
+ Usia |
+ Berat Badan |
+ Tinggi Badan |
+ Lingkar Kepala |
+ Status Gizi |
+
+
+
+ {{-- diisi via JavaScript --}}
+
+
@@ -176,7 +157,8 @@
$('#balita_id').select2({
placeholder: 'Cari nama balita...',
allowClear: true,
- width: '100%'
+ width: '100%',
+ dropdownParent: $('body')
});
$('#balita_id').on('change', function() {
@@ -188,15 +170,14 @@
});
function updateData() {
- let sel = document.getElementById("balita_id");
- let opt = sel.options[sel.selectedIndex];
+ let opt = $('#balita_id option:selected');
- if (opt && opt.value) {
- let jk = opt.getAttribute("data-jk");
+ if (opt && opt.val()) {
+ let jk = opt.attr("data-jk");
document.getElementById("jk_display").value = (jk == 1) ? "Laki-laki" : "Perempuan";
document.getElementById("jk_input").value = jk;
- let tglLahir = new Date(opt.getAttribute("data-tgl"));
+ let tglLahir = new Date(opt.attr("data-tgl"));
let tglUkur = new Date(document.getElementById("tanggal_ukur").value);
let totalBulan = (tglUkur.getFullYear() - tglLahir.getFullYear()) * 12
+ (tglUkur.getMonth() - tglLahir.getMonth());
@@ -205,10 +186,10 @@ function updateData() {
document.getElementById("usia_display").value = (totalBulan < 0 ? 0 : totalBulan) + " Bulan";
document.getElementById("usia_input").value = (totalBulan < 0 ? 0 : totalBulan);
} else {
- document.getElementById("jk_display").value = '';
- document.getElementById("jk_input").value = '';
+ document.getElementById("jk_display").value = '';
+ document.getElementById("jk_input").value = '';
document.getElementById("usia_display").value = '';
- document.getElementById("usia_input").value = '';
+ document.getElementById("usia_input").value = '';
}
}
@@ -218,25 +199,48 @@ function fetchLastHistory(balitaId) {
return;
}
- $.get(`/pengukuran-balita/last/${balitaId}`, function(data) {
- if (data.found) {
- $('#last-tanggal').text(data.tanggal);
- $('#last-usia').text(data.usia_saat_ukur);
- $('#last-bb').text(data.berat_badan);
- $('#last-tb').text(data.tinggi_badan);
- $('#last-lk').text(data.lingkar_kepala);
+ $.ajax({
+ url: `{{ url('/pengukuran-balita/last') }}/${balitaId}`,
+ type: 'GET',
+ headers: {
+ 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
+ },
+ success: function(data) {
+ if (data.found) {
+ let rows = '';
+ data.data.forEach(function(item, index) {
+ let badgeColor = '#6c757d';
+ let hasil = item.hasil || '-';
- // Tampilkan status gizi jika ada
- if (data.hasil) {
- $('#last-status').text(data.hasil);
- $('#last-status-wrap').show();
+ if (hasil.toLowerCase().includes('sangat pendek')) badgeColor = '#dc3545'; // merah
+ else if (hasil.toLowerCase().includes('pendek')) badgeColor = '#fd7e14'; // oranye
+ else if (hasil.toLowerCase().includes('normal')) badgeColor = '#28a745'; // hijau
+ else if (hasil.toLowerCase().includes('tinggi')) badgeColor = '#0d6efd'; // biru
+
+ rows += `
+
+ | ${item.tanggal} |
+ ${item.usia} bulan |
+ ${item.berat_badan} kg |
+ ${item.tinggi_badan} cm |
+ ${item.lingkar_kepala} cm |
+
+
+ ${hasil}
+
+ |
+
+ `;
+ });
+
+ $('#last-history-tbody').html(rows);
+ $('#last-history').slideDown(300);
} else {
- $('#last-status-wrap').hide();
+ $('#last-history').slideUp(300);
}
-
- $('#last-history').slideDown(300);
- } else {
- $('#last-history').slideUp(300);
+ },
+ error: function(xhr) {
+ console.log('Error:', xhr.status, xhr.responseText);
}
});
}
diff --git a/project/resources/views/pengukuran_ibuhamil/create.blade.php b/project/resources/views/pengukuran_ibuhamil/create.blade.php
index f4d525c..148cbd8 100644
--- a/project/resources/views/pengukuran_ibuhamil/create.blade.php
+++ b/project/resources/views/pengukuran_ibuhamil/create.blade.php
@@ -128,46 +128,27 @@ class="form-control custom-input fs-5 fw-bold text-center"
{{-- History Pengukuran Terakhir --}}
-
-
+
+
- Pengukuran Terakhir
-
+ Riwayat 5 Pengukuran Terakhir
-
-
-
-
Usia Kehamilan
-
-
-
minggu
-
-
-
-
-
-
Tinggi Badan
-
-
-
cm
-
-
-
-
-
-
-
+
+
+
+
+ | Tanggal |
+ Usia Kehamilan |
+ Berat Badan |
+ Tinggi Badan |
+ LILA |
+ Status Gizi |
+
+
+
+ {{-- diisi via JavaScript --}}
+
+
@@ -227,29 +208,43 @@ class="form-control custom-input fs-5 fw-bold text-center"
// Fetch history pengukuran terakhir
if (ibuId) {
- $.get(`/pengukuran-ibu-hamil/last/${ibuId}`, function(data) {
- if (data.found) {
- $('#last-tanggal').text(data.tanggal);
- $('#last-usia-kehamilan').text(data.usia_kehamilan);
- $('#last-bb').text(data.berat_badan);
- $('#last-tb').text(data.tinggi_badan);
- $('#last-lila').text(data.lila);
+ $.get(`/pengukuran-ibu-hamil/last/${ibuId}`, function(data) {
+ if (data.found) {
+ let rows = '';
+ data.data.forEach(function(item, index) {
+ let badgeColor = '#6c757d'; // default abu
+ let status = item.status_gizi ?? '-';
- if (data.status_gizi) {
- $('#last-status').text(data.status_gizi);
- $('#last-status-wrap').show();
- } else {
- $('#last-status-wrap').hide();
- }
+ if (status.toLowerCase().includes('kurang')) badgeColor = '#dc3545'; // merah
+ else if (status.toLowerCase().includes('normal')) badgeColor = '#28a745'; // hijau
+ else if (status.toLowerCase().includes('lebih')) badgeColor = '#ffc107'; // kuning
+ else if (status.toLowerCase().includes('obesitas')) badgeColor = '#fd7e14'; // oranye
- $('#last-history').slideDown(300);
- } else {
- $('#last-history').slideUp(300);
- }
- });
- } else {
- $('#last-history').slideUp(300);
- }
+ rows += `
+
+ | ${item.tanggal} |
+ ${item.usia_kehamilan} minggu |
+ ${item.berat_badan} kg |
+ ${item.tinggi_badan} cm |
+ ${item.lila} cm |
+
+
+ ${status}
+
+ |
+
+ `;
+ });
+
+ $('#last-history-tbody').html(rows);
+ $('#last-history').slideDown(300);
+ } else {
+ $('#last-history').slideUp(300);
+ }
+ });
+ } else {
+ $('#last-history').slideUp(300);
+ }
});
});