# Bloodwork Tracker - Nokken Documentation
Documentation for the Nokken medical tracking application
Author: Charlotte Croce

Skip to content

# Bloodwork Tracker

The bloodwork tracker feature helps users manage their lab results, medical appointments, and visualize trends in hormone levels over time.

## Models

- `Bloodwork`: Primary model for lab tests and medical appointments.

      class Bloodwork {
        final String id;
        final DateTime date;
        final AppointmentType appointmentType;
        final List<HormoneReading> hormoneReadings;
        final String? location;
        final String? doctor;
        final String? notes;
      }

- `HormoneReading`: Represents an individual hormone measurement with value and unit.

      class HormoneReading {
        final String name;
        final double value;
        final String unit;

        // Serialization methods
        Map<String, dynamic> toJson() {...}
        factory HormoneReading.fromJson(Map<String, dynamic> json) {...}
      }

- `AppointmentType`: Enumeration for different types of medical appointments (bloodwork, appointment, surgery).
- `HormoneTypes`: Contains predefined hormone types with their default units.

## Providers

- `bloodworkStateProvider`: Manages bloodwork CRUD operations
- Various derived providers:

    // Main state providers
    final bloodworkStateProvider = StateNotifierProvider<BloodworkNotifier, BloodworkState>

    // Derived providers
    final bloodworkRecordsProvider = Provider<List<Bloodwork>>
    final bloodworkLoadingProvider = Provider<bool>
    final bloodworkErrorProvider = Provider<String?>
    final sortedBloodworkProvider = Provider<List<Bloodwork>>
    final bloodworkTypeRecordsProvider = Provider<List<Bloodwork>>
    final bloodworkDatesProvider = Provider<Set<DateTime>>
    final groupedBloodworkProvider = Provider<Map<String, List<Bloodwork>>>
    final hormoneTypesProvider = Provider<List<String>>
    final hormoneRecordsProvider = Provider.family<List<MapEntry<DateTime, double>>, String>
    final latestHormoneValueProvider = Provider.family<double?, String>

### State Notifier

    class BloodworkNotifier extends StateNotifier<BloodworkState> {
      // Notifier methods
      Future<void> loadBloodwork() async {...}
      Future<void> addBloodwork(Bloodwork bloodwork) async {...}
      Future<void> updateBloodwork(Bloodwork bloodwork) async {...}
      Future<void> deleteBloodwork(String id) async {...}
    }

## Screens

- `BloodworkListScreen`: List of all appointments organized by upcoming/past/today.
- `AddEditBloodworkScreen`: Form for adding and editing appointments and lab results.
- `BloodLevelListScreen`: Overview display of all tracked hormone levels with mini graphs.
- `BloodworkGraphScreen`: Visualizations of hormone levels over time with reference ranges.

## Interactions

- Uses `DatabaseService` for persistent storage of bloodwork data
- Interacts with Scheduler feature to display appointments on calendar and daily views
- Uses `ValidationService` for data validation