const assert = require('node:assert');
const { parse: parseHl7 } = require('../src/parsers/hl7Parser');
const { parse: parseAstm } = require('../src/parsers/astmParser');
const { normalize } = require('../src/normalizers');

async function run() {
  const hl7Sample = String.raw`MSH|^~\&|LIS|LAB|CLQMS|NORTH|202603261000||ORU^R01|msg-123|P|2.5
OBR|1|SOMEID|SMP-001||CBC^^^WBC^H|||202603261000
OBX|1|NM|WBC^White Blood Cell Count||8.2|10^3/uL|N|||F
OBX|2|NM|RBC^Red Blood Cell Count||4.5|10^6/uL|N|||F`;
  const astmSample = String.raw`H|\^&|LAB||ASTM1
P|1
O|1|SMP-100|12345^Instrument|^^^GLU^^^||
R|1|^^^GLU^7.2|7.2|mg/dL|||||N|
R|2|^^^ALT^7.4|50|IU/L|||||N|`;

  const hl7Result = await parseHl7(hl7Sample);
  assert.strictEqual(hl7Result.results.length, 2, 'HL7 should parse two OBX segments');
  const hl7Normalized = normalize(hl7Result);
  assert.strictEqual(hl7Normalized.instrument_id, 'SOMEID');
  assert.strictEqual(hl7Normalized.results[0].test_code, 'WBC');

  const astmResult = parseAstm(astmSample);
  assert.strictEqual(astmResult.results.length, 2, 'ASTM should parse multi R segments');
  const astmNormalized = normalize(astmResult);
  assert.strictEqual(astmNormalized.results[0].test_code, 'GLU');
  console.log('Parser smoke tests passed');
}

run().catch((err) => {
  console.error(err);
  process.exit(1);
});
