Add support for spitting out a StructureMap from a FHIR mapping language file

This commit is contained in:
Lloyd McKenzie 2022-01-03 13:16:28 -07:00
parent 3523d38052
commit f3727c2cf8
5 changed files with 44 additions and 0 deletions

View File

@ -410,6 +410,11 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
return transform(cnt.focus, cnt.cntType, map);
}
public StructureMap compile(String mapUri) throws FHIRException, IOException {
StructureMap map = context.getTransform(mapUri);
return map;
}
public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri) throws FHIRException, IOException {
List<Base> outputs = new ArrayList<>();
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs, mapLog, context));

View File

@ -241,6 +241,9 @@ public class ValidatorCli {
case TRANSFORM:
validationService.transform(cliContext, validator);
break;
case COMPILE:
validationService.compile(cliContext, validator);
break;
case NARRATIVE:
validationService.generateNarrative(cliContext, validator);
break;

View File

@ -253,6 +253,37 @@ public class ValidationService {
}
}
public void compile(CliContext cliContext, ValidationEngine validator) throws Exception {
if (cliContext.getSources().size() > 0)
throw new Exception("Cannot specify sources when compling transform (found " + cliContext.getSources() + ")");
// if (cliContext.getTxServer() == null)
// throw new Exception("Must provide a terminology server when compiling a transform");
if (cliContext.getMap() == null)
throw new Exception("Must provide a map when compiling a transform");
try {
List<StructureDefinition> structures = validator.getContext().allStructures();
for (StructureDefinition sd : structures) {
if (!sd.hasSnapshot()) {
if (sd.getKind() != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
validator.getContext().generateSnapshot(sd, true);
} else {
validator.getContext().generateSnapshot(sd, false);
}
}
}
validator.setMapLog(cliContext.getMapLog());
cliContext.getMap();
StructureMap map = validator.compile(cliContext.getMap());
System.out.println(" ...success");
if (cliContext.getOutput() != null) {
validator.handleOutput(map, cliContext.getOutput(), validator.getVersion());
}
} catch (Exception e) {
System.out.println(" ...Failure: " + e.getMessage());
e.printStackTrace();
}
}
public void transformVersion(CliContext cliContext, ValidationEngine validator) throws Exception {
if (cliContext.getSources().size() > 1) {
throw new Exception("Can only have one source when converting versions (found " + cliContext.getSources() + ")");

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.validation.cli.utils;
public enum EngineMode {
VALIDATION,
COMPILE,
TRANSFORM,
NARRATIVE,
SNAPSHOT,

View File

@ -31,6 +31,7 @@ public class Params {
public static final String TO_VERSION = "-to-version";
public static final String DO_NATIVE = "-do-native";
public static final String NO_NATIVE = "-no-native";
public static final String COMPILE = "-compile";
public static final String TRANSFORM = "-transform";
public static final String NARRATIVE = "-narrative";
public static final String SNAPSHOT = "-snapshot";
@ -191,6 +192,9 @@ public class Params {
} else if (args[i].equals(TRANSFORM)) {
cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.TRANSFORM);
} else if (args[i].equals(COMPILE)) {
cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.COMPILE);
} else if (args[i].equals(NARRATIVE)) {
cliContext.setMode(EngineMode.NARRATIVE);
} else if (args[i].equals(SPREADSHEET)) {