befund_test.go
| 1 | package befund |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestDelta(t *testing.T) { |
| 9 | cases := []struct{ a, b, want string }{ |
| 10 | {"0-0-120", "0-0-135", "+15"}, |
| 11 | {"5-0-110", "0-0-130", "-5 / +20"}, |
| 12 | {"3", "4", "+1"}, |
| 13 | {"4", "4", "±0"}, |
| 14 | {"12,5 s", "10 s", "-2,5"}, |
| 15 | {"4+", "5", "+1"}, |
| 16 | {"", "3", ""}, |
| 17 | {"elastisch", "fest", ""}, |
| 18 | } |
| 19 | for _, c := range cases { |
| 20 | if got := Delta(c.a, c.b); got != c.want { |
| 21 | t.Errorf("Delta(%q,%q) = %q, want %q", c.a, c.b, got, c.want) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestFromForm(t *testing.T) { |
| 27 | f := url.Values{ |
| 28 | "f.diag": {" Gonarthrose re "}, "f.rf_cancer": {"1"}, "f.pain_now": {"6"}, "f.unbekannt": {"x"}, |
| 29 | "t.rom.n": {"3"}, "t.rom.0.joint": {"Knie re"}, "t.rom.0.act": {"0-5-110"}, "t.rom.2.move": {"Ext"}, |
| 30 | "stamps": {`[{"v":0,"x":0.5,"y":0.3,"s":"pain","c":"#ff0000","z":2},{"v":9,"x":0.5,"y":0.5,"s":"pain"},{"v":1,"x":2,"y":0,"s":"pain"},{"v":1,"x":0.1,"y":0.1,"s":"bogus"}]`}, |
| 31 | } |
| 32 | d := FromForm(f) |
| 33 | if d.Get("diag") != "Gonarthrose re" || d.Get("rf_cancer") != "1" || d.Get("pain_now") != "6" { |
| 34 | t.Errorf("Felder: %+v", d.Fields) |
| 35 | } |
| 36 | if _, ok := d.Fields["unbekannt"]; ok { |
| 37 | t.Error("unbekanntes Feld übernommen") |
| 38 | } |
| 39 | if n := len(d.Tables["rom"]); n != 2 { |
| 40 | t.Errorf("ROM-Zeilen %d, erwartet 2 (leere Zeile verworfen)", n) |
| 41 | } |
| 42 | if len(d.Stamps) != 1 { |
| 43 | t.Errorf("Stempel %d, erwartet 1 gültigen", len(d.Stamps)) |
| 44 | } |
| 45 | if !d.HasSection(Sections[1]) { // Screening |
| 46 | t.Error("Screening-Sektion sollte Daten haben") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Datei im Format der alten Befundseite |
| 51 | const legacy = `{ |
| 52 | "name": "Erika Muster", "diag": "Z. n. VKB-Plastik re", "date": "2025-10-01", "dob": "1990", |
| 53 | "S/I": "mittel", "24h": "morgens steif", "im_payr": true, "im_homann": false, |
| 54 | "custom-ab12cd": "Eigener Abschnitt", |
| 55 | "rom": [{"joint":"Knie re","move":"Flex/Ext","act":"0-5-100","pass":"0-0-110","end":"fest"}, {"joint":"","move":"","act":"","pass":"","end":""}], |
| 56 | "mfp": [{"muscle":"Quadrizeps","right":"4","left":"5"}], |
| 57 | "circ": [], "timeline": [{"date":"2025-08-01","title":"OP","note":"VKB"}], |
| 58 | "treat": [{"date":"2025-10-02","goal":"Extension","note":"gut"}, {"date":"","goal":"","note":""}], |
| 59 | "blocks": {}, "fields": {}, "order": [], "_v": 2 |
| 60 | }` |
| 61 | |
| 62 | func TestParseLegacy(t *testing.T) { |
| 63 | l, err := ParseLegacy([]byte(legacy)) |
| 64 | if err != nil { |
| 65 | t.Fatal(err) |
| 66 | } |
| 67 | if l.Name != "Erika Muster" || l.Date != "2025-10-01" || l.Dob != "1990" { |
| 68 | t.Errorf("Kopf: %+v", l) |
| 69 | } |
| 70 | d := l.Data |
| 71 | if d.Get("diag") == "" || d.Get("S/I") != "mittel" || d.Get("24h") == "" || d.Get("im_payr") != "1" || d.Get("im_homann") != "" { |
| 72 | t.Errorf("Felder: %v", d.Fields) |
| 73 | } |
| 74 | if d.Get("zusatz") != "Eigener Abschnitt" { |
| 75 | t.Errorf("Zusatzabschnitt: %q", d.Get("zusatz")) |
| 76 | } |
| 77 | if len(d.Tables["rom"]) != 1 || len(d.Tables["mfp"]) != 1 || len(d.Tables["timeline"]) != 1 { |
| 78 | t.Errorf("Tabellen: %v", d.Tables) |
| 79 | } |
| 80 | if len(l.Sessions) != 1 { |
| 81 | t.Errorf("Behandlungen: %d", len(l.Sessions)) |
| 82 | } |
| 83 | if _, err := ParseLegacy([]byte(`{"foo":1}`)); err == nil { |
| 84 | t.Error("fremde JSON-Datei akzeptiert") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestCompare(t *testing.T) { |
| 89 | a, b := New(), New() |
| 90 | a.Fields["pain_now"], b.Fields["pain_now"] = "7", "3" |
| 91 | a.Fields["diag"], b.Fields["diag"] = "X", "X" |
| 92 | a.Tables["rom"] = []Row{{"joint": "Knie", "move": "Flex", "act": "0-0-100"}} |
| 93 | b.Tables["rom"] = []Row{{"joint": "Knie", "move": "Flex", "act": "0-0-125"}, {"joint": "Hüfte", "move": "Flex", "act": "0-0-120"}} |
| 94 | b.Tables["psfs"] = []Row{{"activity": "Treppe", "score": "6"}} |
| 95 | fields, tables := Compare(a, b) |
| 96 | if len(fields) != 1 || fields[0].A != "7" || fields[0].B != "3" { |
| 97 | t.Errorf("Felder: %+v", fields) |
| 98 | } |
| 99 | if len(tables) != 2 || tables[0].Rows[0].Cells[0].Delta != "+25" || len(tables[0].Rows) != 2 { |
| 100 | t.Errorf("Tabellen: %+v", tables) |
| 101 | } |
| 102 | if PSFSMean(b) != "6,0" { |
| 103 | t.Errorf("PSFS: %q", PSFSMean(b)) |
| 104 | } |
| 105 | } |
| 106 |