├── README.md ├── image.png ├── clinic_diagram.png ├── LICENSE.md └── schema_based_on_diagram.sql /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kifle23/clinic-db/HEAD/README.md -------------------------------------------------------------------------------- /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kifle23/clinic-db/HEAD/image.png -------------------------------------------------------------------------------- /clinic_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kifle23/clinic-db/HEAD/clinic_diagram.png -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kifle Haile 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /schema_based_on_diagram.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE clinic; 2 | 3 | CREATE TABLE patients ( 4 | id SERIAL PRIMARY KEY, 5 | name VARCHAR(255), 6 | date_of_birth DATE 7 | ); 8 | 9 | CREATE TABLE medical_histories ( 10 | id SERIAL PRIMARY KEY, 11 | admitted_at TimeStamp, 12 | patient_id INTEGER REFERENCES patients(id), 13 | status VARCHAR(255) 14 | ); 15 | 16 | CREATE TABLE treatments ( 17 | id SERIAL PRIMARY KEY, 18 | type VARCHAR(255), 19 | name VARCHAR(255) 20 | ); 21 | 22 | CREATE TABLE medical_histories_treatments ( 23 | medical_history_id INTEGER REFERENCES medical_histories(id), 24 | treatment_id INTEGER REFERENCES treatments(id), 25 | PRIMARY KEY (medical_history_id, treatment_id) 26 | ); 27 | 28 | CREATE TABLE invoices ( 29 | id SERIAL PRIMARY KEY, 30 | total_amount DECIMAL, 31 | generated_at TimeStamp, 32 | payed_at TimeStamp, 33 | medical_history_id INTEGER REFERENCES medical_histories(id) 34 | ); 35 | 36 | CREATE TABLE invoice_items ( 37 | id SERIAL PRIMARY KEY, 38 | unit_price DECIMAL, 39 | quantity INTEGER, 40 | total_price DECIMAL, 41 | invoice_id INTEGER REFERENCES invoices(id), 42 | treatment_id INTEGER REFERENCES treatments(id) 43 | ); 44 | 45 | CREATE INDEX idx_patient_id ON medical_histories (patient_id); 46 | CREATE INDEX idx_medical_history_id ON medical_histories_treatments (medical_history_id); 47 | CREATE INDEX idx_treatment_id ON medical_histories_treatments (treatment_id); 48 | CREATE INDEX idx_medical_history_id_invoices ON invoices (medical_history_id); 49 | CREATE INDEX idx_invoice_id ON invoice_items (invoice_id); 50 | CREATE INDEX idx_treatment_id_invoice_items ON invoice_items (treatment_id); 51 | --------------------------------------------------------------------------------