Changes between Version 6 and Version 7 of RelationalModel


Ignore:
Timestamp:
09/14/26 12:54:39 (11 days ago)
Author:
231039
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RelationalModel

    v6 v7  
    44
    55[[Image(RelationalModel-PawCare.svg)]]
     6
     7== Entities ==
     8
     91. '''Owner''' – entity that stores information about pet owners.
     10 * owner_id (serial, primary key)
     11 * last_name (varchar, not null)
     12 * first_name (varchar, not null)
     13 * phone (varchar)
     14 * email (varchar, not null, unique)
     15 * address (varchar)
     16 * gender (varchar, check: 'M' or 'F')
     17
     182. '''Pet''' – entity that represents a pet registered at the clinic. The `age_display` field is a generated column that automatically computes a human-readable age based on `age`.
     19 * pet_id (serial, primary key)
     20 * name (varchar, not null)
     21 * is_active (boolean, not null, default: true)
     22 * type (varchar, check: 'mammal', 'bird', 'fish', 'amphibian', 'reptile')
     23 * breed (varchar)
     24 * age (integer, check: >= 0)
     25 * medical_history (text)
     26 * owner_id (foreign key -> owner.owner_id, not null)
     27 * age_display (text, generated always as ... stored)
     28
     293. '''Role''' – entity that defines employee roles at the clinic (e.g. veterinarian, assistant, receptionist).
     30 * role_id (serial, primary key)
     31 * name (varchar, not null)
     32 * description (varchar)
     33
     344. '''Employee''' – entity that represents a clinic employee. Employee has a self-reference (`supervised_by`) used to model a hierarchy between employees (e.g. an assistant supervised by a veterinarian).
     35 * employee_id (serial, primary key)
     36 * last_name (varchar, not null)
     37 * first_name (varchar, not null)
     38 * phone (varchar)
     39 * email (varchar, not null, unique)
     40 * address (varchar)
     41 * date_employment (date, default: current_date)
     42 * experience (integer, default: 0, check: >= 0)
     43 * role_id (foreign key -> role.role_id)
     44 * supervised_by (foreign key -> employee.employee_id, self-reference)
     45 * gender (varchar, check: 'M' or 'F')
     46
     475. '''Appointment''' – entity that represents the initial request/booking made by the owner (when and why the visit was requested). The actual scheduled slot, with an assigned employee and room, is stored separately in `Examination`.
     48 * appointment_id (serial, primary key)
     49 * date_appointment (date, not null)
     50 * reason (varchar, not null)
     51 * phone (varchar)
     52 * owner_id (foreign key -> owner.owner_id)
     53 * pet_id (foreign key -> pet.pet_id)
     54
     556. '''Specialization''' – entity that stores employees' specializations (one employee can have multiple specializations).
     56 * specialization_id (serial, primary key)
     57 * specialization (varchar, not null)
     58 * license_number (varchar, not null)
     59 * employee_id (foreign key -> employee.employee_id, not null)
     60
     617. '''Certificate''' – entity that stores employees' certificates.
     62 * certificate_id (serial, primary key)
     63 * certificate_name (varchar, not null)
     64 * employee_id (foreign key -> employee.employee_id, not null)
     65 * category (varchar)
     66
     678. '''Examination_room''' – entity that represents a room at the clinic (examination room, surgery room, laboratory, etc.).
     68 * examination_room_id (serial, primary key)
     69 * room_number (varchar, not null)
     70 * type (varchar, not null, check: 'examination', 'surgery', 'radiology', 'laboratory', 'isolation ward', 'patient ward')
     71 * capacity (integer, check: > 0)
     72 * status (varchar, default: 'available', check: 'available' or 'unavailable')
     73
     749. '''Examination''' – entity that represents the concrete scheduled slot: when it takes place, which employee handles it, in which room, and its current status. It is linked to `Appointment` (the initial request) and is the entity that all treatments (`Treatment`) attach to.
     75 * examination_id (serial, primary key)
     76 * date_examination (date, not null, default: current_date)
     77 * status (varchar, not null, default: 'scheduled', check: 'scheduled', 'completed', 'cancelled')
     78 * description (text)
     79 * appointment_id (foreign key -> appointment.appointment_id)
     80 * employee_id (foreign key -> employee.employee_id)
     81 * examination_room_id (foreign key -> examination_room.examination_room_id)
     82
     8310. '''Coupon''' – entity that represents a discount coupon that can be applied to an entire invoice.
     84 * coupon_id (serial, primary key)
     85 * code (varchar, not null, unique)
     86 * type (varchar, not null, check: 'fixed' or 'percentage')
     87 * value (numeric, not null, check: >= 0)
     88 * valid_from (date, not null, default: current_date)
     89 * valid_to (date, not null)
     90 * usage_limit (integer, not null, default: 1)
     91 * usage_count (integer, not null, default: 0)
     92 * is_active (boolean, not null, default: true)
     93 * min_total (numeric, default: 0, check: >= 0)
     94
     9511. '''Shop_item_category''' – entity that categorizes products in the shop. It has a self-reference (`parent_id`) to allow a hierarchy of categories and subcategories.
     96 * shop_item_category_id (serial, primary key)
     97 * name (varchar, not null)
     98 * parent_id (foreign key -> shop_item_category.shop_item_category_id, self-reference)
     99
     10012. '''Shop_item''' – entity that represents a product sold in the clinic's shop (e.g. medicine, food, equipment).
     101 * shop_item_id (serial, primary key)
     102 * name (varchar, not null)
     103 * price (numeric, not null, check: >= 0)
     104 * stock (integer, default: 0, check: >= 0)
     105 * shop_item_category_id (foreign key -> shop_item_category.shop_item_category_id)
     106
     10713. '''Shop_item_attribute''' – entity that defines which attributes are relevant for products in a given category (e.g. "weight" for food, "expiration date" for medicine). It is split into its own entity to enable an EAV (Entity-Attribute-Value) pattern, since different product categories have different sets of attributes and it isn't practical for every attribute to be its own column on `Shop_item`.
     108 * shop_item_attribute_id (serial, primary key)
     109 * name (varchar, not null)
     110 * data_type (varchar, not null, check: 'text', 'integer', 'decimal', 'boolean', 'date')
     111 * shop_item_category_id (foreign key -> shop_item_category.shop_item_category_id, not null)
     112
     11314. '''Shop_item_attribute_value''' – entity that stores the actual value of one attribute for one specific product (EAV pattern).
     114 * shop_item_attribute_value_id (serial, primary key)
     115 * value (varchar, not null)
     116 * notes (varchar)
     117 * shop_item_attribute_id (foreign key -> shop_item_attribute.shop_item_attribute_id, not null)
     118 * shop_item_id (foreign key -> shop_item.shop_item_id, not null)
     119
     12015. '''Medicine''' – entity that represents a medicine. It is linked to `Shop_item` because medicines are also physical products sold/dispensed through the shop.
     121 * medicine_id (serial, primary key)
     122 * name (varchar, not null)
     123 * manufacturer (varchar)
     124 * description (varchar)
     125 * shop_item_id (foreign key -> shop_item.shop_item_id)
     126
     12716. '''Prescription''' – entity that represents a prescription issued during a given examination. `examination_id` is UNIQUE, since an examination can have at most one prescription.
     128 * prescription_id (serial, primary key)
     129 * examination_id (foreign key -> examination.examination_id, not null, unique)
     130 * date_start (date, not null)
     131 * date_end (date, not null)
     132 * description (text)
     133
     13417. '''Prescription_medicine''' – entity that links prescriptions and medicines (N:M), with additional attributes specific to that combination (dosage, number of days).
     135 * prescription_id (foreign key -> prescription.prescription_id, primary key)
     136 * medicine_id (foreign key -> medicine.medicine_id, primary key)
     137 * dosage (integer, not null, check: > 0)
     138 * num_days (integer, not null, check: > 0)
     139
     14018. '''Treatment_type''' – entity that defines the types of treatments the clinic offers (consultation, prescription, vaccination, operation).
     141 * treatment_type_id (serial, primary key)
     142 * name (varchar, not null, check: 'prescription', 'vaccination', 'consultation', 'operation')
     143
     14419. '''Treatment''' – entity that represents a specific treatment carried out as part of one examination. One `Examination` can include multiple treatments (e.g. a consultation followed by a vaccination in the same visit).
     145 * treatment_id (serial, primary key)
     146 * date_treatment (date, not null, default: current_date)
     147 * notes (text)
     148 * treatment_type_id (foreign key -> treatment_type.treatment_type_id)
     149 * examination_id (foreign key -> examination.examination_id)
     150
     15120. '''Treatment_attribute''' – entity that defines which attributes are relevant for a given treatment type (e.g. "date_next" and "adverse_reaction" for vaccination, "duration_minutes" for operation). It is split into its own entity to enable an EAV pattern, since each treatment type has a different set of attributes.
     152 * treatment_attribute_id (serial, primary key)
     153 * name (varchar, not null)
     154 * data_type (varchar, not null, check: 'text', 'integer', 'decimal', 'boolean', 'date')
     155 * treatment_type_id (foreign key -> treatment_type.treatment_type_id, not null)
     156
     15721. '''Treatment_attribute_value''' – entity that stores the actual value of one attribute for one specific treatment (EAV pattern).
     158 * treatment_attribute_value_id (serial, primary key)
     159 * value (varchar, not null)
     160 * notes (varchar)
     161 * treatment_attribute_id (foreign key -> treatment_attribute.treatment_attribute_id, not null)
     162 * treatment_id (foreign key -> treatment.treatment_id, not null)
     163
     16422. '''Discount''' – entity that represents a discount on a specific shop product.
     165 * discount_id (serial, primary key)
     166 * type (varchar, not null, check: 'fixed' or 'percentage')
     167 * value (numeric, not null, check: >= 0)
     168 * description (varchar)
     169 * date_from (date, default: current_date)
     170 * date_to (date)
     171 * shop_item_id (foreign key -> shop_item.shop_item_id)
     172
     17323. '''Invoice''' – entity that represents an invoice issued to an owner, with an optional coupon applied to it.
     174 * invoice_id (serial, primary key)
     175 * date_invoice (date, not null, default: current_date)
     176 * total (numeric, not null, check: >= 0)
     177 * coupon_id (foreign key -> coupon.coupon_id)
     178 * owner_id (foreign key -> owner.owner_id)
     179
     18024. '''Invoice_item''' – entity that represents a line item on an invoice. The `type` field determines whether the line item is a shop product or a treatment, and the check constraint ensures that exactly one of `shop_item_id`/`treatment_id` is populated, depending on the type.
     181 * num_item (integer, not null, check: > 0, part of composite primary key)
     182 * invoice_id (foreign key -> invoice.invoice_id, not null, part of composite primary key)
     183 * price (numeric, not null, check: >= 0)
     184 * quantity (integer, not null, default: 1, check: >= 0)
     185 * type (varchar, check: 'shop_item' or 'treatment')
     186 * shop_item_id (foreign key -> shop_item.shop_item_id)
     187 * treatment_id (foreign key -> treatment.treatment_id)
     188
     18925. '''Payment''' – entity that represents a payment made toward a given invoice. One invoice can be paid through multiple payments (e.g. partial payments).
     190 * payment_id (serial, primary key)
     191 * date_payment (date, not null, default: current_date)
     192 * amount (numeric, not null, check: >= 0)
     193 * method (varchar, not null, check: 'cash', 'debit card', 'credit card', 'digital wallet', 'other')
     194 * invoice_id (foreign key -> invoice.invoice_id, not null)
     195
     196== Relations ==
     197
     1981. **Owns** (Owner : Pet, 1:N) - One owner can have multiple pets, while each pet belongs to exactly one owner.
     1992. **Requests** (Owner : Appointment, 1:N) - One owner can request multiple appointments, while each appointment is requested by at most one owner.
     2003. **Concerns** (Pet : Appointment, 1:N) - One pet can have multiple appointments over time, while each appointment concerns at most one pet.
     2014. **Has_role** (Role : Employee, 1:N) - One role can be held by multiple employees, while each employee has at most one role.
     2025. **Supervises** (Employee : Employee, 1:N) - One employee (supervisor) can supervise multiple other employees, while each employee is supervised by at most one other employee (self-reference).
     2036. **Has_specialization** (Employee : Specialization, 1:N) - One employee can have multiple specializations, while each specialization belongs to exactly one employee.
     2047. **Has_certificate** (Employee : Certificate, 1:N) - One employee can have multiple certificates, while each certificate belongs to exactly one employee.
     2058. **Results_in** (Appointment : Examination, 1:N) - One appointment results in one or more examinations, while each examination originates from at most one appointment.
     2069. **Conducts** (Employee : Examination, 1:N) - One employee can conduct multiple examinations, while each examination is conducted by at most one employee.
     20710. **Held_in** (Examination_room : Examination, 1:N) - Multiple examinations can be held in one room over time, while each examination takes place in at most one room.
     20811. **Includes** (Examination : Treatment, 1:N) - One examination can include multiple treatments (e.g. a consultation and a vaccination in the same visit), while each treatment belongs to at most one examination.
     20912. **Classified_as** (Treatment_type : Treatment, 1:N) - One treatment type covers multiple specific treatments, while each treatment belongs to exactly one type.
     21013. **Defines_attribute** (Treatment_type : Treatment_attribute, 1:N) - One treatment type defines multiple specific attributes, while each attribute belongs to exactly one treatment type.
     21114. **Has_value** (Treatment_attribute : Treatment_attribute_value, 1:N) - One attribute can have multiple recorded values (for different treatments), while each value refers to exactly one attribute.
     21215. **Has_attribute_value** (Treatment : Treatment_attribute_value, 1:N) - One treatment can have multiple attribute values, while each value belongs to exactly one treatment.
     21316. **Has_prescription** (Examination : Prescription, 1:1) - One examination can have at most one prescription, and each prescription belongs to exactly one examination.
     21417. **Contains_medicine / Prescribed_in** (Prescription : Medicine, N:M via Prescription_medicine) - One prescription can contain multiple medicines, and one medicine can appear in multiple prescriptions; the relationship is modeled through the associative entity Prescription_medicine, which additionally stores the dosage and number of days.
     21518. **Sold_as** (Shop_item : Medicine, 1:N) - One shop product conceptually corresponds to at most one medicine, but since `shop_item_id` is not UNIQUE-constrained in the model, the formal relationship is 1:N.
     21619. **Belongs_to_category** (Shop_item_category : Shop_item, 1:N) - One category contains multiple products, while each product belongs to at most one category.
     21720. **Has_subcategory** (Shop_item_category : Shop_item_category, 1:N) - One category can have multiple subcategories, while each category has at most one parent category (self-reference).
     21821. **Defines_item_attribute** (Shop_item_category : Shop_item_attribute, 1:N) - One product category defines multiple specific attributes, while each attribute belongs to exactly one category.
     21922. **Has_item_attribute_value** (Shop_item_attribute : Shop_item_attribute_value, 1:N) - One attribute can have multiple recorded values (for different products), while each value refers to exactly one attribute.
     22023. **Has_attribute_value_for_item** (Shop_item : Shop_item_attribute_value, 1:N) - One product can have multiple attribute values, while each value belongs to exactly one product.
     22124. **Applies_to** (Shop_item : Discount, 1:N) - One product can have multiple discounts over time, while each discount applies to at most one product.
     22225. **Used_in** (Coupon : Invoice, 1:N) - One coupon can be used on multiple invoices (up to its defined usage_limit), while each invoice uses at most one coupon.
     22326. **Issued_to** (Owner : Invoice, 1:N) - One owner can be issued multiple invoices, while each invoice is issued to at most one owner.
     22427. **Contains_item** (Invoice : Invoice_item, 1:N) - One invoice contains multiple line items, while each line item belongs to exactly one invoice.
     22528. **Referenced_as_item** (Shop_item : Invoice_item, 1:N) - One product can appear as a line item on multiple invoices, while each line item of type 'shop_item' refers to exactly one product.
     22629. **Referenced_as_treatment** (Treatment : Invoice_item, 1:N) - One treatment can appear as a line item on multiple invoices, while each line item of type 'treatment' refers to exactly one treatment.
     22730. **Paid_through** (Invoice : Payment, 1:N) - One invoice can be paid through multiple payments (e.g. partial payments), while each payment belongs to exactly one invoice.
    6228
    7229== Descriptive Documentation and Argumentation ==