diff --git a/admissionServer.exe b/admissionServer.exe new file mode 100644 index 0000000..59d5dba Binary files /dev/null and b/admissionServer.exe differ diff --git a/basicModels.go b/basicModels.go index 646ee78..bf095b5 100644 --- a/basicModels.go +++ b/basicModels.go @@ -1,6 +1,9 @@ package main -import "time" +import ( + "database/sql" + "time" +) type patient struct { Pesel string @@ -20,7 +23,7 @@ type diagnosis struct { } type doctor struct { - DoctorID int + DoctorID int64 Name string Surname string AcademicDegree academicDegree @@ -30,12 +33,12 @@ type doctor struct { } type operation struct { - OperationID int + OperationID int64 Name string - averageTime time.Time + averageTime string operationType operationTypes - cost float32 - refoundation int + cost []uint8 + refoundation int64 } type room struct { @@ -66,3 +69,9 @@ type diagnoses []diagnosis type admissions []admission type operations []operation type rooms []room + +type iDatabaseModel interface{} +type iDatabaseModels []iDatabaseModel +type iStoreModels interface { + readModels(rows *sql.Rows) iDatabaseModels +} diff --git a/databaseConnection.go b/databaseConnection.go index d01c3e4..f1699e0 100644 --- a/databaseConnection.go +++ b/databaseConnection.go @@ -1,6 +1,7 @@ package main import ( + "context" "database/sql" "fmt" "log" @@ -26,5 +27,41 @@ func testConnection() { log.Fatal(err.Error()) } fmt.Printf("Connected!\n") - fmt.Println("..I..") +} + +type iHasValue interface{} +type values []iHasValue + +func readDatabase(tableName string) (iDatabaseModels, error) { + ctx := context.Background() + checkIsDatabaseAlive() + tsql := "SELECT * FROM " + tableName + rows, _ := db.QueryContext(ctx, tsql) + defer rows.Close() + var models iDatabaseModels + models = nil + switch tableName { + case "Lekarze": + var x doctors + models = x.readModels(rows) + case "Pacjenci": + var x patients + models = x.readModels(rows) + case "Operacje": + var x operations + models = x.readModels(rows) + case "Diagnozy": + var x diagnoses + models = x.readModels(rows) + } + return models, nil +} + +func checkIsDatabaseAlive() error { + err = db.Ping() + if err != nil { + log.Fatal(err.Error()) + + } + return nil } diff --git a/enums.go b/enums.go index d1570a7..24fbc17 100644 --- a/enums.go +++ b/enums.go @@ -1,12 +1,12 @@ package main type patientStates string -type sex int -type surgeryField int -type academicDegree int -type specialization int -type jobPosition int -type operationTypes int +type sex string +type surgeryField string +type academicDegree string +type specialization string +type jobPosition string +type operationTypes string const ( critical patientStates = "KRYTYCZNY" //KRYTYCZNY @@ -17,57 +17,57 @@ const ( ) const ( - k sex = 0 - m sex = 1 + k sex = "K" + m sex = "M" ) const ( - ogolna surgeryField = 0 - klatkiPiersiowej surgeryField = 1 - sercowoNaczyniowa surgeryField = 2 - ukladuNerwowego surgeryField = 3 - urologia surgeryField = 4 - szczekowoTwarzowa surgeryField = 5 - urazowa surgeryField = 6 - inne surgeryField = 7 + ogolna surgeryField = "Ogólna" + klatkiPiersiowej surgeryField = "Klatki piersiowej" + sercowoNaczyniowa surgeryField = "Sercowo - naczyniowa" + ukladuNerwowego surgeryField = "Układu nerwowego" + urologia surgeryField = "Urologia" + szczekowoTwarzowa surgeryField = "Szczękowo - twarzowa" + urazowa surgeryField = "Urazowa" + inne surgeryField = "NULL" ) const ( - lekMed academicDegree = 0 - lekRez academicDegree = 1 - lekSpec academicDegree = 2 - dr academicDegree = 3 - drHab academicDegree = 4 - prof academicDegree = 5 + lekMed academicDegree = "lek. med." + lekRez academicDegree = "lek. rez." + lekSpec academicDegree = "lek. spec." + dr academicDegree = "dr" + drHab academicDegree = "dr hab." + prof academicDegree = "prof." ) const ( - chirOgolna specialization = 0 - chirKlatkiPiers specialization = 1 - chirSercowoNaczyn specialization = 2 - chirUkNerwowego specialization = 3 - chirUrologiczna specialization = 4 - chirSzczekTwarz specialization = 5 - chirUrazowa specialization = 6 + chirOgolna specialization = "Chirurgia ogólna" + chirKlatkiPiers specialization = "Chirurgia klatki piersiowej" + chirSercowoNaczyn specialization = "Chirurgia sercowo - naczyniowa" + chirUkNerwowego specialization = "Chirurgia układu nerwowego" + chirUrologiczna specialization = "Urologia" + chirSzczekTwarz specialization = "Chirurgia szczękowo - twarzowa" + chirUrazowa specialization = "Chirurgia urazowa" ) const ( - generalPracticioner jobPosition = 0 - mainDoctor jobPosition = 1 - viceManager jobPosition = 2 - manager jobPosition = 3 - hospitalHead jobPosition = 4 + generalPracticioner jobPosition = "Lekarz ogólny" + mainDoctor jobPosition = "Lekarz prowadzący" + viceManager jobPosition = "Zastępca kierownika" + manager jobPosition = "Kierownik" + hospitalHead jobPosition = "Ordynator" ) const ( - szycie operationTypes = 0 - resekcja operationTypes = 1 - amputacja operationTypes = 2 - drenaz operationTypes = 3 - nastawienieZlaman operationTypes = 4 - operacjaKlatkiPiers operationTypes = 5 - operacjaSerca operationTypes = 6 - operacjaUkNerwow operationTypes = 7 - przeszczep operationTypes = 8 - inneOperacje operationTypes = 9 + szycie operationTypes = "Szycie" + resekcja operationTypes = "Resekcja" + amputacja operationTypes = "Amputacja" + drenaz operationTypes = "Drenaż" + nastawienieZlaman operationTypes = "Nastawianie złamań" + operacjaKlatkiPiers operationTypes = "Ingerencja wewnątrz klatki piersiowej" + operacjaSerca operationTypes = "Operacja serca" + operacjaUkNerwow operationTypes = "Operacja układu nerwowego" + przeszczep operationTypes = "Przeszczep" + inneOperacje operationTypes = "Inne" ) diff --git a/handlers.go b/handlers.go index 3efb330..b7639c6 100644 --- a/handlers.go +++ b/handlers.go @@ -5,7 +5,6 @@ import ( "fmt" "html" "net/http" - "time" "github.com/gorilla/mux" ) @@ -14,10 +13,9 @@ func index(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) } func getAll(w http.ResponseWriter, r *http.Request) { - patientsList := patients{ - patient{"kss", "dasda", "asdasd a", time.Now(), patientStates(critical), sex(m), "xxx@yyy.zz"}, - patient{"00112245789", "Adam", "Marcel", time.Now(), patientStates(stable), sex(k), "xxxx@yyy.zz"}, - } + args := mux.Vars(r) + table := args["tableName"] + patientsList, _ := readDatabase(table) json.NewEncoder(w).Encode(patientsList) } func getIndex(w http.ResponseWriter, r *http.Request) { diff --git a/index.go b/index.go index e02dd1d..a2b6511 100644 --- a/index.go +++ b/index.go @@ -7,10 +7,11 @@ import ( ) // Zrobione ostatnio: -// prosta refraktoryzacja; -// Zrobione: -// Podstawowy serwer; Podstawowe struktury modeli; niezbędne enumy; // +// Zrobione: +// Podstawowy serwer; Podstawowe struktury modeli; niezbędne enumy; prosta refraktoryzacja; +// Utworzenie połączenia z bazą danych + // Do zrobienia: // Funkcje modeli; Interfejsy json; łączenie z bazą danych; Rozne metody do tworzenia komend sql; // Komunikacja z aplikacja desktopowa; Walidacja danych!! ; diff --git a/modelsMethods.go b/modelsMethods.go new file mode 100644 index 0000000..c83a4c3 --- /dev/null +++ b/modelsMethods.go @@ -0,0 +1,87 @@ +package main + +import ( + "database/sql" + "time" +) + +func (doc doctors) readModels(rows *sql.Rows) iDatabaseModels { + var models iDatabaseModels + for rows.Next() { + var valueList [7]iHasValue + rows.Scan(&valueList[0], &valueList[1], &valueList[2], &valueList[3], &valueList[4], + &valueList[5], &valueList[6]) + + models = append(models, doctor{ + valueList[0].(int64), valueList[1].(string), valueList[2].(string), academicDegree(valueList[3].(string)), + specialization(valueList[4].(string)), valueList[5].(time.Time), jobPosition(valueList[6].(string))}) + } + return models +} +func (pat patients) readModels(rows *sql.Rows) iDatabaseModels { + var models iDatabaseModels + for rows.Next() { + var valueList [7]iHasValue + rows.Scan(&valueList[0], &valueList[1], &valueList[2], &valueList[3], &valueList[4], + &valueList[5]) + var patientSta patientStates + if valueList[4] == nil { + patientSta = patientStates("NULL") + } else { + patientSta = patientStates(valueList[4].(string)) + } + var se sex + if valueList[5] == nil { + se = sex("M") + } else { + se = sex(valueList[5].(string)) + } + models = append(models, patient{ + valueList[0].(string), valueList[1].(string), valueList[2].(string), valueList[3].(time.Time), + patientSta, se, ""}) + } + return models +} +func (dia diagnoses) readModels(rows *sql.Rows) iDatabaseModels { + var models iDatabaseModels + for rows.Next() { + var valueList [4]iHasValue + rows.Scan(&valueList[0], &valueList[1], &valueList[2], &valueList[3]) + var opis string + if valueList[3] == nil { + opis = "Brak" + } else { + opis = valueList[3].(string) + } + models = append(models, diagnosis{ + valueList[0].(string), valueList[1].(string), surgeryField(valueList[2].(string)), opis}) + } + return models +} +func (ope operations) readModels(rows *sql.Rows) iDatabaseModels { + var models iDatabaseModels + for rows.Next() { + var valueList [6]iHasValue + rows.Scan(&valueList[0], &valueList[1], &valueList[2], &valueList[3], &valueList[4], + &valueList[5]) + + models = append(models, operation{ + valueList[0].(int64), valueList[1].(string), "5:00", operationTypes(valueList[3].(string)), + valueList[4].([]uint8), valueList[5].(int64)}) + } + return models +} + +/*func (doc admissions) readModels(rows *sql.Rows) iDatabaseModels { + var models iDatabaseModels + for rows.Next() { + var valueList [7]iHasValue + rows.Scan(&valueList[0], &valueList[1], &valueList[2], &valueList[3], &valueList[4], + &valueList[5], &valueList[6]) + + models = append(models, admission{ + valueList[0].(int64), valueList[1].(string), valueList[2].(string), academicDegree(valueList[3].(string)), + specialization(valueList[4].(string)), valueList[5].(time.Time), jobPosition(valueList[6].(string))}) + } + return models +}*/ diff --git a/routes.go b/routes.go index 08bfeed..eaf1ab9 100644 --- a/routes.go +++ b/routes.go @@ -16,7 +16,7 @@ type routes []route var registredRoutes = routes{ route{"Index", "/", index}, - route{"GetAll", "/getfromdb", getAll}, + route{"GetAll", "/getfromdb/{tableName}", getAll}, route{"GetOne", "/getfromdb/{primaryKey}", getIndex}, }