use of org.hl7.fhir.r5.elementmodel.Manager.FhirFormat in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method convertToR3.
private void convertToR3(InputStream source, OutputStream dest, FhirFormat format) throws FHIRException, IOException {
org.hl7.fhir.dstu3.elementmodel.Element r2 = new org.hl7.fhir.dstu3.elementmodel.XmlParser(contextR2).parse(source);
StructureMap map = library.get("http://hl7.org/fhir/StructureMap/" + r2.fhirType() + "2to3");
if (map == null)
throw new FHIRException("No Map Found from R2 to R3 for " + r2.fhirType());
String tn = smu3.getTargetType(map).getType();
Resource r3 = ResourceFactory.createResource(tn);
smu3.transform(new TransformContextR2R3(contextR3, r2.getChildValue("id")), r2, map, r3);
FormatUtilities.makeParser(format).setOutputStyle(style).compose(dest, r3);
}
use of org.hl7.fhir.r5.elementmodel.Manager.FhirFormat in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method main.
public static void main(String[] args) throws IOException, FHIRException {
if (args.length == 0 || !hasParam(args, "-d2") || !hasParam(args, "-d3") || !hasParam(args, "-maps") || !hasParam(args, "-src") || !hasParam(args, "-dest") || (!hasParam(args, "-r2") && !hasParam(args, "-r3"))) {
System.out.println("R2 <--> R3 Convertor");
System.out.println("====================");
System.out.println();
System.out.println("parameters: -d2 [r2 definitions] -d3 [r3 definitions] -maps [map source] -src [source] -dest [dest] -r2/3 - fmt [format]");
System.out.println();
System.out.println("d2: definitions from http://hl7.org/fhir/DSTU2/downloads.html");
System.out.println("d3: definitions from http://hl7.org/fhir/STU3/downloads.html");
System.out.println("maps: R2/R3 maps from http://hl7.org/fhir/r2r3maps.zip");
System.out.println("src: filename for source to convert");
System.out.println("dest: filename for destination of conversion");
System.out.println("-r2: source is r2, convert to r3");
System.out.println("-r3: source is r3, convert to r2");
System.out.println("-fmt: xml | json (xml is default)");
} else {
R2R3ConversionManager self = new R2R3ConversionManager();
self.setR2Definitions(getNamedParam(args, "-d2"));
self.setR3Definitions(getNamedParam(args, "-d3"));
self.setMappingLibrary(getNamedParam(args, "-maps"));
FhirFormat fmt = hasParam(args, "-fmt") ? getNamedParam(args, "-fmt").equalsIgnoreCase("json") ? FhirFormat.JSON : FhirFormat.XML : FhirFormat.XML;
InputStream src = new FileInputStream(getNamedParam(args, "-src"));
OutputStream dst = new FileOutputStream(getNamedParam(args, "-dest"));
self.convert(src, dst, hasParam(args, "-r2"), fmt);
}
}
use of org.hl7.fhir.r5.elementmodel.Manager.FhirFormat in project org.hl7.fhir.core by hapifhir.
the class FormatUtilities method loadFile.
public static Resource loadFile(String path) throws FileNotFoundException, IOException, FHIRException {
byte[] src = TextFile.fileToBytes(path);
FhirFormat fmt = determineFormat(src);
ParserBase parser = makeParser(fmt);
return parser.parse(src);
}
use of org.hl7.fhir.r5.elementmodel.Manager.FhirFormat in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method validate.
@Override
public org.hl7.fhir.r5.elementmodel.Element validate(Object appContext, List<ValidationMessage> errors, InputStream stream, FhirFormat format, List<StructureDefinition> profiles) throws FHIRException {
ParserBase parser = Manager.makeParser(context, format);
if (parser instanceof XmlParser)
((XmlParser) parser).setAllowXsiLocation(allowXsiLocation);
parser.setupValidation(ValidationPolicy.EVERYTHING, errors);
long t = System.nanoTime();
List<NamedElement> list = null;
try {
list = parser.parse(stream);
} catch (IOException e1) {
throw new FHIRException(e1);
}
timeTracker.load(t);
if (list != null && !list.isEmpty()) {
String url = parser.getImpliedProfile();
if (url != null) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null) {
rule(errors, IssueType.NOTFOUND, "Payload", false, "Implied profile " + url + " not known to validator");
} else {
profiles.add(sd);
}
}
for (NamedElement ne : list) {
validate(appContext, errors, ne.getName(), ne.getElement(), profiles);
}
}
// todo: this is broken, but fixing it really complicates things elsewhere, so we do this for now
return (list == null || list.isEmpty()) ? null : list.get(0).getElement();
}
use of org.hl7.fhir.r5.elementmodel.Manager.FhirFormat in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
// testing entry point
public OperationOutcome validate(FhirFormat format, InputStream stream, List<String> profiles) throws FHIRException, IOException, EOperationOutcome {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
InstanceValidator validator = getValidator(format);
validator.validate(null, messages, stream, format, asSdList(profiles));
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
Aggregations