commit f52bf4334433565a67fd2111061679de728eb733 Author: The Magician Date: Sun Apr 7 12:44:55 2024 +0100 Initial commit diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..82b0932 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module main + +go 1.22.1 + +require github.com/go-sql-driver/mysql v1.8.1 + +require filippo.io/edwards25519 v1.1.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..19dbcec --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= diff --git a/images/theredphone.ico b/images/theredphone.ico new file mode 100644 index 0000000..457864d Binary files /dev/null and b/images/theredphone.ico differ diff --git a/images/theredphone.png b/images/theredphone.png new file mode 100644 index 0000000..1f773ea Binary files /dev/null and b/images/theredphone.png differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..4057542 --- /dev/null +++ b/main.go @@ -0,0 +1,236 @@ +package main + +import ( + "database/sql" + "fmt" + "html/template" + "net/http" + + "github.com/go-sql-driver/mysql" +) + +func getIndex(w http.ResponseWriter, r *http.Request) { + tmpl, err := template.ParseFiles("templates/index.tmpl") + if err != nil { + fmt.Println(err) + return + } + + err = tmpl.Execute(w, nil) + if err != nil { + fmt.Println(err) + return + } +} + +func getParamedicView(w http.ResponseWriter, r *http.Request) { + tmpl, err := template.ParseFiles("templates/paramedicForm.tmpl") + if err != nil { + fmt.Println(err) + return + } + + err = tmpl.Execute(w, nil) + if err != nil { + fmt.Println(err) + return + } +} + +type Alert struct { + Id int + + // Categorization + MedicalOrTrauma string + + // Patient data + Age string + Sex string + NhsNumber string + + // Observations + HeartRate string + RespiratoryRate string + OxygenSaturation string + Gcs string + BloodPressure string + + // Extra information + Eta string + Interventions string + BackgroundInfo string +} + +func postParamedicForm(w http.ResponseWriter, r *http.Request) { + // Parse data from form + var alert Alert + alert.MedicalOrTrauma = r.PostFormValue("medical-or-trauma") + alert.Age = r.PostFormValue("age") + alert.Sex = r.PostFormValue("sex") + alert.NhsNumber = r.PostFormValue("nhs-number") + alert.HeartRate = r.PostFormValue("heart-rate") + alert.RespiratoryRate = r.PostFormValue("respiratory-rate") + alert.OxygenSaturation = r.PostFormValue("oxygen-saturation") + alert.Gcs = r.PostFormValue("gcs") + alert.BloodPressure = r.PostFormValue("blood-pressure") + alert.Eta = r.PostFormValue("eta") + alert.Interventions = r.PostFormValue("interventions") + alert.BackgroundInfo = r.PostFormValue("background") + + // Insert data into database + query := `INSERT INTO Alert ( + MedicalOrTrauma, + Age, + Sex, + NhsNumber, + HeartRate, + RespiratoryRate, + OxygenSaturation, + Gcs, + BloodPressure, + Eta, + Interventions, + BackgroundInfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);` + + insert, err := database.Prepare(query) + defer insert.Close() + if err != nil { + fmt.Println(err) + } + + result, err := insert.Exec(alert.MedicalOrTrauma, + alert.Age, + alert.Sex, + alert.NhsNumber, + alert.HeartRate, + alert.RespiratoryRate, + alert.OxygenSaturation, + alert.Gcs, + alert.BloodPressure, + alert.Eta, + alert.Interventions, + alert.BackgroundInfo) + rowsAffected, err := result.RowsAffected() + if err != nil || rowsAffected != 1 { + fmt.Println(err) + } + + http.Redirect(w, r, "http://localhost:3333/paramedic", http.StatusFound) +} + +func getERView(w http.ResponseWriter, r *http.Request) { + // Get list of alerts from database + alerts := []Alert{} + + rows, err := database.Query("SELECT * FROM Alert;") + if err != nil { + fmt.Println(err) + } + defer rows.Close() + + var alert Alert + for rows.Next() { + err := rows.Scan(&alert.Id, + &alert.MedicalOrTrauma, + &alert.Age, + &alert.Sex, + &alert.NhsNumber, + &alert.HeartRate, + &alert.RespiratoryRate, + &alert.OxygenSaturation, + &alert.Gcs, + &alert.BloodPressure, + &alert.Eta, + &alert.Interventions, + &alert.BackgroundInfo) + + if err != nil { + fmt.Println(err) + } + + alerts = append(alerts, alert) + } + + for i, j := 0, len(alerts)-1; i < j; i, j = i+1, j-1 { + alerts[i], alerts[j] = alerts[j], alerts[i] + } + + // Execute template with list + tmpl, err := template.ParseFiles("templates/er.tmpl") + if err != nil { + fmt.Println(err) + return + } + + err = tmpl.Execute(w, alerts) + if err != nil { + fmt.Println(err) + return + } +} + +func setupDatabaseTable(db *sql.DB) { + query := `CREATE TABLE IF NOT EXISTS Alert ( + Id SERIAL PRIMARY KEY, + MedicalOrTrauma VARCHAR(100) NULL, + Age VARCHAR(100) NULL, + Sex VARCHAR(100) NULL, + NhsNumber VARCHAR(100) NULL, + HeartRate VARCHAR(100) NULL, + RespiratoryRate VARCHAR(100) NULL, + OxygenSaturation VARCHAR(100) NULL, + Gcs VARCHAR(100) NULL, + BloodPressure VARCHAR(100) NULL, + Eta VARCHAR(100) NULL, + Interventions VARCHAR(100) NULL, + BackgroundInfo VARCHAR(100) NULL + )` + + _, err := db.Exec(query) + if err != nil { + fmt.Println(err) + } +} + +var database *sql.DB + +func main() { + config := mysql.Config{ + User: "root", + Passwd: "o7MS6CIn660jIApSP", + Net: "tcp", + Addr: "127.0.0.1:3306", + DBName: "theredphone", + AllowNativePasswords: true, + } + + db, err := sql.Open("mysql", config.FormatDSN()) + defer db.Close() + database = db + + if err != nil { + fmt.Println(err) + return + } + + if err = db.Ping(); err != nil { + fmt.Println(err) + return + } + + fmt.Println("Connected to database") + setupDatabaseTable(db) + + //mux := http.NewServeMux() + + http.HandleFunc("/", getIndex) + http.HandleFunc("/paramedic", getParamedicView) + http.HandleFunc("/paramedicForm", postParamedicForm) + http.HandleFunc("/er", getERView) + + http.Handle("/styles/", http.StripPrefix("/styles/", http.FileServer(http.Dir("styles")))) + http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("images")))) + + fmt.Println("Serving") + http.ListenAndServe(":3333", nil) +} diff --git a/styles/er.css b/styles/er.css new file mode 100644 index 0000000..fcef106 --- /dev/null +++ b/styles/er.css @@ -0,0 +1,29 @@ +body { + width: 100%; +} + +.er__title { + height: 20%; + + background: #d6130c; + + display: grid; + place-items: center; + + border-bottom-left-radius:50%; + border-bottom-right-radius:50%; +} + +.alerts { + height: 80%; + + display: flex; + flex-direction: column; + + justify-items: space-around; +} + +.alert { + border: 1px solid black; + margin: 20px; +} diff --git a/styles/index.css b/styles/index.css new file mode 100644 index 0000000..8f82529 --- /dev/null +++ b/styles/index.css @@ -0,0 +1,34 @@ +.theredphone__title { + height: 40%; + + background: #d6130c; + + display: grid; + place-items: center; + + border-bottom-left-radius:50%; + border-bottom-right-radius:50%; +} + +.theredphone__links { + height: 60%; + + display: flex; + justify-content: space-evenly; + align-items: center; +} + +.theredphone__link { + font-size: 2rem; + + padding-top: 2rem; + padding-bottom: 2rem; + padding-left: 1rem; + padding-right: 1rem; + + border: 1px solid red; + border-radius: 25%; + color: black; + text-decoration: none; + background-color: red; +} diff --git a/styles/main.css b/styles/main.css new file mode 100644 index 0000000..16f7ec1 --- /dev/null +++ b/styles/main.css @@ -0,0 +1,17 @@ +*, *::before, *::after { + margin: 0; + box-sizing: border-box; +} + +body { + width: 100vw; + height: 100vh; +} + +.center-grid { + width: 100%; + height: 100%; + + display: grid; + place-items: center; +} diff --git a/styles/paramedic.css b/styles/paramedic.css new file mode 100644 index 0000000..3f976db --- /dev/null +++ b/styles/paramedic.css @@ -0,0 +1,30 @@ +.paramedic-form__title { + height: 20%; + + background: #d6130c; + + display: grid; + place-items: center; + + border-bottom-left-radius:50%; + border-bottom-right-radius:50%; +} + +label { + display: block; +} + +.form-block { + width: 30%; + + display: grid; + place-items: center; + + padding-top: 10px; + padding-bottom: 10px; +} + +form { + display: grid; + place-items: center; +} diff --git a/templates/er.tmpl b/templates/er.tmpl new file mode 100644 index 0000000..d56a921 --- /dev/null +++ b/templates/er.tmpl @@ -0,0 +1,54 @@ + + + + + + + + + + TheRedPhone.xyz -- ER Personnel + + + + + +
+

TheRedPhone.xyz -- ER Personnel

+
+ +
+
+ {{ range . }} +
+

Categorization

+

Categorization: {{ .MedicalOrTrauma }}

+ +
+ +

Patient Data

+

Age: {{ .Age }}

+

Sex: {{ .Sex }}

+

NHS Number: {{ .NhsNumber }}

+ +
+ +

Observations

+

Heart rate: {{ .HeartRate }}

+

Respiratory rate: {{ .RespiratoryRate }}

+

Oxygen Saturation: {{ .OxygenSaturation }}

+

GCS: {{ .Gcs }}

+

Blood pressure: {{ .BloodPressure }}

+ +
+ +

Extra Information

+

Estimated Time of Arrival: {{ .Eta }}

+

Interventions given: {{ .Interventions }}

+

Background info: {{ .BackgroundInfo }}

+
+ {{ end }} +
+
+ + diff --git a/templates/index.tmpl b/templates/index.tmpl new file mode 100644 index 0000000..66621ea --- /dev/null +++ b/templates/index.tmpl @@ -0,0 +1,25 @@ + + + + + + + + + + TheRedPhone.xyz + + + + + +
+

TheRedPhone.xyz

+

Are you a paramedic or ER personnel?

+
+ + + diff --git a/templates/paramedicForm.tmpl b/templates/paramedicForm.tmpl new file mode 100644 index 0000000..38cc6ef --- /dev/null +++ b/templates/paramedicForm.tmpl @@ -0,0 +1,90 @@ + + + + + + + + + + TheRedPhone.xyz: Paramedics + + + + + +
+
+

TheRedPhone.xyz: Paramedics

+

You Are Ambulance Crew Number: 9836283762

+
+ +
+
+

Categorization

+ + +
+ +
+ +
+

Patient Data

+ + + + + + + + +
+ +
+ +
+

Observations

+ + + + + + + + + + + + + + +
+ +
+ +
+

Extra Information

+ + + + + + + + +
+ +
+ +
+
+
+ +