A Lab Test Fulfillment System With A Multi Role Model Using Ruby on Rails
The overall concept of this project is as follows. A company is selling a uMMA B12 Deficiency test, the test needs to be delivered to a customer, who collects the sample and then registers the test (associating a unique test id with that customer) on the site before returning the test to the lab.
The Lab receives the test sample and performs the test. The Lab uses the unique test id attached to the sample to find that test in the database and enters the results accordingly. The Lab marks the test “verified” and the customer can now see their results in their dashboard.
Ok…That’s the simple version. I wanted this to have a much broader scope. I didn’t just want this to be used for just 1 Company, 1 Lab and many customers. I wanted a company to be able to support many labs and labs to support many companies and customers to have many test results owned by different companies.
Originally I was going to have separate models for the Company Admins, Lab Admins and User accounts. But after considering it I settled on one User model with boolean values to assign roles.
Here is a look at my models…
The first issue I encountered was. How am I going to associate a Company and a Lab so that they can share data and fulfill lab tests? I decided on a join table called Company Lab Connection. This table has more than just their foreign keys, it also has some boolean values to determine if the connection was successful and approved by the respective party.
The flow is like this. A company creates a Company account and is brought to this dashboard.
Here the company super admin can perform different actions such as generating new test ids or connecting a lab to the company account.
A simple email address is needed to connect a lab. If the email exists in the database, the lab associated with it will receive a notification in their dashboard showing that Company “X” wants to connect.
Below the company name is a random string due to creating an account with google omniauth. The company admin can change this after sign up.
Once connected, the lab can see all of the company’s tests and can update them with test results.
The results updated be the Lab need to be verified by the lab technician in order for the results to go through towards the customer. However the company can still view all the results before they are verified. Only a lab can verify the result (very important for CLIA compliance) and once verified it cannot be altered.
Now…the lab may be connected to many companies and performing many tests for them. Their dashboards will reflect this. Only data owned by ( or available to) a certain account is viewable in these dashboards.
Even a company admin account who can view all the test results of a certain customer, will only be able to see the results of that customer where associated with the company.
Finally a user’s dashboard will be updated with their result once it has been verified. This ends the lifecycle of the app and can be repeated over and over again :)
Side note on OmniAuth. Since I have effectively three different types of account sign ups, I wanted everyone to be able to sign up with their google account. This posed a challenge at first because I needed to assign different roles based on the sign up form and maintain state through the process. Luckily there is a simple way you can do this by appending information to the OmniAuth request URL which is then stored in the callback hash. So based on different parameters in the callback we assign different roles.
You can check out the application for yourself here…company-lab-tests.herokuapp.com