defmodule Patient do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "patients"
repo Repo
end
attributes do
uuid_primary_key(:id)
attribute(:first_name, :string)
attribute(:last_name, :string)
timestamps()
end
relationships do
has_many :event_series, EventSeries
end
end
defmodule EventSeries do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "event_series"
repo Repo
custom_indexes do
index [:patient_id, :initial_date], unique: true
end
end
attributes do
uuid_primary_key(:id)
attribute(:initial_date, :date)
timestamps()
end
relationships do
belongs_to :patient, Patient, allow_nil?: false
has_many :exams, Exam
end
end
defmodule Exam do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "exams"
repo Repo
end
attributes do
uuid_primary_key(:id)
attribute(:performed_on, :date)
timestamps()
end
relationships do
belongs_to :event_series, EventSeries, allow_nil?: false
end
end
defmodule Patient do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "patients"
repo Repo
end
attributes do
uuid_primary_key(:id)
attribute(:first_name, :string)
attribute(:last_name, :string)
timestamps()
end
relationships do
has_many :event_series, EventSeries
end
end
defmodule EventSeries do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "event_series"
repo Repo
custom_indexes do
index [:patient_id, :initial_date], unique: true
end
end
attributes do
uuid_primary_key(:id)
attribute(:initial_date, :date)
timestamps()
end
relationships do
belongs_to :patient, Patient, allow_nil?: false
has_many :exams, Exam
end
end
defmodule Exam do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "exams"
repo Repo
end
attributes do
uuid_primary_key(:id)
attribute(:performed_on, :date)
timestamps()
end
relationships do
belongs_to :event_series, EventSeries, allow_nil?: false
end
end