Bayesian Modeling of Latent Heterogeneity in Complex Survey Data and Electronic Health Records