-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel-to-fhir.test.ts
89 lines (78 loc) · 2.12 KB
/
excel-to-fhir.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
assertEquals,
assertThrows,
} from "https://deno.land/[email protected]/assert/mod.ts";
import { convertJSONToFHIR, convertSheetsToJSON } from "./excel-to-fhir.ts";
/**
* Test convertSheetsToJSON
*/
Deno.test("convertSheetsToJSON test valid sheets", () => {
const filePath = "testdata/example.xlsx";
const sheetNames = ["property", "unit"];
const expected = {
property: [
{
game_property: "STEPS",
LOINC_code: 100,
LOINC_display: "Steps_L",
LOINC_equivalence: "equivalent",
SNOMED_code: 100,
SNOMED_display: "Steps_S",
SNOMED_equivalence: "equivalent",
},
{
game_property: "DISTANCE",
LOINC_code: "L002",
LOINC_display: "Distance_L",
LOINC_equivalence: "equivalent",
SNOMED_code: "S002",
SNOMED_display: "Distance_S",
SNOMED_equivalence: "equivalent",
},
],
unit: [
{
unit: "meters",
UCUM_code: "m",
UCUM_display: "meter",
UCUM_equivalence: "equal",
},
{
unit: "seconds",
UCUM_code: "s",
UCUM_display: "second",
UCUM_equivalence: "equivalent",
},
],
};
const result = convertSheetsToJSON(filePath, sheetNames);
assertEquals(result, expected);
});
Deno.test("convertSheetsToJSON test non-existent sheets", () => {
const filePath = "testdata/example.xlsx";
const sheetNames = ["sheet1"];
assertThrows(
() => convertSheetsToJSON(filePath, sheetNames),
Error,
"Sheet sheet1 not found",
);
});
/**
* Test convertJSONToFHIR
*/
Deno.test("convertJSONToFHIR test valid input", async () => {
const data = {
people: [{ name: "John", age: 30 }],
};
const jsonataExpression = "people.name";
const expected = "John";
const result = await convertJSONToFHIR(data, jsonataExpression);
assertEquals(result, expected);
});
Deno.test("convertJSONToFHIR test empty input", async () => {
const data = {};
const jsonataExpression = "people.name";
const expected = undefined;
const result = await convertJSONToFHIR(data, jsonataExpression);
assertEquals(result, expected);
});