databasedatabase-designrelational-databaseerddatabase-relations

Vaccination Database design ERD


My intentions to design the database schema for the small pet vaccination application. Inside Pet table I want to store details about the pets and if specific vaccination is required. There are 3-4 vaccination types(VT1, VT2, Vt3, VT4), which is stored inside Vaccine_Type table. For each vaccination type there are vaccines from various vendors, so I decided to store that information inside Vaccine table. Vaccination details are stored inside associative table - Vaccination. Inside which I have: pet_id, vaccination_type, vaccine_id, veterinarian_id, vaccination_date and expiation_date, if expiration date is over active field is set to False, indicating that vaccination is no more active and requires new vaccination. Kindly advise how can link this information into Pet table, to show which vaccination Type requires revaccination. And advice if the database schema is correct , or could be optimized more. enter image description here


Solution

  • I would modify a little bit.

    When you want to check if a pet has any expired vaccinations, do the following:

    1. Get the list of vaccines that apply to the pet's species via the Vaccines table and Species table.
    2. Get the latest date that each Vaccine was injected to the Pet via the Vaccination table. That value might be null if it was never done. In that case, go to step 5 below.
    3. Get the active period for the vaccines from the list of vaccines you extracted above.
    4. Compare the (date from step 2 + period from step 3) with the current date.
    5. If it is expired, schedule a new injection via your scheduling application.

    As a general concept, store data in the database. Anything that requires to be calculated does not go in a field, it goes in the application, using the data in the database.

    Another concept, do not link things that can be derived from other links. This respects the normal forms.

    So:

    Pet
        petid, PK
        name, NN
        speciesid, FK (Species.speciesid), NN
    Species
        speciesid, PK
        name, NN
    
    Vet
        vetid, PK
        name, NN
        
    Vaccine
        vaccineid, PK
        name, NN
        vaccinetypeid, FK (Vaccinetype.vaccinetypeid), NN
        activeperiod, NN
    Vaccinetype
        vaccinetypeid, PK
        name, NN
    Vaccine_Species
        vaccineid, FK (Vaccine.vaccineid)
        Species, FK (Species.speciesid)
        
    Vaccination
        vaccinationid
        vetid, FK (Vet.vetid)
        petid, FK (Pet.petid)
        vaccineid, FK (Vaccine.vaccineid)
        date, NN
        
    

    Legend:

    Notes: