Dodano podstawowe modele i enumy

- Podstawowe modele reprezentujące tabele w DB zostały dodane;
- Podstawowe enumy zostały dodane
This commit is contained in:
Marcel 2018-11-25 12:46:45 +01:00
parent 880b93b93f
commit 8b9daa4f2c
3 changed files with 164 additions and 2 deletions

68
basicModels.go Normal file
View File

@ -0,0 +1,68 @@
package main
import "time"
type patient struct {
Pesel string
Name string
Surname string
BirthDate time.Time
PatientState patientStates
PatientSex sex
PatientEmail string
}
type diagnosis struct {
IcdSymbol string
Name string
FieldOfSurgery surgeryField
Description string
}
type doctor struct {
DoctorID int
Name string
Surname string
AcademicDegree academicDegree
Specialization specialization
DateOfEmployment time.Time
JobPosition jobPosition
}
type operation struct {
OperationID int
Name string
averageTime time.Time
operationType operationTypes
cost float32
refoundation int
}
type room struct {
RoomNumber int
NumberOfBeds int
IncrasedCare bool
}
type admission struct {
AdmissionID int
AdmissionDate time.Time
EndDate time.Time
PatientPesel string
DiagnosisSymbol string
MainDoctor int
PlanedOperation int
RoomNumber int
IsPlanned bool
}
func (p patient) showPatient() string {
return p.Pesel
}
type patients []patient
type doctors []doctor
type diagnoses []diagnosis
type admissions []admission
type operations []operation
type rooms []room

73
enums.go Normal file
View File

@ -0,0 +1,73 @@
package main
type patientStates string
type sex int
type surgeryField int
type academicDegree int
type specialization int
type jobPosition int
type operationTypes int
const (
critical patientStates = "KRYTYCZNY" //KRYTYCZNY
stable patientStates = "STABILNY" //Stabilny
endangered patientStates = "ZAGROŻONY" // ZAGROZONY
none patientStates = "NULL" //NULL
)
const (
k sex = 0
m sex = 1
)
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
)
const (
lekMed academicDegree = 0
lekRez academicDegree = 1
lekSpec academicDegree = 2
dr academicDegree = 3
drHab academicDegree = 4
prof academicDegree = 5
)
const (
chirOgolna specialization = 0
chirKlatkiPiers specialization = 1
chirSercowoNaczyn specialization = 2
chirUkNerwowego specialization = 3
chirUrologiczna specialization = 4
chirSzczekTwarz specialization = 5
chirUrazowa specialization = 6
)
const (
generalPracticioner jobPosition = 0
mainDoctor jobPosition = 1
viceManager jobPosition = 2
manager jobPosition = 3
hospitalHead jobPosition = 4
)
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
)

View File

@ -1,31 +1,52 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"html" "html"
"log" "log"
"net/http" "net/http"
"time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
// Zrobione ostatnio:
// Podstawowe struktury modeli; niezbędne enumy;
// Zrobione:
// Podstawowy serwer;
//
// Do zrobienia:
// Funkcje modeli; Interfejsy json; łączenie z bazą danych; Rozne metody do tworzenia komend sql;
// Komunikacja z aplikacja desktopowa; Walidacja danych!! ;
func main() { func main() {
xx := getXxx()
xx.Pesel = "ssss"
muxRouter := mux.NewRouter().StrictSlash(true) muxRouter := mux.NewRouter().StrictSlash(true)
muxRouter.HandleFunc("/", index) muxRouter.HandleFunc("/", index)
muxRouter.HandleFunc("/getfromdb", getAll) muxRouter.HandleFunc("/getfromdb", getAll)
muxRouter.HandleFunc("/getfromdb/{primaryKey}", getIndex) muxRouter.HandleFunc("/getfromdb/{primaryKey}", getIndex)
log.Fatal(http.ListenAndServe(":8080", muxRouter)) log.Fatal(http.ListenAndServe(":8080", muxRouter))
} }
func index(w http.ResponseWriter, r *http.Request) { func index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
} }
func getAll(w http.ResponseWriter, r *http.Request) { func getAll(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Tutaj dostaniesz wyniki z bazy danych") 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"},
}
json.NewEncoder(w).Encode(patientsList)
} }
func getIndex(w http.ResponseWriter, r *http.Request) { func getIndex(w http.ResponseWriter, r *http.Request) {
args := mux.Vars(r) args := mux.Vars(r)
pk := args["primaryKey"] pk := args["primaryKey"]
fmt.Fprintf(w, "Tutaj bedzie wynik dla PK = %s", pk) fmt.Fprintf(w, "Tutaj bedzie wynik dla PK = %s", pk)
} }
func getXxx() patient {
pat := patient{"kss", "dasda", "asdasd a", time.Now(), patientStates(critical), sex(m), "xxx@yyy.zz"}
return pat
}