This is my Z schema for Appointment DB.
|--AppointmentDB----------------
|attendees : P Person /** those involved in the appointment **/
|
|/** a new TYPE object to store attendees, schedule and purpose **/
|appointments : P APPOINTMENT
|hasAppointment : Person <-> APPOINTMENT
|schedule : APPOINTMENT -> DateTime
|purpose : APPOINTMENT -> Report
|
|/** a forward relation compositions to relate attendees with purpose and schedule **/
|attendeePurpose : hasAppointment;purpose
|attendeeSchedule : hasAppointment;schedule
|-----------------------------
|attendees ⊆ dom(hasAppointment)
|attendees ⊆ dom(attendeePurpose)
|appointments ⊆ ran(hasAppointment)
|-----------------------------
I would like to create a search function that finds an appointment based on the name of the attendees
.
How do I design it?
Here is my take :
|--FindAppointment---------------------------------------------------
|ΞAppointmentDB
|attendees? : Person
|appointmentAttendees! : P Person
|appointmentPurpose! : Report
|appointmentSchedule! : DateTime
|-----------------------------
|/** if name of any attendees is given, then it must exist in appointments' domain
|respectively before this function can run**/
|attendees? ∈ dom(attendees)
|
|/** return the set of attendees of the same APPOINTMENT using attendees? as input **/
|appointmentAttendees! = hasAppointment~(|{attendees?}|)
|
|/** Get the image of both forward relational compositions according to set of
|attendees?**/
|appointmentPurpose! = attendeePurpose(|{attendees?}|)
|appointmentSchedule! = attendeeSchedule(|{attendees?}|)
|----------------------------------------------------------------------
Have you type checked your specification?
Your declaration subject? : P Person
states that subject?
is a set of persons, but subject? : dom(attendees)
implies that subject?
is a single person.
If you want to have either none or one person given you could introduce a datatype analogous to the Maybe monad in functional programming languages (or null values in other programming languages):
MaybePerson ::= NoPerson | JustPerson <<Person>>
Then you can declare an input like
subject? : MaybePerson
Then I would to suggest to restrain the possible solutions for one input
subject? : ran(JustPerson) => schedule! : schedule(|{ JustPerson~ subject? }|)
If subject?
is a set of persons you can achieve the same with:
subject? /= {} => schedule! : schedule(|subject?|)
And then just do the same for the other possible input. You can add also a condition that not both entries should be NoPerson
resp. not both input sets should be empty.