Best way to arrange object and models with different sets of important attributes
Suppose I have some medical software that tracks billing and medical procedures for patients. Each patient then has three important groups of attributes.
- Shared attributes - name, age, gender, patient number, etc.
- Billing Attributes - address, account number, balance, etc
- 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.
精彩评论