Hey guys,
I work as a web developer for a medical company, and I'm starting from scratch with this new version of the records software, and I'm really trying to do this with the best OOP principles possible. I'm in the planning phase now, and I'm trying to lay out some UML-like diagrams relating the different domain objects.
In the past, I've had a Patient class with a unique ID, and then a few other classes for SOAP notes, Transfers, History and Physicals, and they're all related with that unique ID. This works alright, but the need is arising for more control based on this ID. The format of the ID is as follows: xxx-xxxx-xxx. The first triplet represents the company, the middle quartet is a unique ID (unique within that company) and the last triplet is for the plan that they are enrolled in. So, I need methods like patientPeer::retrieveByCompany(03X), and patientPeer::retrieveByPlan(03B). Then there's a whole bunch of methods required for validation, creation of new IDs, etc.
Basically, there is tons of logic for the ID that I need to use. In the past, I've just had the ID stored as a string, and then in the controller nastily explode() it based on the hyphen. That's messy though, and all sorts of duplication results. So, I'm wondering how you'd recommend I model this.
My idea was to make a new class just for the ID. This would have four fields, one for the text string of the entire id, and then three others for each of the sections. This way I could easily have peer methods retrieving based based on any of the little sections of the ID. This presents the problem of how it would relate to my patient class. Obviously, the ID is nothing without the patient class, and vice versa. Perhaps having the Patient class inherit from the ID class? Still, not sure how that'd work--or if it's the best option.
This is probably basic stuff to you guys, so I apologize if it does not merit this forum, but I really want to do this as best as humanly possible, and as such, I figured I'd ask on here.
Designing my domain model--could use some help
Moderator: General Moderators
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: Designing my domain model--could use some help
If i understand correctly (hopefully I do)
What you can do for this is have a structure like follows
Generating an Id would be something like this
Hope this helps you get started, and you understand, if you don't or something doesn't seem right letme know...I did this in my head and there might be some problems
Here is a working Example
What you can do for this is have a structure like follows
Code: Select all
Company Class
-----------------------------------------
Stores all companies and their ID's for each company
|- Patient Class
----------------------------
Subclass from the company class, that each company ID has its own Patient class object, which
allows you add patients to each company with the possibity of collisions very low as each patient ID is tied only to the
company it is assigned to
Plan Class
-----------------------------------------
This can store all of the plans and their ID's
Main Class
------------------------------------
This will combine everything be used to retrieve everything into one place grouping your companies - and their patients, and all of the plans.
Here is an example Breakdown
--------------------------------------------
Company Object
|- Id = FooId
|- Patient 1 - Id 32aC - Object
|- Patient 1 - Id 56ub - Object
|- Id = FooId2
|- Patient 1 - Id 32aC - Object
|- Patient 1 - Id 56ub - Object
Plans Object
|- Id = Plan1
Main
|- Companies
|- Registry of your company object
|- Plans
|- Registry of your plans
Code: Select all
Main::registry('company')->getCompanyId('Foo') .':'.Main::registry('company')->getCompany('Foo')->getPatientId('Joe').':'.Main::registry('plans')->getPlanId('Best Plan');
Here is a working Example
Code: Select all
class Company {
/*
* Array containing all companies
*/
public $companies = array();
public function __construct() {}
/*
* Adds a new company
*
* @param string id Companies ID
* @param string name Companies Name
*
* @return this
*/
public function addCompany($id, $name)
{
$this->companies[$name] = new Company_Object($id, $name);
return $this;
}
public function getCompany($name) {
return $this->companies[$name];
}
}
class Company_Object {
/*
* Patient List
*/
private $_patients = array();
/*
* ID
*/
private $_id = null;
/*
* Name
*/
private $_name = null;
public function __construct($id, $name) {
$this->_id = $id;
$this->_name = $name;
}
public function addPatient($id, $name, Plan_Object $plan)
{
$this->_patients[$name] = new Patient($id, $name, $plan);
}
public function getPatient($name)
{
return $this->_patients[$name];
}
}
class Patient {
/*
* Name
*/
private $_name = null;
/*
* Id
*/
private $_id = null;
/*
* Plan Object
*/
private $_plan = null;
/*
* Adds a new patient
*/
public function __construct($id, $name, $plan)
{
$this->_name = $name;
$this->_id = $id;
$this->_plan = $plan;
}
}
class Plan {
/*
* List of plans
*/
private $_plans = array();
/*
* Adds a new company
*
* @param string id Companies ID
* @param string name Companies Name
*
* @return this
*/
public function __construct()
{
// automatically build plans?
}
public function addPlan($id, $name)
{
$this->_plan[$name] = new Plan_Object($id, $name);
}
public function getPlan($name)
{
return $this->_plan[$name];
}
}
class Plan_Object {
/*
* Name of plan
*/
private $_name = null;
/*
* Id of plan
*/
private $_id = null;
public function __construct($id, $name) {
$this->_id = $id;
$this->_name = $name;
}
}
class Hospital {
public $company = object;
public $plan = object;
public function __construct()
{
$this->company = new Company();
$this->plan = new Plan();
}
public function getCompany($name)
{
return $this->company->getCompany($name);
}
public function getPlan($name)
{
return $this->plan->getPlan($name);
}
}
$hospital = new Hospital();
// add new plan
$hospital->plan->addPlan('foo1', 'Foo Plan');
// add new company
$hospital->company->addCompany('com1', 'Company One');
// add patient to this company with the Foo Plan
$hospital->company->getCompany('Company One')->addPatient('ee4d', 'John Doe', $hospital->plan->getPlan('Foo Plan'));
Code: Select all
object(Hospital)#1 (2) {
["company"]=>
object(Company)#2 (1) {
["companies"]=>
array(1) {
["Company One"]=>
object(Company_Object)#5 (3) {
["_patients:private"]=>
array(1) {
["John Doe"]=>
object(Patient)#6 (3) {
["_name:private"]=>
string(8) "John Doe"
["_id:private"]=>
string(4) "ee4d"
["_plan:private"]=>
object(Plan_Object)#4 (2) {
["_name:private"]=>
string(8) "Foo Plan"
["_id:private"]=>
string(4) "foo1"
}
}
}
["_id:private"]=>
string(4) "com1"
["_name:private"]=>
string(11) "Company One"
}
}
}
["plan"]=>
object(Plan)#3 (2) {
["_plans:private"]=>
array(0) {
}
["_plan"]=>
array(1) {
["Foo Plan"]=>
object(Plan_Object)#4 (2) {
["_name:private"]=>
string(8) "Foo Plan"
["_id:private"]=>
string(4) "foo1"
}
}
}
}
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: Designing my domain model--could use some help
Thanks a bunch for your time, it's greatly appreciated. I'm definitely going to keep your schema there as an option, and I'm going to try a few different things.
Thanks again.
Thanks again.