ER Diagram Practice- Pandemic Risk Example
Published: 2020-09-07 02:50:13

#*Hello and welcome*

This is a simple look at ER diagramming using the (frustrating and sad) example of the current Covid-19 situation.

##**Pandemic Risk Diagramming**
The effects of the Covid-19 virus have ravaged the world in the landscape of 2020. While the virus will hopefully peter out with time, the current concern is limiting the risk to individuals while helping those at risks. The issue with this is figuring out just *who* is at a higher risk.

The use of ER (Entity Relationship) diagrams can display basic characteristics of just what can cause a person to be at risk. The entities show specific objects(or generally nouns) that relate to the individual while the attributes describe the entities themselves(similar to adjectives or character attributes). The relationship between entities marks how they interact with each-other on a basic level. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0c66sqi3ej1glssa3ash.png)

The above diagram is an example of a basic ER diagram. It relates the 'Patient' entity, as an individual person, to their personal 'Health Risk' and 'Behavior'. The individual is then also related to their 'Location', 'Employer', and 'Hospital'.

**Patient Entity**
The patient as the focal point is given an 'ID Number' attribute (a UUID) to describe them personally and uniquely throughout the process of assessing risk. They are additionally qualified by whether they have tested positive for C-19, if they show symptoms, their general health rating, age, and race or ethnicity.

**Other Entities**
The other entities within the diagram are generally written with the individual in mind so as to help them assess their own risk. The health risks and behavior pertain specifically to each individual and how their own health and actions affect their general level of risk. The employer and location relate to level of risk that stems from exposure to the public, while the hospital determines the capability of care. 
The entities themselves all relate to each other through the patient but may still relate to each-other on their own. A location limits the types of businesses you may employed at, the number/type of health resources available locally, likelihood of behaviors (such as partying), etc. Some of these relationships can be difficult to show on a clean diagram. The diagram certainly isn't perfect or distinct in some relations. What isn't shown can be mapped better within a database using tuples and relational tables that function smoother than the simple diagram created here.

**Tuples upon Tuples**
Example tuples for the diagram above can be seen below. These tuples list out the attributes of the entities. Where those entities are connected by relations, there may be additional tables that pull tuples or lines and connect the entities within a database.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4f6zeo509az05pq13iv1.PNG)

**Primary v Foreign Keys**
With tuples covered we can begin to discuss primary and foreign keys. A primary key is something like the patient id, the UUID (Universally Unique Identifier) for the individual which should be the only thing that the id is attached to.
This primary key then relates within a 'foreign' table. The primary can be the patient id, but it as a foreign key exists within the hospital registry for currently listed patients.

**Cardinality**
The discussion of primary ties into the idea of cardinality, which is essentially how many times that data is in a relationship. A patient can have an id that is reused over multiple visits, but the prescription they are given is used only once and given to only them. This is an example of one-to-many vs. one-to-one cardinality.

**Disclaimer**
Absolutely none of this is expert level or the depth that would be required for a genuine risk-analysis database. This was primarily an exercise in creating an ER Diagram and the though process involved. For more depth into the thought process itself watch the linked video.

[Covid Risk ER Diagram Example pt 1](https://youtu.be/21YKh1-ajj0)

For a genuine breakdown of ER Diagrams try chewing one of these.
[ER Diagrams Tutorial](https://www.guru99.com/er-diagram-tutorial-dbms.html)
[Entity Relationship Diagram-ERD-Tutorial pt 1](https://youtu.be/QpdhBUYk7Kk)

Hope this didn't bore some poor soul to tears, but mostly hope you can stay curious about it all.