|
|
|
@ -66,8 +66,10 @@ func loadKeyPair() credentials.TransportCredentials { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type HISServer struct { |
|
|
|
|
srv *http.Server |
|
|
|
|
inited bool |
|
|
|
|
apiSrv *http.Server |
|
|
|
|
apiInited bool |
|
|
|
|
uiSrv *http.Server |
|
|
|
|
uiInited bool |
|
|
|
|
data *gorm.DB |
|
|
|
|
stopTasks chan struct{} |
|
|
|
|
clientCert tls.Certificate |
|
|
|
@ -80,27 +82,51 @@ func (srv *HISServer) LoadData(location string) error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) Addr() string { |
|
|
|
|
if srv.srv == nil { |
|
|
|
|
if srv.apiSrv == nil { |
|
|
|
|
return "" |
|
|
|
|
} |
|
|
|
|
return srv.srv.Addr |
|
|
|
|
return srv.apiSrv.Addr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) ListenAndServe() { |
|
|
|
|
if !srv.inited { |
|
|
|
|
srv.init() |
|
|
|
|
func (srv *HISServer) ListenAndServeAPI() error { |
|
|
|
|
|
|
|
|
|
if !srv.apiInited { |
|
|
|
|
srv.initAPI() |
|
|
|
|
} |
|
|
|
|
log.Printf("API Listening on %v\n", srv.apiSrv.Addr) |
|
|
|
|
return srv.apiSrv.ListenAndServeTLS("", "") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) ListenAndServeUI() error { |
|
|
|
|
|
|
|
|
|
if !srv.uiInited { |
|
|
|
|
srv.initUI() |
|
|
|
|
} |
|
|
|
|
log.Println("Listening on %v", srv.srv.Addr) |
|
|
|
|
srv.srv.ListenAndServeTLS("", "") |
|
|
|
|
log.Printf("UI Listening on %v\n", srv.uiSrv.Addr) |
|
|
|
|
return srv.uiSrv.ListenAndServeTLS("", "") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) ShutdownAPI(ctx context.Context) (error, error) { |
|
|
|
|
return srv.apiSrv.Shutdown(ctx), srv.uiSrv.Shutdown(ctx) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) ShutdownUI(ctx context.Context) (error, error) { |
|
|
|
|
return srv.uiSrv.Shutdown(ctx), srv.uiSrv.Shutdown(ctx) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) Shutdown(ctx context.Context) error { |
|
|
|
|
return srv.srv.Shutdown(ctx) |
|
|
|
|
func (srv *HISServer) initAPI() { |
|
|
|
|
srv.apiInited = true |
|
|
|
|
r := srv.apiSrv.Handler.(*gin.Engine) |
|
|
|
|
|
|
|
|
|
r.Use(srv.Authenticate) |
|
|
|
|
r.GET("/external/api/patients/:id", srv.GetPatient) |
|
|
|
|
r.GET("/external/fhir/Patient", srv.GetFHIRPatient) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *HISServer) init() { |
|
|
|
|
r := srv.srv.Handler.(*gin.Engine) |
|
|
|
|
func (srv *HISServer) initUI() { |
|
|
|
|
srv.uiInited = true |
|
|
|
|
|
|
|
|
|
r := srv.uiSrv.Handler.(*gin.Engine) |
|
|
|
|
r.LoadHTMLGlob("templates/*") |
|
|
|
|
r.Static("/assets", "./assets") |
|
|
|
|
|
|
|
|
@ -121,11 +147,6 @@ func (srv *HISServer) init() { |
|
|
|
|
r.GET("/api/services", srv.GetServices) |
|
|
|
|
r.POST("/api/services/:id/subscriptions", srv.UpdateSubscription) |
|
|
|
|
|
|
|
|
|
r.Use(srv.Authenticate) |
|
|
|
|
r.GET("/external/api/patients/:id", srv.GetPatient) |
|
|
|
|
r.GET("/external/fhir/Patient", srv.GetFHIRPatient) |
|
|
|
|
srv.inited = true |
|
|
|
|
|
|
|
|
|
ticker := time.NewTicker(30 * time.Second) |
|
|
|
|
srv.stopTasks = make(chan struct{}) |
|
|
|
|
srv.TaskSyncPatients() |
|
|
|
@ -612,11 +633,11 @@ func (srv *HISServer) GetFHIRPatient(c *gin.Context) { |
|
|
|
|
c.JSON(404, nil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewServer(addr string) *HISServer { |
|
|
|
|
func NewServer(apiAddr, uiAddr string) *HISServer { |
|
|
|
|
cert := loadCert() |
|
|
|
|
srv := &HISServer{ |
|
|
|
|
srv: &http.Server{ |
|
|
|
|
Addr: addr, |
|
|
|
|
apiSrv: &http.Server{ |
|
|
|
|
Addr: apiAddr, |
|
|
|
|
Handler: gin.Default(), |
|
|
|
|
TLSConfig: &tls.Config{ |
|
|
|
|
ClientAuth: tls.RequestClientCert, |
|
|
|
@ -625,6 +646,15 @@ func NewServer(addr string) *HISServer { |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
uiSrv: &http.Server{ |
|
|
|
|
Addr: uiAddr, |
|
|
|
|
Handler: gin.Default(), |
|
|
|
|
TLSConfig: &tls.Config{ |
|
|
|
|
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) { |
|
|
|
|
return cert, nil |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
clientCert: *cert, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|