Skip to content

Latest commit

 

History

History
194 lines (172 loc) · 6.16 KB

002.4.APP_APOTEK_FLUTTERFIRE.md

File metadata and controls

194 lines (172 loc) · 6.16 KB

SUDAH MENGIKUTI LANGKAH 3️⃣.

Langkah berikutnya adalah Laporan Data Pasien dan Laporan Hasil Pemeriksaan. Fitur ini memungkinkan admin untuk melihat semua data pasien dan hasil pemeriksaan yang sudah tersimpan di Firebase Firestore.


1. Laporan Data Pasien

Buat Layar Laporan Pasien

Buat file baru: screens/patient_report_screen.dart.

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class PatientReportScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Laporan Data Pasien')),
      body: StreamBuilder<QuerySnapshot>(
        stream: FirebaseFirestore.instance.collection('patients').snapshots(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Center(child: CircularProgressIndicator());
          }
          if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
            return Center(child: Text('Tidak ada data pasien.'));
          }

          final patients = snapshot.data!.docs;

          return ListView.builder(
            itemCount: patients.length,
            itemBuilder: (context, index) {
              final data = patients[index].data() as Map<String, dynamic>;
              return Card(
                margin: EdgeInsets.all(8.0),
                child: ListTile(
                  title: Text(data['nama']),
                  subtitle: Text('Alamat: ${data['alamat']}\nNo. HP: ${data['noHp']}'),
                  trailing: Text(data['id']),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

2. Laporan Hasil Pemeriksaan

Buat Layar Laporan Pemeriksaan

Buat file baru: screens/medical_report_screen.dart.

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class MedicalReportScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Laporan Hasil Pemeriksaan')),
      body: StreamBuilder<QuerySnapshot>(
        stream: FirebaseFirestore.instance.collection('medical_checks').snapshots(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Center(child: CircularProgressIndicator());
          }
          if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
            return Center(child: Text('Tidak ada hasil pemeriksaan.'));
          }

          final checks = snapshot.data!.docs;

          return ListView.builder(
            itemCount: checks.length,
            itemBuilder: (context, index) {
              final data = checks[index].data() as Map<String, dynamic>;
              return Card(
                margin: EdgeInsets.all(8.0),
                child: ListTile(
                  title: Text('ID Pasien: ${data['patientId']}'),
                  subtitle: Text(
                    'Suhu: ${data['suhu']} °C\n'
                    'Tekanan Darah: ${data['tekananDarah']}\n'
                    'Diagnosa: ${data['diagnosa']}\n'
                    'Obat: ${data['obat']} (${data['dosis']})',
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

3. Tambahkan Navigasi untuk Laporan

Buka screens/home_screen.dart dan tambahkan tombol untuk membuka layar laporan.

import 'package:flutter/material.dart';
import 'registration_screen.dart';
import 'medical_check_screen.dart';
import 'patient_report_screen.dart';
import 'medical_report_screen.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Poliklinik App')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => RegistrationScreen()),
                );
              },
              child: const Text('Pendaftaran Pasien'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => MedicalCheckScreen()),
                );
              },
              child: const Text('Pemeriksaan Pasien'),
            ),
            SizedBox(height: 20),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => PatientReportScreen()),
                    );
                  },
                  child: Text('Laporan Data Pasien'),
                ),
                SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => MedicalReportScreen()),
                    );
                  },
                  child: Text('Laporan Hasil Pemeriksaan'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Testing

  1. Jalankan aplikasi dan navigasikan ke Laporan Data Pasien untuk melihat data pasien yang sudah terdaftar.
  2. Navigasikan ke Laporan Hasil Pemeriksaan untuk melihat hasil pemeriksaan pasien.
  3. Pastikan semua data tampil sesuai dengan isi Firestore.

Next Step

Menambahkan fitur Update data / Edit.