A Causal Inference Framework For Comparative Effectiveness And Safety Research Using Observational Data, With Application In Type 2 Diabetes