OntoMedRec: Logically-Pretrained Model-Agnostic Ontology Encoders for Medication Recommendation