demo additionnal content for the future

This commit is contained in:
mr
2026-03-09 16:29:32 +01:00
parent cbf32fff48
commit e439e06ac4
19 changed files with 395 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: chu-pipeline
namespace: default
spec:
entrypoint: chu-steps
volumeClaimTemplates:
- metadata:
name: chu-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
templates:
- name: chu-steps
steps:
- - name: chu-statistics
template: chu-statistics
- - name: chu-analyzer
template: chu-analyzer
- name: chu-statistics
container:
image: opencloudregistry/chu-statistics:latest
command: ["chu-statistics"]
volumeMounts:
- name: chu-data
mountPath: /data
- name: chu-analyzer
container:
image: opencloudregistry/chu-analyzer:latest
command: ["chu-analyzer"]
volumeMounts:
- name: chu-data
mountPath: /data

View File

@@ -0,0 +1,12 @@
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod .
COPY main.go .
RUN go build -o chu-analyzer .
FROM alpine:latest
RUN apk --no-cache add ca-certificates tzdata
RUN mkdir -p /data
WORKDIR /app
COPY --from=builder /app/chu-analyzer /usr/local/bin/chu-analyzer
ENTRYPOINT ["chu-analyzer"]

View File

@@ -0,0 +1,3 @@
module chu-stats-analyzer
go 1.22

View File

@@ -0,0 +1,204 @@
package main
import (
"encoding/json"
"fmt"
"log"
"math"
"os"
"strings"
"time"
)
const dataFile = "/data/chu_stats.json"
type CHUStats struct {
GeneratedAt time.Time `json:"generated_at"`
HospitalName string `json:"hospital_name"`
Date string `json:"date"`
BedsTotal int `json:"beds_total"`
BedsOccupied int `json:"beds_occupied"`
OccupancyRate float64 `json:"occupancy_rate"`
PatientsAdmitted int `json:"patients_admitted"`
PatientsDischarge int `json:"patients_discharged"`
EmergencyVisits int `json:"emergency_visits"`
AvgERWaitMinutes int `json:"avg_er_wait_minutes"`
SurgeriesPerformed int `json:"surgeries_performed"`
ICUBeds int `json:"icu_beds"`
ICUOccupied int `json:"icu_occupied"`
MortalityRate float64 `json:"mortality_rate"`
InfectionRate float64 `json:"infection_rate"`
StaffPresent int `json:"staff_present"`
StaffRequired int `json:"staff_required"`
PatientSatisfaction float64 `json:"patient_satisfaction"`
}
type Check struct {
Indicator string `json:"indicator"`
Value float64 `json:"value"`
Unit string `json:"unit"`
Threshold string `json:"threshold"`
Conformant bool `json:"conformant"`
Severity string `json:"severity"`
Message string `json:"message"`
}
type Analysis struct {
AnalyzedAt time.Time `json:"analyzed_at"`
HospitalName string `json:"hospital_name"`
StatsDate string `json:"stats_date"`
Conformant bool `json:"conformant"`
Score int `json:"score"`
PassingChecks int `json:"passing_checks"`
TotalChecks int `json:"total_checks"`
CriticalAlerts int `json:"critical_alerts"`
WarningAlerts int `json:"warning_alerts"`
Checks []Check `json:"checks"`
Summary string `json:"summary"`
}
func round2(v float64) float64 {
return math.Round(v*100) / 100
}
func analyze(s CHUStats) Analysis {
var checks []Check
occ := Check{Indicator: "Taux d'occupation des lits", Value: s.OccupancyRate, Unit: "%", Threshold: "< 85%"}
switch {
case s.OccupancyRate < 85:
occ.Conformant, occ.Severity, occ.Message = true, "ok", "Taux d'occupation normal"
case s.OccupancyRate < 95:
occ.Conformant, occ.Severity, occ.Message = false, "warning", "Taux d'occupation élevé, risque de saturation"
default:
occ.Conformant, occ.Severity, occ.Message = false, "critical", "Saturation critique des lits hospitaliers"
}
checks = append(checks, occ)
er := Check{Indicator: "Temps d'attente aux urgences", Value: float64(s.AvgERWaitMinutes), Unit: "min", Threshold: "< 60 min"}
switch {
case s.AvgERWaitMinutes < 60:
er.Conformant, er.Severity, er.Message = true, "ok", "Temps d'attente aux urgences acceptable"
case s.AvgERWaitMinutes < 120:
er.Conformant, er.Severity, er.Message = false, "warning", "Temps d'attente aux urgences trop long"
default:
er.Conformant, er.Severity, er.Message = false, "critical", "Saturation critique des urgences"
}
checks = append(checks, er)
icuRate := round2(float64(s.ICUOccupied) / float64(s.ICUBeds) * 100)
icu := Check{Indicator: "Taux d'occupation ICU", Value: icuRate, Unit: "%", Threshold: "< 85%"}
switch {
case icuRate < 85:
icu.Conformant, icu.Severity, icu.Message = true, "ok", "Capacité de réanimation suffisante"
case icuRate < 95:
icu.Conformant, icu.Severity, icu.Message = false, "warning", "Taux d'occupation ICU élevé"
default:
icu.Conformant, icu.Severity, icu.Message = false, "critical", "Réanimation en situation critique"
}
checks = append(checks, icu)
mort := Check{Indicator: "Taux de mortalité hospitalière", Value: s.MortalityRate, Unit: "%", Threshold: "< 2%"}
switch {
case s.MortalityRate < 2.0:
mort.Conformant, mort.Severity, mort.Message = true, "ok", "Taux de mortalité dans les normes"
case s.MortalityRate < 4.0:
mort.Conformant, mort.Severity, mort.Message = false, "warning", "Taux de mortalité supérieur au seuil recommandé"
default:
mort.Conformant, mort.Severity, mort.Message = false, "critical", "Taux de mortalité critique — investigation requise"
}
checks = append(checks, mort)
infect := Check{Indicator: "Taux d'infection nosocomiale", Value: s.InfectionRate, Unit: "%", Threshold: "< 5%"}
switch {
case s.InfectionRate < 5.0:
infect.Conformant, infect.Severity, infect.Message = true, "ok", "Taux d'infection nosocomiale acceptable"
case s.InfectionRate < 8.0:
infect.Conformant, infect.Severity, infect.Message = false, "warning", "Taux d'infection nosocomiale préoccupant"
default:
infect.Conformant, infect.Severity, infect.Message = false, "critical", "Risque infectieux critique — mesures d'urgence requises"
}
checks = append(checks, infect)
staffRate := round2(float64(s.StaffPresent) / float64(s.StaffRequired) * 100)
staff := Check{Indicator: "Taux de couverture du personnel", Value: staffRate, Unit: "%", Threshold: ">= 80%"}
switch {
case staffRate >= 80:
staff.Conformant, staff.Severity, staff.Message = true, "ok", "Personnel suffisant"
case staffRate >= 70:
staff.Conformant, staff.Severity, staff.Message = false, "warning", "Manque de personnel, vigilance requise"
default:
staff.Conformant, staff.Severity, staff.Message = false, "critical", "Sous-effectif critique"
}
checks = append(checks, staff)
sat := Check{Indicator: "Satisfaction des patients", Value: s.PatientSatisfaction, Unit: "/ 5", Threshold: ">= 3.5 / 5"}
switch {
case s.PatientSatisfaction >= 3.5:
sat.Conformant, sat.Severity, sat.Message = true, "ok", "Satisfaction des patients satisfaisante"
case s.PatientSatisfaction >= 3.0:
sat.Conformant, sat.Severity, sat.Message = false, "warning", "Satisfaction des patients insuffisante"
default:
sat.Conformant, sat.Severity, sat.Message = false, "critical", "Satisfaction des patients très mauvaise"
}
checks = append(checks, sat)
passing, critical, warning := 0, 0, 0
for _, c := range checks {
if c.Conformant {
passing++
}
switch c.Severity {
case "critical":
critical++
case "warning":
warning++
}
}
total := len(checks)
score := passing * 100 / total
return Analysis{
AnalyzedAt: time.Now().UTC(),
HospitalName: s.HospitalName,
StatsDate: s.Date,
Conformant: passing == total,
Score: score,
PassingChecks: passing,
TotalChecks: total,
CriticalAlerts: critical,
WarningAlerts: warning,
Checks: checks,
Summary: fmt.Sprintf(
"%d/%d indicateurs conformes (score: %d%%) — %d alerte(s) critique(s), %d avertissement(s)",
passing, total, score, critical, warning,
),
}
}
func main() {
for i := range []int{0, 1} {
data, err := os.ReadFile(strings.ReplaceAll(dataFile, "stats", "stats"+fmt.Sprintf("%v", i)))
if err != nil {
if os.IsNotExist(err) {
log.Fatalf("stats file not found at %s — run chu-stats-generator first", dataFile)
}
log.Fatalf("failed to read stats file: %v", err)
}
var stats CHUStats
if err := json.Unmarshal(data, &stats); err != nil {
log.Fatalf("failed to parse stats file: %v", err)
}
analysis := analyze(stats)
result, err := json.MarshalIndent(analysis, "", " ")
if err != nil {
log.Fatalf("failed to marshal analysis: %v", err)
}
log.Printf("Analysis complete: %s", analysis.Summary)
fmt.Println(string(result))
}
}

View File

@@ -0,0 +1,12 @@
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod .
COPY main.go .
RUN go build -o chu-statistics .
FROM alpine:latest
RUN apk --no-cache add ca-certificates tzdata
RUN mkdir -p /data
WORKDIR /app
COPY --from=builder /app/chu-statistics /usr/local/bin/chu-statistics
ENTRYPOINT ["chu-statistics"]

View File

@@ -0,0 +1,3 @@
module chu-stats-generator
go 1.22

View File

@@ -0,0 +1,96 @@
package main
import (
"encoding/json"
"fmt"
"log"
"math"
"math/rand"
"os"
"strings"
"time"
)
const dataFile = "/data/chu_stats.json"
type CHUStats struct {
GeneratedAt time.Time `json:"generated_at"`
HospitalName string `json:"hospital_name"`
Date string `json:"date"`
BedsTotal int `json:"beds_total"`
BedsOccupied int `json:"beds_occupied"`
OccupancyRate float64 `json:"occupancy_rate"`
PatientsAdmitted int `json:"patients_admitted"`
PatientsDischarge int `json:"patients_discharged"`
EmergencyVisits int `json:"emergency_visits"`
AvgERWaitMinutes int `json:"avg_er_wait_minutes"`
SurgeriesPerformed int `json:"surgeries_performed"`
ICUBeds int `json:"icu_beds"`
ICUOccupied int `json:"icu_occupied"`
MortalityRate float64 `json:"mortality_rate"`
InfectionRate float64 `json:"infection_rate"`
StaffPresent int `json:"staff_present"`
StaffRequired int `json:"staff_required"`
PatientSatisfaction float64 `json:"patient_satisfaction"`
}
func round2(v float64) float64 {
return math.Round(v*100) / 100
}
func generateStats() CHUStats {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
bedsTotal := 800 + rng.Intn(400)
occupancyPct := 0.65 + rng.Float64()*0.32
bedsOccupied := int(float64(bedsTotal) * occupancyPct)
icuBeds := 40 + rng.Intn(30)
icuOccupancyPct := 0.60 + rng.Float64()*0.38
icuOccupied := int(float64(icuBeds) * icuOccupancyPct)
staffRequired := 600 + rng.Intn(300)
staffCoverage := 0.65 + rng.Float64()*0.40
staffPresent := int(float64(staffRequired) * staffCoverage)
return CHUStats{
GeneratedAt: time.Now().UTC(),
HospitalName: "CHU Demo",
Date: time.Now().Format("2006-01-02"),
BedsTotal: bedsTotal,
BedsOccupied: bedsOccupied,
OccupancyRate: round2(occupancyPct * 100),
PatientsAdmitted: 50 + rng.Intn(120),
PatientsDischarge: 40 + rng.Intn(120),
EmergencyVisits: 80 + rng.Intn(150),
AvgERWaitMinutes: 15 + rng.Intn(130),
SurgeriesPerformed: 10 + rng.Intn(50),
ICUBeds: icuBeds,
ICUOccupied: icuOccupied,
MortalityRate: round2(0.3 + rng.Float64()*4.5),
InfectionRate: round2(0.5 + rng.Float64()*9.0),
StaffPresent: staffPresent,
StaffRequired: staffRequired,
PatientSatisfaction: round2(2.0 + rng.Float64()*3.0),
}
}
func main() {
for i, stats := range []CHUStats{generateStats(), generateStats()} {
data, err := json.MarshalIndent(stats, "", " ")
if err != nil {
log.Fatalf("failed to marshal stats: %v", err)
}
if err := os.MkdirAll("/data", 0755); err != nil {
log.Fatalf("failed to create data dir: %v", err)
}
if err := os.WriteFile(strings.ReplaceAll(dataFile, "stats", "stats"+fmt.Sprintf("%v", i)), data, 0644); err != nil {
log.Fatalf("failed to write stats file: %v", err)
}
log.Printf("Stats saved to %s", dataFile)
fmt.Println(string(data))
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[{"_id":"0b6a375f-be3e-49a9-9827-3c2d5eddb057","abstractobject":{"id":"0b6a375f-be3e-49a9-9827-3c2d5eddb057","name":"test","is_draft":false,"creator_id":"c0cece97-7730-4c2a-8c20-a30944564106","creation_date":{"$date":"2025-01-27T10:41:47.741Z"},"update_date":{"$date":"2025-01-27T10:41:47.741Z"},"updater_id":"c0cece97-7730-4c2a-8c20-a30944564106","access_mode":0},"description":"Proto Collaborative area example","collaborative_area":{},"workflows":["58314c99-c595-4ca2-8b5e-822a6774efed"],"allowed_peers_group":{"c0cece97-7730-4c2a-8c20-a30944564106":["*"]},"workspaces":[]}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[{"_id":"c0cece97-7730-4c2a-8c20-a30944564106","failed_execution":null,"abstractobject":{"update_date":{"$date":"2025-03-27T09:13:13.230Z"},"access_mode":0,"id":"c0cece97-7730-4c2a-8c20-a30944564106","name":"local","is_draft":false,"creation_date":{"$date":"2025-03-27T09:13:13.230Z"}},"url":"http://localhost:8000","wallet_address":"my-wallet","public_key":"-----BEGIN RSA PUBLIC KEY-----\nMIICCgKCAgEAw2pdG6wMtuLcP0+k1LFvIb0DQo/oHW2uNJaEJK74plXqp4ztz2dR\nb+RQHFLeLuqk4i/zc3b4K3fKPXSlwnVPJCwzPrnyT8jYGOZVlWlETiV9xeJhu6s/\nBh6g1PWz75XjjwV50iv/CEiLNBT23f/3J44wrQzygqNQCiQSALdxWLAEl4l5kHSa\n9oMyV70/Uql94/ayMARZsHgp9ZvqQKbkZPw6yzVMfCBxQozlNlo315OHevudhnhp\nDRjN5I7zWmqYt6rbXJJC7Y3Izdvzn7QI88RqjSRST5I/7Kz3ndCqrOnI+OQUE5NT\nREyQebphvQfTDTKlRPXkdyktdK2DH28Zj6ZF3yjQvN35Q4zhOzlq77dO5IhhopI7\nct8dZH1T1nYkvdyCA/EVMtQsASmBOitH0Y0ACoXQK5Kb6nm/TcM/9ZSJUNiEMuy5\ngBZ3YKE9oa4cpTpPXwcA+S/cU7HPNnQAsvD3iJi8GTW9uJs84pn4/WhpQqmXd4rv\nhKWECCN3fHy01fUs/U0PaSj2jDY/kQVeXoikNMzPUjdZd9m816TIBh3v3aVXCH/0\niTHHAxctvDgMRb2fpvRJ/wwnYjFG9RpamVFDMvC9NffuYzWAA9IRIY4cqgerfHrV\nZ2HHiPTDDvDAIsvImXZc/h7mXN6m3RCQ4Qywy993wd9gUdgg/qnynHcCAwEAAQ==\n-----END RSA PUBLIC KEY-----\n","state":1}]

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[{"_id":"04bc70b5-8d7b-44e6-9015-fadfa0fb102d","abstractinstanciatedresource":{"abstractresource":{"type":"storage","abstractobject":{"id":"04bc70b5-8d7b-44e6-9015-fadfa0fb102d","name":"IRT risk database","is_draft":false,"creator_id":"c0cece97-7730-4c2a-8c20-a30944564106","creation_date":"2021-09-30T14:00:00.000Z","update_date":"2021-09-30T14:00:00.000Z","updater_id":"c0cece97-7730-4c2a-8c20-a30944564106","access_mode":1},"logo":"https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/IRT risk database.png","description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.","short_description":"S3 compliant IRT file storage","owners":[{"name":"IRT"}]},"instances":[{"env":[{"attr":"source","readonly":true}],"resourceinstance":{"abstractobject":{"id":"7fdccb9c-7090-40a5-bacd-7435bc56c90d","name":"IRT local file storage Marseille"},"location":{"latitude":50.62925,"longitude":3.057256},"country":250,"partnerships":[{"resourcepartnership":{"namespace":"default","peer_groups":{"c0cece97-7730-4c2a-8c20-a30944564106":["*"]},"pricing_profiles":[{"pricing":{"price":50,"currency":"EUR","buying_strategy":0,"time_pricing_strategy":0}}]}}]},"source":"/mnt/vol","local":false,"security_level":"public","size":50,"size_type":3,"redundancy":"RAID5","throughput":"r:200,w:150"}]},"storage_type":5,"acronym":"DC_myDC"},{"_id":"e726020a-b68e-4abc-ab36-c3640ea3f557","abstractinstanciatedresource":{"abstractresource":{"type":"storage","abstractobject":{"id":"e726020a-b68e-4abc-ab36-c3640ea3f557","name":"IRT local file storage","is_draft":false,"creator_id":"c0cece97-7730-4c2a-8c20-a30944564106","creation_date":"2021-09-30T14:00:00.000Z","update_date":"2021-09-30T14:00:00.000Z","updater_id":"c0cece97-7730-4c2a-8c20-a30944564106","access_mode":1},"logo":"https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/IRT local file storage.png","description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.","short_description":"S3 compliant IRT file storage","owners":[{"name":"IRT"}]},"instances":[{"resourceinstance":{"env":[{"attr":"source","readonly":true}],"abstractobject":{"id":"7fdccb9c-7090-40a5-bacd-7435bc56c90d","name":"IRT local file storage Marseille"},"location":{"latitude":50.62925,"longitude":3.057256},"country":250,"partnerships":[{"resourcepartnership":{"namespace":"default","peer_groups":{"c0cece97-7730-4c2a-8c20-a30944564106":["*"]},"pricing_profiles":[{"pricing":{"price":50,"currency":"EUR","buying_strategy":0,"time_pricing_strategy":0}}]}}]},"source":"/mnt/vol","local":true,"security_level":"public","size":500,"size_type":0,"encryption":true,"redundancy":"RAID5S","throughput":"r:300,w:350"}]},"storage_type":5,"acronym":"DC_myDC"}]

File diff suppressed because one or more lines are too long

View File

@@ -12,8 +12,8 @@ docker network create oc | true
docker compose down docker compose down
cd ./tools && docker compose -f ./docker-compose.dev.yml up --force-recreate -d cd ./tools && docker compose -f ./docker-compose.dev.yml down --force-recreate -d && docker compose -f ./docker-compose.traefik.yml down --force-recreate -d
docker compose -f ./docker-compose.traefik.yml up --force-recreate -d && cd .. docker compose -f ./docker-compose.dev.yml up --force-recreate -d && docker compose -f ./docker-compose.traefik.yml up --force-recreate -d && cd ..
cd ./db && ./add.sh && cd .. cd ./db && ./add.sh && cd ..
@@ -39,6 +39,14 @@ do
docker kill $i | true docker kill $i | true
docker rm $i | true docker rm $i | true
cd ./$i cd ./$i
cat <<EOT >> ./env.env
KUBERNETES_SERVICE_HOST=$host
KUBE_CA="$ca"
KUBE_CERT="$cert"
KUBE_DATA="$key"
EOT
docker build . -t $i --build-arg=HOST=$HOST --build-arg=KUBERNETES_SERVICE_HOST=$host \ docker build . -t $i --build-arg=HOST=$HOST --build-arg=KUBERNETES_SERVICE_HOST=$host \
--build-arg=KUBERNETES_SERVICE_PORT=$port --build-arg=KUBE_CA=$ca --build-arg=KUBE_CERT=$cert \ --build-arg=KUBERNETES_SERVICE_PORT=$port --build-arg=KUBE_CA=$ca --build-arg=KUBE_CERT=$cert \
--build-arg=KUBE_DATA=$key && docker compose up -d --build-arg=KUBE_DATA=$key && docker compose up -d

View File

@@ -1,8 +1,8 @@
version: '3.4' version: '3.9'
services: services:
traefik: traefik:
image: traefik:v2.10.4 image: traefik:v3.6
container_name: traefik container_name: traefik
restart: unless-stopped restart: unless-stopped
networks: networks:
@@ -10,11 +10,13 @@ services:
command: command:
- "--api.insecure=true" - "--api.insecure=true"
- "--providers.docker=true" - "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:8000" - "--entrypoints.web.address=:8000"
user: root
ports: ports:
- "8000:8000" # Expose Traefik on port 8000 - "8000:8000" # Expose Traefik on port 8000
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
volumes: volumes:
oc-data: oc-data: