开发者

Best way to arrange object and models with different sets of important attributes

开发者 https://www.devze.com 2023-04-12 01:57 出处:网络
Suppose I have some medical software that tracks billing and medical procedures for patients.Each patient then has three important groups of attributes.

Suppose I have some medical software that tracks billing and medical procedures for patients. Each patient then has three important groups of attributes.

  1. Shared attributes - name, age, gender, patient number, etc.
  2. Billing Attributes - address, account number, balance, etc
  3. Medical Attributes - blood pressure, surgeries, blood type, etc.

I have a single ActiveRecord Patient model with all of the above attributes. I could then have a PatientBillingDetails controller and a PatientMedicalDetails controller to distinguish between the two. Should I also create two more models to correspond to each controller, or just have each c开发者_JAVA技巧ontroller draw from the single Patient model. If creating two new models, what is the best/simplest way to have them use only the appropriate attributes?


To answer your question directly, while Rails tutorials like to silo the information into one controller for one model, my 5+ years experience writing large enterprise applications in Rails has shown me that the controllers you build relate to the views you need to show, rather than a one-to-one relationship with models. Thus, it would seem more than sensical to create several controllers for each aspect of your Patient model.

It seems to me, however, that the real issue is that your Patient model is overloaded by trying to do too many things at once. I would suggest you normalize out some of the information into their own models--particularly where you may need a "has many" relationship, like medical attributes as recorded on different dates.

To give a better answer, I'd need more information on what it is your software is trying to do, particularly what category of "medical software" you are trying to write, and if this is a side utility for a specialty purpose or a general purpose EHR or Medical Billing Application.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号