Tech & Engineering

Building a Yii app: The Data Model

A friend of mine needs a web application to be revamped. I had originally created it about 2 years back using a custom PHP mini framework that I had built for m...

Sumit Datta··3 min read

A friend of mine needs a web application to be revamped. I had originally created it about 2 years back using a custom PHP mini-framework that I had built for many projects at that time. The development had stopped for different reasons and parts of his web application were incomplete. For example images were not upload to Amazon S3, which was originally planned. Some Model edits were not working in many parts and there were some data validation issue. He has been doing the groundwork for his business and now has decided to finally complete the application.

The application is related to Medical needs, information about patients, doctors, hospitals etc. I have decided to make the new version using Yii, since some other developer will take over if the project is successful and Yii (or other popular frameworks) is a very well documented framework for anyone to use. The choice of Yii against other PHP frameworks is rather just an impulsive one. I have read comparisons of the good PHP frameworks and Yii is among the top few. Anyway moving on…

While I am building this application, which is a moderately feature rich one, I intend to write about my experiences. Hope this helps anyone looking for a quick introduction and example for Yii. I am trying to make this a tutorial for Yii, I will try my best here. The project needs data for multiple types:

  • General User Profile (could be a patient)
  • Doctor
  • Hospital
  • Nursing Home
  • Other Medical companies like: Medical Shop, Diagnostic Center, Fitness Center, Ambulance Provider, Nurse, etc.

Other information include:

  • Specialization: this is related to Doctors, explained below
  • Address: City, State, Country, etc. Any entity can have multiple addresses
  • Phone: can be either a fixed or a mobile (cellular) phone. Any entity can have multiple phones, also address can have phones associated with them
  • Department: Hospitals or Nursing Homes can specify many departments
  • Branch: Hospitals, Nursing Homes of Other companies can have multiple locations/branches.
  • Image: multiple images for any entity.
  • User: this is used for authentication, simple email/password for now.

In order to manage the mappings of many entity types to Address, Phone, Branch, Image etc. I have used a central Entity table. Every type of physical entity has an entry in the Entity table (including each branch). Then Address, Phone, Branch, Image, Department are mapped to Entity table.

In Yii terms the relations look like this:

  • Doctors can have one or more Specialization (HAS_MANY in Yii Model)
  • Doctor, Hospital, Nursing Home, Other, Profile have a one-to-one mapping to Entity (BELONGS_TO in Yii)
  • Entity can have multiple Addresses, Phones, Images (HAS_MANY in Yii)
  • Entity can have many Departments (HAS_MANY). This is limited to only Hospital, Nursing Home or Other types though at the application level.
  • Entity can have another Entity as Branch (HS_MANY). This is also limited to Hospital, Nursing Home or Other types at the application level.

I will write about setting up Yii Models in the next blog entry…

Share
Written by
Sumit Datta

Software engineer and entrepreneur, 16+ years at fast-paced startups across the US, Canada, Germany and India.

Comments

Hook this up to your favourite commenting platform — Giscus, Disqus, or your own.

Continue reading

Tech & Engineering·

Frontend Driven Development

I have primarily been a backend web developer, started out with PHP around 2005 and then moving to Python in 2011. I have worked with a lot of JavaScript, mostl...

Sumit Datta · 5 min
Tech & Engineering·

PHP libxml issue while compiling

Today I had some trouble getting libxml to work in PHP. I was compiling PHP 5.3.10 for a client's Joomla site and it needs libxml. The issue seemed to be common...

Sumit Datta · 1 min
Tech & Engineering·

Day One of Amazon DynamoDB

Its been just about a day that I have been going through the documentation of the newly released Amazon DynamoDB. Using the PHP SDK and getting a basic Table up...

Sumit Datta · 3 min

A quieter inbox.

One thoughtful letter every other Sunday — new essays, things worth reading, and the occasional photograph.

Free. Unsubscribe in one click.