Preventing duplicate submission in Rails
That can be done easily by Rails validation, and scope attribute:

# Baseline Model
validates :user_id, uniqueness: { scope: :patient_id }


That mean user_id can present many times in Baseline table, but only one can be connected to exact patient_id.