|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { makeClient } from "src/client.js"; |
| 3 | +// import type { Bundle, OperationOutcome } from "src/fhir-types/hl7-fhir-r4-core"; |
| 4 | +// import type { User, ResourceResponse } from "src/types"; |
| 5 | +// import type { Result } from "src/result"; |
| 6 | + |
| 7 | +const client = makeClient({ baseurl: "http://localhost:8080" }); |
| 8 | +const patientId = "test-id"; |
| 9 | + |
| 10 | +describe("Type Level Interaction", () => { |
| 11 | + describe("create", () => { |
| 12 | + it("should create a Patient", async () => { |
| 13 | + const result = await client.create({ |
| 14 | + type: "Patient", |
| 15 | + resource: { |
| 16 | + id: `pt-${patientId}`, |
| 17 | + } |
| 18 | + }); |
| 19 | + expect(result.isOk()).toBe(true); |
| 20 | + if (result.isOk()) |
| 21 | + expect(result.value.resource).toMatchObject({ |
| 22 | + id: `pt-${patientId}`, |
| 23 | + resourceType: "Patient", |
| 24 | + }); |
| 25 | + }); |
| 26 | + }); |
| 27 | + describe("conditionalCreate", () => { |
| 28 | + it("should create new Patient", async () => { |
| 29 | + const result = await client.conditionalCreate({ |
| 30 | + type: "Patient", |
| 31 | + searchParameters: [["given", "John"]], |
| 32 | + resource: { |
| 33 | + resourceType: "Patient", |
| 34 | + name: [{ |
| 35 | + family: "Doe", |
| 36 | + given: ["John"] |
| 37 | + }], |
| 38 | + } |
| 39 | + }); |
| 40 | + expect(result.isOk()).toBe(true); |
| 41 | + if (result.isOk()) |
| 42 | + expect(result.value.resource).toMatchObject({ |
| 43 | + resourceType: "Patient", |
| 44 | + }); |
| 45 | + }); |
| 46 | + it("should not create a new Patient", async () => { |
| 47 | + const result = await client.conditionalCreate({ |
| 48 | + type: "Patient", |
| 49 | + searchParameters: [["family", "Doe"]], |
| 50 | + resource: { |
| 51 | + resourceType: "Patient", |
| 52 | + name: [{ |
| 53 | + family: "Smith", |
| 54 | + given: ["John"] |
| 55 | + }], |
| 56 | + } |
| 57 | + }); |
| 58 | + expect(result.isOk()).toBe(true); |
| 59 | + if (result.isOk()) |
| 60 | + expect(result.value.resource).toMatchObject({ |
| 61 | + resourceType: "Patient", |
| 62 | + name: [{ |
| 63 | + family: "Doe", |
| 64 | + given: ["John"] |
| 65 | + }], |
| 66 | + }); |
| 67 | + }); |
| 68 | + }); |
| 69 | + describe("search", () => { |
| 70 | + it("should find a Patient", async () => { |
| 71 | + const result = await client.search({query: [["family", "Doe"]], type: "Patient"}); |
| 72 | + expect(result.isOk()).toBe(true); |
| 73 | + if (result.isOk()) |
| 74 | + expect(result.value.resource).toMatchObject({ |
| 75 | + resourceType: "Bundle", |
| 76 | + entry: [{ |
| 77 | + resource: { |
| 78 | + name: [{ |
| 79 | + family: "Doe", |
| 80 | + given: [ |
| 81 | + "John", |
| 82 | + ], |
| 83 | + }], |
| 84 | + resourceType: "Patient", |
| 85 | + }, |
| 86 | + search: { |
| 87 | + mode: "match", |
| 88 | + }, |
| 89 | + }], |
| 90 | + }); |
| 91 | + }); |
| 92 | + it("should not find a Patient", async () => { |
| 93 | + const result = await client.search({query: [["family", "Smith"]], type: "Patient"}); |
| 94 | + expect(result.isOk()).toBe(true); |
| 95 | + if (result.isOk()) |
| 96 | + expect(result.value.resource).toMatchObject({ |
| 97 | + resourceType: "Bundle", |
| 98 | + total: 0, |
| 99 | + type: "searchset", |
| 100 | + }); |
| 101 | + }); |
| 102 | + }); |
| 103 | + describe("conditionalDelete", () => { |
| 104 | + it("should delete a Patient", async () => { |
| 105 | + const result = await client.conditionalDelete({ |
| 106 | + type: "Patient", |
| 107 | + searchParameters: [["family", "Doe"]], |
| 108 | + }); |
| 109 | + expect(result.isOk()).toBe(true); |
| 110 | + if (result.isOk()) |
| 111 | + expect(result.value.resource).toMatchObject({ |
| 112 | + name: [{ |
| 113 | + family: "Doe", |
| 114 | + given: [ |
| 115 | + "John", |
| 116 | + ], |
| 117 | + }], |
| 118 | + resourceType: "Patient", |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | + describe("history", () => { |
| 123 | + it("should retrieve type-level history", async () => { |
| 124 | + const result = await client.history({type: "Patient"}); |
| 125 | + expect(result.isOk()).toBe(true); |
| 126 | + if (result.isOk()) |
| 127 | + expect(result.value.resource).toMatchObject({ |
| 128 | + resourceType: "Bundle", |
| 129 | + type: "history", |
| 130 | + }); |
| 131 | + }); |
| 132 | + }); |
| 133 | +}); |
| 134 | + |
| 135 | +describe("Instance Level Interaction", () => { |
| 136 | + describe("read", () => { |
| 137 | + it("should read Patient", async () => { |
| 138 | + const result = await client.read({type: "Patient", id: `pt-${patientId}`}); |
| 139 | + expect(result.isOk()).toBe(true); |
| 140 | + if (result.isOk()) |
| 141 | + expect(result.value.resource).toMatchObject({ |
| 142 | + id: `pt-${patientId}`, |
| 143 | + resourceType: "Patient", |
| 144 | + }); |
| 145 | + }) |
| 146 | + }); |
| 147 | + // describe("vread", () => { |
| 148 | + // it("should", async () => { const result = await client.vread(); }); |
| 149 | + // }); |
| 150 | + // describe("update", () => { |
| 151 | + // it("should", async () => { const result = await client.update(); }); |
| 152 | + // }); |
| 153 | + // describe("conditionalUpdate", () => { |
| 154 | + // it("should", async () => { const result = await client.conditionalUpdate(); }); |
| 155 | + // }); |
| 156 | + // describe("patch", () => { |
| 157 | + // it("should", async () => { const result = await client.patch(); }); |
| 158 | + // }); |
| 159 | + // describe("conditionalPatch", () => { |
| 160 | + // it("should", async () => { const result = await client.conditionalPatch(); }); |
| 161 | + // }); |
| 162 | + // describe("delete", () => { |
| 163 | + // it("should", async () => { const result = await client.delete(); }); |
| 164 | + // }); |
| 165 | + // describe("deleteHistory", () => { |
| 166 | + // it("should", async () => { const result = await client.deleteHistory(); }); |
| 167 | + // }); |
| 168 | + // describe("deleteHistoryVersion", () => { |
| 169 | + // it("should", async () => { const result = await client.deleteHistoryVersion(); }); |
| 170 | + // }); |
| 171 | + // describe("history", () => { |
| 172 | + // it("should", async () => { const result = await client.history(); }); |
| 173 | + // }); |
| 174 | +}); |
| 175 | + |
| 176 | +// describe("Whole System Interaction", () => { |
| 177 | +// describe("capabilities", () => { |
| 178 | +// it("should", async () => { const result = await client.capabilities(); }); |
| 179 | +// }); |
| 180 | +// describe("batch", () => { |
| 181 | +// it("should", async () => { const result = await client.batch(); }); |
| 182 | +// }); |
| 183 | +// describe("delete", () => { |
| 184 | +// it("should", async () => { const result = await client.delete(); }); |
| 185 | +// }); |
| 186 | +// describe("history", () => { |
| 187 | +// it("should", async () => { const result = await client.history(); }); |
| 188 | +// }); |
| 189 | +// describe("search", () => { |
| 190 | +// it("should", async () => { const result = await client.search(); }); |
| 191 | +// }); |
| 192 | +// }) |
| 193 | + |
| 194 | +// describe("Compartment Interaction", () => { |
| 195 | +// describe("search", () => { |
| 196 | +// it("should", async () => { const result = await client.search(); }); |
| 197 | +// }); |
| 198 | +// }); |
0 commit comments