@atomic-ehr/fhir-canonical-manager 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cache.d.ts +2 -0
  2. package/dist/cache.d.ts.map +1 -1
  3. package/dist/cache.js +27 -2
  4. package/dist/cache.js.map +1 -1
  5. package/dist/local.d.ts +5 -0
  6. package/dist/local.d.ts.map +1 -0
  7. package/dist/local.js +148 -0
  8. package/dist/local.js.map +1 -0
  9. package/dist/manager/canonical.d.ts.map +1 -1
  10. package/dist/manager/canonical.js +205 -24
  11. package/dist/manager/canonical.js.map +1 -1
  12. package/dist/manager/package-spec.d.ts +5 -0
  13. package/dist/manager/package-spec.d.ts.map +1 -0
  14. package/dist/manager/package-spec.js +28 -0
  15. package/dist/manager/package-spec.js.map +1 -0
  16. package/dist/package.d.ts.map +1 -1
  17. package/dist/package.js +25 -5
  18. package/dist/package.js.map +1 -1
  19. package/dist/scanner/parser.d.ts.map +1 -1
  20. package/dist/scanner/parser.js +2 -2
  21. package/dist/scanner/parser.js.map +1 -1
  22. package/dist/types/core.d.ts +12 -0
  23. package/dist/types/core.d.ts.map +1 -1
  24. package/dist/types/internal.d.ts +4 -2
  25. package/dist/types/internal.d.ts.map +1 -1
  26. package/package.json +2 -3
  27. package/src/cache.ts +0 -59
  28. package/src/cli/index.ts +0 -181
  29. package/src/cli/init.ts +0 -112
  30. package/src/cli/list.ts +0 -95
  31. package/src/cli/resolve.ts +0 -63
  32. package/src/cli/search.ts +0 -83
  33. package/src/cli/searchparam.ts +0 -163
  34. package/src/constants.ts +0 -6
  35. package/src/fs/index.ts +0 -5
  36. package/src/fs/utils.ts +0 -28
  37. package/src/index.ts +0 -18
  38. package/src/manager/canonical.ts +0 -359
  39. package/src/manager/index.ts +0 -6
  40. package/src/package.ts +0 -79
  41. package/src/reference.ts +0 -77
  42. package/src/resolver.ts +0 -38
  43. package/src/scanner/directory.ts +0 -36
  44. package/src/scanner/index.ts +0 -8
  45. package/src/scanner/package.ts +0 -35
  46. package/src/scanner/parser.ts +0 -40
  47. package/src/scanner/processor.ts +0 -65
  48. package/src/search/index.ts +0 -6
  49. package/src/search/smart.ts +0 -50
  50. package/src/search/terms.ts +0 -22
  51. package/src/types/core.ts +0 -131
  52. package/src/types/index.ts +0 -6
  53. package/src/types/internal.ts +0 -59
package/src/cli/list.ts DELETED
@@ -1,95 +0,0 @@
1
- import { CanonicalManager } from "../index.js";
2
- import { getConfigFromPackageJson, loadPackageJson, parseArgs } from "./index.js";
3
-
4
- export async function listCommand(args: string[]): Promise<void> {
5
- const { positional, options } = parseArgs(args);
6
- const packageName = positional[0];
7
- const isJson = options.json === true;
8
- const typeFilter = options.type as string | undefined;
9
-
10
- // Load config from package.json
11
- const packageJson = await loadPackageJson();
12
- if (!packageJson?.fcm?.packages || packageJson.fcm.packages.length === 0) {
13
- console.error("Error: No FHIR packages configured");
14
- console.error("Run 'fcm init' first to initialize packages");
15
- if (process.env.NODE_ENV === "test") {
16
- throw new Error("No FHIR packages configured");
17
- }
18
- process.exit(1);
19
- }
20
-
21
- const config = getConfigFromPackageJson(packageJson);
22
- const manager = CanonicalManager(config as any);
23
- await manager.init();
24
-
25
- try {
26
- if (!packageName) {
27
- // List all packages
28
- const packages = await manager.packages();
29
-
30
- if (isJson) {
31
- console.log(JSON.stringify(packages, null, 2));
32
- } else {
33
- console.log("Packages:");
34
- packages.forEach((pkg) => {
35
- console.log(` ${pkg.name}@${pkg.version}`);
36
- });
37
- }
38
- } else {
39
- // List resources in a specific package
40
- const packages = await manager.packages();
41
- const pkg = packages.find((p) => p.name === packageName);
42
-
43
- if (!pkg) {
44
- console.error(`Error: Package '${packageName}' not found`);
45
- console.error("Available packages:");
46
- packages.forEach((p) => {
47
- console.error(` - ${p.name}`);
48
- });
49
- if (process.env.NODE_ENV === "test") {
50
- throw new Error(`Package '${packageName}' not found`);
51
- }
52
- process.exit(1);
53
- }
54
-
55
- let resources = await manager.searchEntries({ package: pkg });
56
-
57
- // Apply type filter if specified
58
- if (typeFilter) {
59
- resources = resources.filter((r) => r.resourceType === typeFilter);
60
- }
61
-
62
- if (isJson) {
63
- console.log(JSON.stringify(resources, null, 2));
64
- } else {
65
- console.log(`Resources in ${packageName}:`);
66
-
67
- if (resources.length === 0) {
68
- console.log(" No resources found");
69
- } else {
70
- // Group by type
71
- const byType = resources.reduce(
72
- (acc, resource) => {
73
- const type = resource.resourceType || resource.type || "Unknown";
74
- if (!acc[type]) acc[type] = 0;
75
- acc[type]++;
76
- return acc;
77
- },
78
- {} as Record<string, number>,
79
- );
80
-
81
- // Show summary
82
- Object.entries(byType)
83
- .sort()
84
- .forEach(([type, count]) => {
85
- console.log(` ${type}: ${count}`);
86
- });
87
-
88
- console.log(`\nTotal: ${resources.length} resources`);
89
- }
90
- }
91
- }
92
- } finally {
93
- await manager.destroy();
94
- }
95
- }
@@ -1,63 +0,0 @@
1
- import { CanonicalManager } from "../index.js";
2
- import { getConfigFromPackageJson, loadPackageJson, parseArgs } from "./index.js";
3
-
4
- export async function resolveCommand(args: string[]): Promise<void> {
5
- const { positional, options } = parseArgs(args);
6
- const url = positional[0];
7
- const fields = options.fields as string | undefined;
8
-
9
- if (!url) {
10
- console.error("Error: Canonical URL required");
11
- console.error("Usage: fcm resolve <canonical-url> [--fields field1,field2]");
12
- console.error("Example: fcm resolve http://hl7.org/fhir/StructureDefinition/Patient");
13
- if (process.env.NODE_ENV === "test") {
14
- throw new Error("Canonical URL required");
15
- }
16
- process.exit(1);
17
- }
18
-
19
- // Load config from package.json
20
- const packageJson = await loadPackageJson();
21
- if (!packageJson?.fcm?.packages || packageJson.fcm.packages.length === 0) {
22
- console.error("Error: No FHIR packages configured");
23
- console.error("Run 'fcm init' first to initialize packages");
24
- if (process.env.NODE_ENV === "test") {
25
- throw new Error("No FHIR packages configured");
26
- }
27
- process.exit(1);
28
- }
29
-
30
- const config = getConfigFromPackageJson(packageJson);
31
- const manager = CanonicalManager(config as any);
32
- await manager.init();
33
-
34
- try {
35
- // Resolve the resource
36
- const resource = await manager.resolve(url);
37
-
38
- if (fields) {
39
- // Extract only specified fields
40
- const fieldList = fields.split(",").map((f) => f.trim());
41
- const filtered: any = {};
42
-
43
- fieldList.forEach((field) => {
44
- if (field in resource) {
45
- filtered[field] = resource[field];
46
- }
47
- });
48
-
49
- console.log(JSON.stringify(filtered, null, 2));
50
- } else {
51
- // Output full resource
52
- console.log(JSON.stringify(resource, null, 2));
53
- }
54
- } catch (error) {
55
- console.error(`Error: Resource not found: ${url}`);
56
- if (process.env.NODE_ENV === "test") {
57
- throw error;
58
- }
59
- process.exit(1);
60
- } finally {
61
- await manager.destroy();
62
- }
63
- }
package/src/cli/search.ts DELETED
@@ -1,83 +0,0 @@
1
- import { CanonicalManager } from "../index.js";
2
- import { getConfigFromPackageJson, loadPackageJson, parseArgs } from "./index.js";
3
-
4
- export async function searchCommand(args: string[]): Promise<void> {
5
- const { positional, options } = parseArgs(args);
6
- const searchTerms = positional; // Now support multiple search terms
7
- const isJson = options.json === true;
8
- const resourceTypeFilter = (options.type || options.resourceType) as string | undefined;
9
- const typeFilter = options.t as string | undefined;
10
- const kindFilter = options.k as string | undefined;
11
- const packageFilter = options.package as string | undefined;
12
-
13
- // Load config from package.json
14
- const packageJson = await loadPackageJson();
15
- if (!packageJson?.fcm?.packages || packageJson.fcm.packages.length === 0) {
16
- console.error("Error: No FHIR packages configured");
17
- console.error("Run 'fcm init' first to initialize packages");
18
- if (process.env.NODE_ENV === "test" || process.env.BUN_TEST) {
19
- throw new Error("No FHIR packages configured");
20
- }
21
- process.exit(1);
22
- }
23
-
24
- const config = getConfigFromPackageJson(packageJson);
25
- const manager = CanonicalManager(config as any);
26
- await manager.init();
27
-
28
- try {
29
- // Build filters for smart search
30
- const filters: any = {};
31
-
32
- if (resourceTypeFilter) {
33
- filters.resourceType = resourceTypeFilter;
34
- }
35
-
36
- if (typeFilter) {
37
- filters.type = typeFilter;
38
- }
39
-
40
- if (kindFilter) {
41
- filters.kind = kindFilter;
42
- }
43
-
44
- if (packageFilter) {
45
- const packages = await manager.packages();
46
- const pkg = packages.find((p) => p.name === packageFilter);
47
- if (!pkg) {
48
- console.error(`Error: Package '${packageFilter}' not found`);
49
- if (process.env.NODE_ENV === "test" || process.env.BUN_TEST) {
50
- throw new Error(`Package '${packageFilter}' not found`);
51
- }
52
- process.exit(1);
53
- }
54
- filters.package = pkg;
55
- }
56
-
57
- // Use the new smartSearch from core
58
- const results = await manager.smartSearch(searchTerms, filters);
59
-
60
- if (isJson) {
61
- console.log(JSON.stringify(results, null, 2));
62
- } else {
63
- if (results.length === 0) {
64
- console.log("No resources found");
65
- } else {
66
- const searchInfo = searchTerms.length > 0 ? ` matching "${searchTerms.join(" ")}"` : "";
67
- console.log(`Found ${results.length} resource${results.length === 1 ? "" : "s"}${searchInfo}:`);
68
-
69
- results.forEach((resource) => {
70
- const info = {
71
- resourceType: resource.resourceType,
72
- kind: resource.kind,
73
- type: resource.type,
74
- package: resource.package?.name,
75
- };
76
- console.log(`${resource.url}, ${JSON.stringify(info)}`);
77
- });
78
- }
79
- }
80
- } finally {
81
- await manager.destroy();
82
- }
83
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * Search parameters command - displays search parameters for a resource type
3
- */
4
-
5
- import { CanonicalManager } from "../index.js";
6
- import type { SearchParameter } from "../types/index.js";
7
- import { getConfigFromPackageJson, loadPackageJson, parseArgs } from "./index.js";
8
-
9
- export async function searchParamCommand(args: string[]): Promise<void> {
10
- const { positional, options } = parseArgs(args);
11
-
12
- if (options.help || positional.length === 0) {
13
- console.log(`
14
- Usage: fcm searchparam <resourceType> [options]
15
-
16
- Display search parameters for a specific FHIR resource type
17
-
18
- Arguments:
19
- resourceType The FHIR resource type (e.g., Patient, Observation)
20
-
21
- Options:
22
- --format Output format: table (default), json, csv
23
- --help Show this help message
24
-
25
- Examples:
26
- fcm searchparam Patient
27
- fcm searchparam Observation --format json
28
- fcm searchparam Encounter --format csv
29
- `);
30
- return;
31
- }
32
-
33
- const resourceType = positional[0];
34
- if (!resourceType) {
35
- console.error("Error: Resource type is required");
36
- process.exit(1);
37
- }
38
- const format = (options.format as string) || "table";
39
-
40
- // Load config from package.json
41
- const packageJson = await loadPackageJson();
42
- if (!packageJson) {
43
- throw new Error("No package.json found. Run 'fcm init' to initialize a project.");
44
- }
45
-
46
- const config = getConfigFromPackageJson(packageJson);
47
- const manager = CanonicalManager({
48
- packages: config.packages || [],
49
- registry: config.registry,
50
- workingDir: config.workingDir || process.cwd(),
51
- });
52
-
53
- await manager.init();
54
-
55
- try {
56
- const searchParams = await manager.getSearchParametersForResource(resourceType);
57
-
58
- if (searchParams.length === 0) {
59
- console.log(`No search parameters found for resource type '${resourceType}'`);
60
- return;
61
- }
62
-
63
- // Format output based on requested format
64
- switch (format) {
65
- case "json":
66
- outputJson(searchParams);
67
- break;
68
- case "csv":
69
- outputCsv(searchParams);
70
- break;
71
- default:
72
- outputTable(searchParams);
73
- break;
74
- }
75
- } finally {
76
- await manager.destroy();
77
- }
78
- }
79
-
80
- function outputTable(searchParams: SearchParameter[]): void {
81
- console.log("");
82
-
83
- // Display each parameter as a multiline block
84
- for (const param of searchParams) {
85
- const code = param.code || "";
86
- const type = param.type || "";
87
- const expression = param.expression || "";
88
- const url = param.url || "";
89
-
90
- console.log(`Code: ${code}`);
91
- console.log(`Type: ${type}`);
92
- if (expression) {
93
- // Wrap long expressions
94
- if (expression.length > 60) {
95
- console.log(`Expression: ${wrapText(expression, 60, " ")}`);
96
- } else {
97
- console.log(`Expression: ${expression}`);
98
- }
99
- } else {
100
- console.log(`Expression: (none)`);
101
- }
102
- console.log(`URL: ${url}`);
103
- console.log("---");
104
- }
105
-
106
- console.log(`Total: ${searchParams.length} search parameters`);
107
- }
108
-
109
- // Helper function to wrap text at specified width
110
- function wrapText(text: string, width: number, indent: string): string {
111
- const words = text.split(" ");
112
- const lines: string[] = [];
113
- let currentLine = "";
114
-
115
- for (const word of words) {
116
- if (currentLine.length + word.length + 1 <= width) {
117
- currentLine += (currentLine ? " " : "") + word;
118
- } else {
119
- if (currentLine) {
120
- lines.push(currentLine);
121
- }
122
- currentLine = word;
123
- }
124
- }
125
-
126
- if (currentLine) {
127
- lines.push(currentLine);
128
- }
129
-
130
- return lines.join(`\n${indent}`);
131
- }
132
-
133
- function outputJson(searchParams: SearchParameter[]): void {
134
- const output = searchParams.map((param) => ({
135
- code: param.code,
136
- type: param.type,
137
- expression: param.expression || null,
138
- url: param.url,
139
- }));
140
- console.log(JSON.stringify(output, null, 2));
141
- }
142
-
143
- function outputCsv(searchParams: SearchParameter[]): void {
144
- // CSV header
145
- console.log("Code,Type,Expression,URL");
146
-
147
- // CSV rows - no truncation for CSV output
148
- for (const param of searchParams) {
149
- const code = escapeCsv(param.code || "");
150
- const type = escapeCsv(param.type || "");
151
- const expression = escapeCsv(param.expression || "");
152
- const url = escapeCsv(param.url || "");
153
- console.log(`${code},${type},${expression},${url}`);
154
- }
155
- }
156
-
157
- function escapeCsv(value: string): string {
158
- // Escape CSV values that contain commas, quotes, or newlines
159
- if (value.includes(",") || value.includes('"') || value.includes("\n")) {
160
- return `"${value.replace(/"/g, '""')}"`;
161
- }
162
- return value;
163
- }
package/src/constants.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Shared constants for FHIR Canonical Manager
3
- */
4
-
5
- // Default FHIR package registry
6
- export const DEFAULT_REGISTRY = "https://fs.get-ig.org/pkgs/";
package/src/fs/index.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * File system utilities exports
3
- */
4
-
5
- export { ensureDir, fileExists, isFhirPackage } from "./utils.js";
package/src/fs/utils.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * File system utility functions
3
- */
4
-
5
- import * as fs from "node:fs/promises";
6
- import * as path from "node:path";
7
-
8
- export const fileExists = async (filePath: string): Promise<boolean> => {
9
- try {
10
- await fs.access(filePath);
11
- return true;
12
- } catch {
13
- return false;
14
- }
15
- };
16
-
17
- export const ensureDir = async (dirPath: string): Promise<void> => {
18
- try {
19
- await fs.mkdir(dirPath, { recursive: true });
20
- } catch {
21
- // Ignore errors
22
- }
23
- };
24
-
25
- export const isFhirPackage = async (dirPath: string): Promise<boolean> => {
26
- const indexPath = path.join(dirPath, ".index.json");
27
- return fileExists(indexPath);
28
- };
package/src/index.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * FHIR Canonical Manager - Modular Implementation
3
- * A package manager for FHIR resources with canonical URL resolution
4
- */
5
-
6
- // Re-export main CanonicalManager factory and class
7
- export { CanonicalManager, createCanonicalManager } from "./manager/index.js";
8
- export type { ReferenceManager as ReferenceManagerType } from "./reference.js";
9
- // Re-export reference management
10
- export { createReferenceManager, ReferenceManagerFactory as ReferenceManager } from "./reference.js";
11
- // Re-export CanonicalManager type interface with T prefix
12
- export type { CanonicalManager as TCanonicalManager } from "./types/core.js";
13
- // Re-export all public types
14
- export * from "./types/index.js";
15
-
16
- // Default export for backward compatibility
17
- import { createCanonicalManager } from "./manager/index.js";
18
- export default createCanonicalManager;