Skip to content

Commit 3af62f0

Browse files
Merge pull request #13 from Outburn-IL/fix-socket-hangups
Fix socket hangups
2 parents 43d9713 + e8f4a8d commit 3af62f0

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

package-lock.json

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

src/utils/file-utils.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@ const { log, logError } = require('./logger');
55

66
const BIN_DIR = path.join(__dirname, '../../bin');
77
const JAR_PATH = path.join(BIN_DIR, 'validator.jar');
8-
const GITHUB_API_URL = "https://api.github.com/repos/hapifhir/org.hl7.fhir.validator-wrapper/releases/latest";
8+
// Outburn's fork of the Validator Wrapper, supports skipping preset loading
9+
const GITHUB_API_URL = "https://api.github.com/repos/Outburn-IL/org.hl7.fhir.validator-wrapper/releases/latest";
10+
// Fallback to the original HAPI FHIR Validator Wrapper
11+
const GITHUB_API_FALLBACK = "https://api.github.com/repos/hapifhir/org.hl7.fhir.validator-wrapper/releases/latest";
912

1013
/**
1114
* Fetches the latest FHIR Validator JAR URL from GitHub Releases.
1215
*/
1316
async function getLatestValidatorJarUrl() {
17+
let response;
18+
try {
19+
response = await axios.get(GITHUB_API_URL);
20+
} catch (error) {
21+
logError("❌ Failed to fetch Outburn's fork of the validator. Falling back to the original HAPI FHIR Validator Wrapper.");
22+
response = await axios.get(GITHUB_API_FALLBACK);
23+
}
24+
1425
try {
1526
log("🔎 Checking latest FHIR Validator release...");
16-
const response = await axios.get(GITHUB_API_URL);
27+
1728
const assets = response.data.assets;
1829

19-
const jarAsset = assets.find(asset => asset.name.includes('validator_cli.jar'));
30+
const jarAsset = assets.find(asset => asset.name.startsWith('validator') && asset.name.endsWith('.jar'));
2031
if (!jarAsset) {
2132
throw new Error("Validator CLI JAR not found in the latest release.");
2233
}

src/validator.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class FHIRValidator {
1313
constructor({ cliContext = {} }) {
1414
this.javaExecutable = getJavaExecutable();
1515
this.cliContext = cliContext;
16-
if (this.cliContext?.txServer && this.cliContext.txServer === 'n/a') this.cliContext.txServer = null;
16+
if (this.cliContext?.txServer && ['n/a', '', 'null', 'none', 'na'].includes(this.cliContext.txServer)) this.cliContext.txServer = null;
17+
this.cliContext.igs = this.cliContext?.igs || [];
18+
this.cliContext.sv = this.cliContext?.sv || '4.0.1';
1719
this.sessionId = null;
1820
this.keepAliveInterval = null;
1921
}
@@ -22,7 +24,7 @@ class FHIRValidator {
2224
* Checks if the Validator Server is available by making a direct HTTP request.
2325
* @returns {Promise<boolean>} - Resolves to true if the server is responsive, otherwise false.
2426
*/
25-
async _isPortInUse() {
27+
async isValidatorServerUp() {
2628
const url = "http://localhost:3500/ig";
2729
const maxRetries = 10;
2830
let attempts = 0;
@@ -62,7 +64,7 @@ class FHIRValidator {
6264
* Starts the Validator Server if it's not already running.
6365
*/
6466
async startValidator() {
65-
const isRunning = await this._isPortInUse(3500);
67+
const isRunning = await this.isValidatorServerUp();
6668

6769
if (!isRunning) {
6870
log("🚀 Starting FHIR Validator Server...");
@@ -75,7 +77,12 @@ class FHIRValidator {
7577
], {
7678
detached: true,
7779
stdio: ['ignore', 'pipe', 'pipe'], // Capture stdout & stderr
78-
env: { ...process.env, ENVIRONMENT: "prod" }
80+
env: {
81+
...process.env,
82+
ENVIRONMENT: "prod",
83+
// DEFAULT_SV: this.cliContext.sv,
84+
LOAD_PRESETS: "false"
85+
}
7986
});
8087

8188
let serverReady = false;
@@ -113,7 +120,7 @@ class FHIRValidator {
113120
// ✅ Our process successfully started
114121
clearInterval(checkInterval);
115122
resolve();
116-
} else if (await this._isPortInUse(3500) && !serverReady) {
123+
} else if (await this.isValidatorServerUp() && !serverReady) {
117124
// ⚠️ Another process took the port, and we never got "serverReady"
118125
log("⚠️ Another process successfully bound to the port before ours was ready. Switching to 'already running' mode and terminating this process.");
119126
this.process.kill();

test/test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ const expectedResult2 = {
132132
(async () => {
133133
const validator1 = await createValidatorInstance({
134134
sv: "4.0.1",
135-
igs: ["il.core.fhir.r4#0.16.2"],
136-
locale: "en"
135+
igs: ["il.core.fhir.r4#0.16.2"]
137136
});
138137

139138
const validator2 = await createValidatorInstance({
140139
sv: "4.0.1",
141-
locale: "en"
140+
igs: []
142141
});
143142

144143
const resource = {

0 commit comments

Comments
 (0)