Compare commits

...

5 Commits

Author SHA1 Message Date
Bas Kloosterman 8447582bbc Add initial docker-compose file 1 year ago
Bas Kloosterman f7bd097470 Update docker-compose copy bin folder 1 year ago
Bas Kloosterman 81876ae051 Cleanup whitebox server code 1 year ago
Bas Kloosterman b76b8aebae Cleanup dvza server code 1 year ago
Bas Kloosterman bc161904d8 Update gitignore to ignore database and certs 1 year ago
  1. 2
      .gitignore
  2. 1
      Dockerfile.wbx
  3. 36
      docker-compose.yaml
  4. 87
      dvzaservice/srv.go
  5. 108
      whiteboxservice/srv.go

2
.gitignore vendored

@ -1 +1,3 @@
node_modules
data/data.db
certs

@ -29,6 +29,7 @@ WORKDIR /
COPY ./whiteboxservice/assets /assets
COPY ./whiteboxservice/templates /templates
COPY ./whiteboxservice/bin /bin
COPY --from=build /app/bin/wbx ./wbx
RUN adduser -D nonroot

@ -0,0 +1,36 @@
version: '3.0'
services:
okapi_his:
image: src.whiteboxsystems.nl/decozo/okapidemo/his
container_name: okapi_his
restart: always
environment:
EXT_ADDR: "https://okapi_his:8084"
volumes:
- "./his/data:/data"
- "./his/certs:/certs"
ports:
- 8084:8084
okapi_wbx:
image: src.whiteboxsystems.nl/decozo/okapidemo/whitebox
container_name: okapi_wbx
restart: always
environment:
EXT_ADDR: "okapi_wbx:8888"
BIN_FOLDER: "/wbxbin"
volumes:
- "./wbx/data:/data"
- "./wbx/certs:/certs"
ports:
- 8085:8085
okapi_dvza:
image: src.whiteboxsystems.nl/decozo/okapidemo/whitebox
container_name: okapi_dvza
restart: always
environment:
EXT_ADDR: "okapi_dvza:9999"
volumes:
- "./dvza/data:/data"
- "./dvza/certs:/certs"
ports:
- 9095:9095

@ -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(&registrations)
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{

@ -57,7 +57,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)
@ -66,8 +66,6 @@ func (srv *UIService) init() {
r.GET("/api/connections/:connID/:serviceID", srv.GetSubscriptions)
r.GET("/api/connections/:connID/:serviceID/:patientID", srv.GetPatient)
r.GET("/api/registrations", srv.GetRegistrations)
// r.GET("/api/systems/:sysid/patients", srv.GetPatients)
// r.GET("/api/systems/:sysid/patients/:patid", srv.GetPatient)
srv.inited = true
}
@ -79,14 +77,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) {
@ -96,7 +94,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
patient := &sharedmodel.Subscription{}
serviceConfig := &sharedmodel.ServiceConfig{}
if err := srv.data.Preload("FetchProtocol").Preload("FetchProtocol.AuthConfig").Preload("Service").Where("connection_id = ? and id = ?", connID, serviceID).Find(&serviceConfig).Error; err != nil {
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
return
}
srv.data.Where("service_config_id = ? and id = ?", serviceID, patientID).Find(&patient)
@ -106,16 +104,21 @@ 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/%v/%v", protoconfig["url"], "patients", protometa["patientID"])
req, _ := http.NewRequest("GET", url, nil)
// req.Header.Set("Authorization", serviceConfig.FetchProtocol.AuthConfig.Raw)
client := &http.Client{
Transport: &http.Transport{
@ -129,7 +132,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
}
@ -142,7 +145,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
sin, err := cmd.StdinPipe()
if err != nil {
log.Println("[ediviewer] Failed to open stdin pipe:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer sin.Close()
@ -150,7 +153,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
serr, err := cmd.StderrPipe()
if err != nil {
log.Println("[ediviewer] Failed to open stderr pipe:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer serr.Close()
@ -158,14 +161,14 @@ func (srv *UIService) GetPatient(c *gin.Context) {
sout, err := cmd.StdoutPipe()
if err != nil {
log.Println("[ediviewer] Failed to open stdout pipe:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer sout.Close()
if err := cmd.Start(); err != nil {
log.Println("[ediviewer] Failed to start:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
return
}
@ -176,7 +179,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
defer wg.Done()
if _, err := io.Copy(sin, resp.Body); err != nil {
log.Println("[ediviewer] Error reading EDIFACT:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
}
}()
@ -184,7 +187,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
defer wg.Done()
if _, err := io.Copy(c.Writer, sout); err != nil {
log.Println("[ediviewer] Error output EDIFACT:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
}
}()
@ -192,7 +195,7 @@ func (srv *UIService) GetPatient(c *gin.Context) {
defer wg.Done()
if _, err := io.Copy(os.Stderr, serr); err != nil {
log.Println("[ediviewer] Error stderr EDIFACT:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
}
}()
@ -200,89 +203,26 @@ func (srv *UIService) GetPatient(c *gin.Context) {
if err := cmd.Wait(); err != nil {
log.Println("[ediviewer] Failed:", err)
c.AbortWithError(500, err)
c.AbortWithError(http.StatusInternalServerError, err)
}
}
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(&registrations)
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()

Loading…
Cancel
Save