You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.1 KiB
71 lines
2.1 KiB
package model
|
|
|
|
import (
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"whiteboxsystems.nl/openkvpoc/openkv"
|
|
"whiteboxsystems.nl/openkvpoc/sharedmodel"
|
|
)
|
|
|
|
func GetDB(location string) (*gorm.DB, error) {
|
|
db, err := gorm.Open(sqlite.Open(location), &gorm.Config{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Migrate the schema
|
|
db.AutoMigrate(&sharedmodel.Registration{})
|
|
db.AutoMigrate(&sharedmodel.Connection{})
|
|
db.AutoMigrate(&sharedmodel.Service{})
|
|
db.AutoMigrate(&sharedmodel.AuthConfig{})
|
|
db.AutoMigrate(&sharedmodel.ProtocolConfig{})
|
|
db.AutoMigrate(&sharedmodel.ServiceConfig{})
|
|
db.AutoMigrate(&sharedmodel.Subscription{})
|
|
|
|
var cnt int64
|
|
db.Model(&sharedmodel.Service{}).Count(&cnt)
|
|
|
|
if cnt == 0 {
|
|
db.Create(&sharedmodel.Service{
|
|
Name: "Visitelijst",
|
|
Description: "Visitelijst voor het inzien van patientendossiers op visite",
|
|
SubscriptionPolicy: openkv.SubscriptionPolicy_optin,
|
|
ConsentPolicy: openkv.ConsentPolicy_presumed,
|
|
ServiceID: "wbx:visitelijst",
|
|
FetchProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-fetch/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
PushProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-push/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
})
|
|
|
|
db.Create(&sharedmodel.Service{
|
|
Name: "Waarneminglijst",
|
|
Description: "Waarneminglijst om patienten inzichtelijk te maken op de HAP",
|
|
SubscriptionPolicy: openkv.SubscriptionPolicy_optin,
|
|
ConsentPolicy: openkv.ConsentPolicy_explicit,
|
|
ServiceID: "wbx:waarneming",
|
|
FetchProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-fetch/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
PushProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-push/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
return db, nil
|
|
}
|
|
|