|
|
|
@ -54,7 +54,7 @@ func (srv *UIService) init() { |
|
|
|
|
|
|
|
|
|
r.Use(srv.Authenticate) |
|
|
|
|
r.GET("/", func(c *gin.Context) { |
|
|
|
|
c.Redirect(301, "/ui") |
|
|
|
|
c.Redirect(http.StatusMovedPermanently, "/ui") |
|
|
|
|
}) |
|
|
|
|
r.GET("/ui", srv.GetIndex) |
|
|
|
|
r.GET("/ui/*page", srv.GetIndex) |
|
|
|
@ -76,14 +76,14 @@ func (srv *UIService) GetConnection(c *gin.Context) { |
|
|
|
|
connID := c.Param("connID") |
|
|
|
|
connection := &sharedmodel.Connection{} |
|
|
|
|
srv.data.Where("id = ?", connID).Find(&connection) |
|
|
|
|
c.JSON(200, connection) |
|
|
|
|
c.JSON(http.StatusOK, connection) |
|
|
|
|
} |
|
|
|
|
func (srv *UIService) GetSubscriptions(c *gin.Context) { |
|
|
|
|
connID := c.Param("connID") |
|
|
|
|
serviceID := c.Param("serviceID") |
|
|
|
|
serviceConfig := &sharedmodel.ServiceConfig{} |
|
|
|
|
srv.data.Preload("Service").Preload("Subscriptions").Where("connection_id = ? and id = ?", connID, serviceID).Find(&serviceConfig) |
|
|
|
|
c.JSON(200, serviceConfig) |
|
|
|
|
c.JSON(http.StatusOK, serviceConfig) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *UIService) GetPatient(c *gin.Context) { |
|
|
|
@ -100,11 +100,17 @@ func (srv *UIService) GetPatient(c *gin.Context) { |
|
|
|
|
|
|
|
|
|
err := serviceConfig.FetchProtocol.UnmarshalConfig(&protoconfig) |
|
|
|
|
|
|
|
|
|
log.Println(err, protoconfig) |
|
|
|
|
if err != nil { |
|
|
|
|
c.AbortWithStatus(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = patient.GetProtocolMeta(&protometa) |
|
|
|
|
|
|
|
|
|
log.Println(err, protometa) |
|
|
|
|
if err != nil { |
|
|
|
|
c.AbortWithStatus(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
url := fmt.Sprintf("%v?id=%v", protoconfig["url"], protometa["patientID"]) |
|
|
|
|
|
|
|
|
@ -122,7 +128,7 @@ func (srv *UIService) GetPatient(c *gin.Context) { |
|
|
|
|
resp, err := client.Do(req) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
c.AbortWithError(500, err) |
|
|
|
|
c.AbortWithError(http.StatusInternalServerError, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -135,84 +141,21 @@ func (srv *UIService) GetPatient(c *gin.Context) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *UIService) Authenticate(c *gin.Context) { |
|
|
|
|
// authHeader := c.Request.Header.Get("Authorization")
|
|
|
|
|
// log.Printf("authHeader: %v", authHeader)
|
|
|
|
|
|
|
|
|
|
// if authHeader != "1111" {
|
|
|
|
|
// c.Status(401)
|
|
|
|
|
// c.Abort()
|
|
|
|
|
// }
|
|
|
|
|
// Maybe authenticate user
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *UIService) GetConnections(c *gin.Context) { |
|
|
|
|
connections := []*sharedmodel.Connection{} |
|
|
|
|
srv.data.Preload("Services").Preload("Services.Service").Preload("Services.Subscriptions").Find(&connections) |
|
|
|
|
c.JSON(200, connections) |
|
|
|
|
c.JSON(http.StatusOK, connections) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (srv *UIService) GetRegistrations(c *gin.Context) { |
|
|
|
|
registrations := []*sharedmodel.Registration{} |
|
|
|
|
srv.data.Where("status = ?", sharedmodel.RegistrationStatusPending).Find(®istrations) |
|
|
|
|
c.JSON(200, registrations) |
|
|
|
|
c.JSON(http.StatusOK, registrations) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// func (srv *UIService) GetSystems(c *gin.Context) {
|
|
|
|
|
// id := c.Param("id")
|
|
|
|
|
// for _, p := range patients {
|
|
|
|
|
// if p.PatientID == id {
|
|
|
|
|
// f, err := os.Open(path.Join("./data/patients", p.EDI))
|
|
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// c.Error(err)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// io.Copy(c.Writer, f)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// c.JSON(404, nil)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// func (srv *UIService) GetPatients(c *gin.Context) {
|
|
|
|
|
// id := c.Param("id")
|
|
|
|
|
// for _, p := range patients {
|
|
|
|
|
// if p.PatientID == id {
|
|
|
|
|
// f, err := os.Open(path.Join("./data/patients", p.EDI))
|
|
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// c.Error(err)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// io.Copy(c.Writer, f)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// c.JSON(404, nil)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// func (srv *UIService) GetPatient(c *gin.Context) {
|
|
|
|
|
// id := c.Param("id")
|
|
|
|
|
// for _, p := range patients {
|
|
|
|
|
// if p.PatientID == id {
|
|
|
|
|
// f, err := os.Open(path.Join("./data/patients", p.EDI))
|
|
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// c.Error(err)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// io.Copy(c.Writer, f)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// c.JSON(404, nil)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
func NewUIServer(addr string) *UIService { |
|
|
|
|
cert := loadCert() |
|
|
|
|
srv := &UIService{srv: &http.Server{ |
|
|
|
|