Skip to content

Commit 9e03d8f

Browse files
committed
Refactor: Excel to config model parser tooling
1 parent 9c984ed commit 9e03d8f

12 files changed

Lines changed: 2163 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ dist
2626

2727
.env
2828
/.envrc
29+
/specifications.xlsx
30+
~*

package-lock.json

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/excel-parser/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Excel Parser
2+
3+
A package for parsing and generating Excel files for NHS Notify supplier configuration data.
4+
5+
## Features
6+
7+
- Parse Excel files containing supplier configuration data (PackSpecification, LetterVariant, VolumeGroup, Supplier, SupplierAllocation, SupplierPack)
8+
- Generate template Excel files with the correct sheet structure and headers
9+
- Validate parsed data against Zod schemas
10+
11+
## Usage
12+
13+
### Parsing an Excel file
14+
15+
```typescript
16+
import { parseExcelFile } from "@nhs-notify/excel-parser";
17+
18+
const result = parseExcelFile("./specifications.xlsx");
19+
20+
console.log(result.packs); // Record<string, PackSpecification>
21+
console.log(result.variants); // Record<string, LetterVariant>
22+
console.log(result.volumeGroups); // Record<string, VolumeGroup>
23+
console.log(result.suppliers); // Record<string, Supplier>
24+
console.log(result.allocations); // Record<string, SupplierAllocation>
25+
console.log(result.supplierPacks); // Record<string, SupplierPack>
26+
```
27+
28+
### Generating a template Excel file
29+
30+
```typescript
31+
import { generateTemplateExcel } from "@nhs-notify/excel-parser";
32+
33+
// Generate a new template (fails if file exists)
34+
generateTemplateExcel("./specifications.template.xlsx");
35+
36+
// Force overwrite existing file
37+
generateTemplateExcel("./specifications.template.xlsx", true);
38+
```
39+
40+
## Required Excel Sheets
41+
42+
The Excel file must contain the following sheets:
43+
44+
1. **PackSpecification** - Pack specification definitions
45+
2. **LetterVariant** - Letter variant configurations
46+
3. **VolumeGroup** - Volume group definitions
47+
4. **Supplier** - Supplier information
48+
5. **SupplierAllocation** - Supplier allocation percentages per volume group
49+
6. **SupplierPack** - Mapping of suppliers to pack specifications
50+
51+
See `EXCEL_HEADERS.md` for detailed column specifications.
15.7 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
moduleNameMapper: {
5+
"^@supplier-config/excel-parser/(.*)$": "<rootDir>/src/$1",
6+
},
7+
preset: "ts-jest",
8+
testEnvironment: "node",
9+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
10+
transform: {
11+
"^.+\\.tsx?$": [
12+
"@swc/jest",
13+
{
14+
jsc: {
15+
parser: {
16+
syntax: "typescript",
17+
tsx: false,
18+
},
19+
target: "es2022",
20+
},
21+
},
22+
],
23+
},
24+
};
25+
26+
export default config;

packages/excel-parser/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"dependencies": {
3+
"@nhsdigital/nhs-notify-event-schemas-supplier-config": "*",
4+
"xlsx": "^0.18.5",
5+
"zod": "^4.1.12"
6+
},
7+
"devDependencies": {
8+
"@swc/core": "^1.11.13",
9+
"@swc/jest": "^0.2.37",
10+
"@tsconfig/node22": "^22.0.2",
11+
"@types/jest": "^29.5.14",
12+
"@types/xlsx": "^0.0.35",
13+
"jest": "^29.7.0",
14+
"jest-mock-extended": "^3.0.7",
15+
"typescript": "^5.9.3"
16+
},
17+
"name": "@supplier-config/excel-parser",
18+
"private": true,
19+
"scripts": {
20+
"build": "tsc",
21+
"lint": "eslint .",
22+
"lint:fix": "eslint . --fix",
23+
"test": "jest",
24+
"test:unit": "jest",
25+
"typecheck": "tsc --noEmit"
26+
},
27+
"version": "0.0.1"
28+
}

0 commit comments

Comments
 (0)