排列具有不同重要属性集的对象和模型的最佳方式
假设我有一些医疗软件可以跟踪患者的计费和医疗程序。每个患者都具有三组重要的属性。
- 共享属性 - 姓名、年龄、性别、患者编号等
- 计费属性 - 地址、帐号、余额等
- 医疗属性 - 血压、手术、血型等
我有一个包含上述所有内容的 ActiveRecord 患者模型属性。然后我可以有一个 PatientBillingDetails 控制器和一个 PatientMedicalDetails 控制器来区分两者。我是否还应该创建两个以上的模型来对应每个控制器,或者只是让每个控制器从单个患者模型中提取。如果创建两个新模型,让它们仅使用适当的属性的最佳/最简单方法是什么?
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 controller 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直接回答你的问题,虽然 Rails 教程喜欢将信息存储到一个模型的一个控制器中,但我在 Rails 中编写大型企业应用程序 5 年以上的经验告诉我,你构建的控制器与你需要显示的视图相关,而不是与你需要显示的视图相关。而不是与模型的一对一关系。因此,为患者模型的每个方面创建多个控制器似乎非常有意义。
然而,在我看来,真正的问题是你的 Patient 模型由于试图同时做太多事情而超载。我建议您将一些信息标准化为自己的模型 - 特别是在您可能需要“有很多”关系的情况下,例如在不同日期记录的医疗属性。
为了给出更好的答案,我需要更多关于您的软件正在尝试做什么的信息,特别是您正在尝试编写什么类别的“医疗软件”,以及这是否是用于特殊目的的辅助实用程序或通用 EHR 或医疗计费应用程序。
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.