# Forms Aggregation Service

This directory contains services responsible for handling data aggregation and side effects related to form submissions within the system.

## FilledFormsAggregationService

`FilledFormsAggregationService` is triggered when a `FilledDocument` is created, updated, or deleted. Its primary responsibility is to keep the corresponding `Appointment` document synchronized with the state of its associated forms.

### Core Functions:

- **`handleFilledFormCreateOrUpdate`**: When a form is filled or updated, this function updates the `linkedForms` array on the parent `Appointment` document. It fetches the correct document template (including the specific version) to retrieve the form's `title` and other metadata, ensuring the appointment has up-to-date information about the form's status, path, and title.
- **`handleFilledFormDelete`**: When a filled form is deleted, this function removes the corresponding entry from the `linkedForms` and `linkedFormIds` arrays on the `Appointment` document.
- **`handleRequiredUserFormCreate`**: When a new form that is marked as `isRequired` is created for a user, this function adds the form's ID to the `pendingUserFormsIds` array on the `Appointment`, helping track incomplete required forms.
