Merge pull request #1387 from hapifhir/2023-08-gg-byte_provider
2023 08 gg byte provider
This commit is contained in:
commit
444c33da2a
|
@ -38,7 +38,6 @@ public class CPTImporter {
|
|||
|
||||
}
|
||||
|
||||
private Connection con;
|
||||
|
||||
private void doImport(String src, String version, String dst) throws FHIRException, FileNotFoundException, IOException, ClassNotFoundException, SQLException {
|
||||
|
||||
|
@ -85,8 +84,15 @@ public class CPTImporter {
|
|||
System.out.println(k);
|
||||
|
||||
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dst), cs);
|
||||
produceDB(Utilities.changeFileExt(dst, ".db"), cs);
|
||||
|
||||
connect(Utilities.changeFileExt(dst, ".db"));
|
||||
cs.getConcept().removeIf(cc -> !Utilities.existsInList(cc.getCode(), "metadata-kinds", "metadata-designations", "99202", "99203", "25", "P1"));
|
||||
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.changeFileExt(dst, "-fragment.json")), cs);
|
||||
produceDB(Utilities.changeFileExt(dst, "-fragment.db"), cs);
|
||||
}
|
||||
|
||||
private void produceDB(String path, CodeSystem cs) throws ClassNotFoundException, SQLException {
|
||||
Connection con = connect(path);
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute("insert into Information (name, value) values ('version', "+cs.getVersion()+")");
|
||||
|
@ -95,7 +101,7 @@ public class CPTImporter {
|
|||
stmt.execute("insert into Concepts (code, modifier) values ('"+cc.getCode()+"', "+isModifier(cc)+")");
|
||||
int i = 0;
|
||||
if (cc.hasDisplay()) {
|
||||
stmt.execute("insert into Designations (code, type, sequence, value) values ('"+cc.getCode()+"', 0, 0, '"+Utilities.escapeSql(cc.getDisplay())+"')");
|
||||
stmt.execute("insert into Designations (code, type, sequence, value) values ('"+cc.getCode()+"', 'display', 0, '"+Utilities.escapeSql(cc.getDisplay())+"')");
|
||||
i++;
|
||||
}
|
||||
for (ConceptDefinitionDesignationComponent d : cc.getDesignation()) {
|
||||
|
@ -111,9 +117,7 @@ public class CPTImporter {
|
|||
}
|
||||
}
|
||||
}
|
||||
cs.getConcept().removeIf(cc -> !Utilities.existsInList(cc.getCode(), "metadata-kinds", "metadata-designations", "99202", "25"));
|
||||
|
||||
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dst+"-fragment"), cs);
|
||||
}
|
||||
|
||||
private String isModifier(ConceptDefinitionComponent cc) {
|
||||
|
@ -126,19 +130,19 @@ public class CPTImporter {
|
|||
}
|
||||
|
||||
|
||||
private void connect(String dest) throws SQLException, ClassNotFoundException {
|
||||
private Connection connect(String dest) throws SQLException, ClassNotFoundException {
|
||||
// Class.forName("com.mysql.jdbc.Driver");
|
||||
// con = DriverManager.getConnection("jdbc:mysql://localhost:3306/omop?useSSL=false","root",{pwd});
|
||||
new File(dest).delete();
|
||||
con = DriverManager.getConnection("jdbc:sqlite:"+dest);
|
||||
makeMetadataTable();
|
||||
makeConceptsTable();
|
||||
makeDesignationsTable();
|
||||
makePropertiesTable();
|
||||
|
||||
Connection con = DriverManager.getConnection("jdbc:sqlite:"+dest);
|
||||
makeMetadataTable(con);
|
||||
makeConceptsTable(con);
|
||||
makeDesignationsTable(con);
|
||||
makePropertiesTable(con);
|
||||
return con;
|
||||
}
|
||||
|
||||
private void makeDesignationsTable() throws SQLException {
|
||||
private void makeDesignationsTable(Connection con) throws SQLException {
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute("CREATE TABLE Designations (\r\n"+
|
||||
"`code` varchar(15) NOT NULL,\r\n"+
|
||||
|
@ -149,7 +153,7 @@ public class CPTImporter {
|
|||
}
|
||||
|
||||
|
||||
private void makePropertiesTable() throws SQLException {
|
||||
private void makePropertiesTable(Connection con) throws SQLException {
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute("CREATE TABLE Properties (\r\n"+
|
||||
|
@ -162,7 +166,7 @@ public class CPTImporter {
|
|||
}
|
||||
|
||||
|
||||
private void makeConceptsTable() throws SQLException {
|
||||
private void makeConceptsTable(Connection con) throws SQLException {
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute("CREATE TABLE Concepts (\r\n"+
|
||||
|
@ -173,7 +177,7 @@ public class CPTImporter {
|
|||
}
|
||||
|
||||
|
||||
private void makeMetadataTable() throws SQLException {
|
||||
private void makeMetadataTable(Connection con) throws SQLException {
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.execute("CREATE TABLE Information (\r\n"+
|
||||
|
|
|
@ -71,6 +71,7 @@ import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
|
|||
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
|
||||
import org.hl7.fhir.r5.utils.R5Hacker;
|
||||
import org.hl7.fhir.r5.utils.XVerExtensionManager;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.hl7.fhir.utilities.CSFileInputStream;
|
||||
import org.hl7.fhir.utilities.MagicResources;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
|
@ -291,11 +292,11 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
return build(context);
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromDefinitions(Map<String, byte[]> source, IContextResourceLoader loader, PackageInformation pi) throws IOException, FHIRException {
|
||||
public SimpleWorkerContext fromDefinitions(Map<String, ByteProvider> source, IContextResourceLoader loader, PackageInformation pi) throws IOException, FHIRException {
|
||||
SimpleWorkerContext context = getSimpleWorkerContextInstance();
|
||||
for (String name : source.keySet()) {
|
||||
try {
|
||||
context.loadDefinitionItem(name, new ByteArrayInputStream(source.get(name)), loader, null, pi);
|
||||
context.loadDefinitionItem(name, new ByteArrayInputStream(source.get(name).getBytes()), loader, null, pi);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading "+name+": "+e.getMessage());
|
||||
throw new FHIRException("Error loading "+name+": "+e.getMessage(), e);
|
||||
|
|
|
@ -17,89 +17,35 @@ public class RendererFactory {
|
|||
return new LiquidRenderer(context, liquidTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
if ("CodeSystem".equals(resourceName)) {
|
||||
return new CodeSystemRenderer(context);
|
||||
switch (resourceName) {
|
||||
case "ActorDefinition": return new ActorDefinitionRenderer(context);
|
||||
case "Bundle": return new BundleRenderer(context);
|
||||
case "CapabilityStatement": return new CapabilityStatementRenderer(context);
|
||||
case "CodeSystem": return new CodeSystemRenderer(context);
|
||||
case "CompartmentDefinition": return new CompartmentDefinitionRenderer(context);
|
||||
case "ConceptMap": return new ConceptMapRenderer(context);
|
||||
case "DiagnosticReport": return new DiagnosticReportRenderer(context);
|
||||
case "Encounter": return new EncounterRenderer(context);
|
||||
case "ExampleScenario": return new ExampleScenarioRenderer(context);
|
||||
case "ImplementationGuide": return new ImplementationGuideRenderer(context);
|
||||
case "Library": return new LibraryRenderer(context);
|
||||
case "List": return new ListRenderer(context);
|
||||
case "NamingSystem": return new NamingSystemRenderer(context);
|
||||
case "OperationDefinition": return new OperationDefinitionRenderer(context);
|
||||
case "OperationOutcome": return new OperationOutcomeRenderer(context);
|
||||
case "Parameters": return new ParametersRenderer(context);
|
||||
case "Patient": return new PatientRenderer(context);
|
||||
case "Provenance": return new ProvenanceRenderer(context);
|
||||
case "Questionnaire": return new QuestionnaireRenderer(context);
|
||||
case "QuestionnaireResponse": return new QuestionnaireResponseRenderer(context);
|
||||
case "Requirements": return new RequirementsRenderer(context);
|
||||
case "SearchParameter": return new SearchParameterRenderer(context);
|
||||
case "StructureDefinition": return new StructureDefinitionRenderer(context);
|
||||
case "StructureMap": return new StructureMapRenderer(context);
|
||||
case "SubscriptionTopic": return new SubscriptionTopicRenderer(context);
|
||||
case "TestPlan": return new TestPlanRenderer(context);
|
||||
case "ValueSet": return new ValueSetRenderer(context);
|
||||
}
|
||||
if ("ValueSet".equals(resourceName)) {
|
||||
return new ValueSetRenderer(context);
|
||||
}
|
||||
if ("ConceptMap".equals(resourceName)) {
|
||||
return new ConceptMapRenderer(context);
|
||||
}
|
||||
|
||||
if ("CapabilityStatement".equals(resourceName)) {
|
||||
return new CapabilityStatementRenderer(context);
|
||||
}
|
||||
if ("StructureDefinition".equals(resourceName)) {
|
||||
return new StructureDefinitionRenderer(context);
|
||||
}
|
||||
if ("OperationDefinition".equals(resourceName)) {
|
||||
return new OperationDefinitionRenderer(context);
|
||||
}
|
||||
if ("SearchParameter".equals(resourceName)) {
|
||||
return new SearchParameterRenderer(context);
|
||||
}
|
||||
if ("CompartmentDefinition".equals(resourceName)) {
|
||||
return new CompartmentDefinitionRenderer(context);
|
||||
}
|
||||
if ("ImplementationGuide".equals(resourceName)) {
|
||||
return new ImplementationGuideRenderer(context);
|
||||
}
|
||||
if ("NamingSystem".equals(resourceName)) {
|
||||
return new NamingSystemRenderer(context);
|
||||
}
|
||||
if ("Questionnaire".equals(resourceName)) {
|
||||
return new QuestionnaireRenderer(context);
|
||||
}
|
||||
|
||||
if ("QuestionnaireResponse".equals(resourceName)) {
|
||||
return new QuestionnaireResponseRenderer(context);
|
||||
}
|
||||
|
||||
if ("Patient".equals(resourceName)) {
|
||||
return new PatientRenderer(context);
|
||||
}
|
||||
if ("Encounter".equals(resourceName)) {
|
||||
return new EncounterRenderer(context);
|
||||
}
|
||||
if ("Library".equals(resourceName)) {
|
||||
return new LibraryRenderer(context);
|
||||
}
|
||||
if ("List".equals(resourceName)) {
|
||||
return new ListRenderer(context);
|
||||
}
|
||||
if ("DiagnosticReport".equals(resourceName)) {
|
||||
return new DiagnosticReportRenderer(context);
|
||||
}
|
||||
|
||||
if ("Provenance".equals(resourceName)) {
|
||||
return new ProvenanceRenderer(context);
|
||||
}
|
||||
if ("OperationOutcome".equals(resourceName)) {
|
||||
return new OperationOutcomeRenderer(context);
|
||||
}
|
||||
if ("Parameters".equals(resourceName)) {
|
||||
return new ParametersRenderer(context);
|
||||
}
|
||||
if ("Bundle".equals(resourceName)) {
|
||||
return new BundleRenderer(context);
|
||||
}
|
||||
if ("ActorDefinition".equals(resourceName)) {
|
||||
return new ActorDefinitionRenderer(context);
|
||||
}
|
||||
if ("Requirements".equals(resourceName)) {
|
||||
return new RequirementsRenderer(context);
|
||||
}
|
||||
if ("SubscriptionTopic".equals(resourceName)) {
|
||||
return new SubscriptionTopicRenderer(context);
|
||||
}
|
||||
if ("StructureMap".equals(resourceName)) {
|
||||
return new StructureMapRenderer(context);
|
||||
}
|
||||
if ("TestPlan".equals(resourceName)) {
|
||||
return new TestPlanRenderer(context);
|
||||
}
|
||||
return new ProfileDrivenRenderer(context);
|
||||
}
|
||||
|
||||
|
@ -123,21 +69,12 @@ public class RendererFactory {
|
|||
return new LiquidRenderer(context, liquidTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
if ("List".equals(resource.getName())) {
|
||||
return new ListRenderer(context);
|
||||
}
|
||||
if ("Library".equals(resource.getName())) {
|
||||
return new LibraryRenderer(context);
|
||||
}
|
||||
if ("Patient".equals(resource.getName())) {
|
||||
return new PatientRenderer(context);
|
||||
}
|
||||
if ("DiagnosticReport".equals(resource.getName())) {
|
||||
return new DiagnosticReportRenderer(context);
|
||||
}
|
||||
if ("QuestionnaireResponse".equals(resource.getName())) {
|
||||
return new QuestionnaireResponseRenderer(context);
|
||||
switch (resource.getName()) {
|
||||
case "DiagnosticReport": return new DiagnosticReportRenderer(context);
|
||||
case "Library": return new LibraryRenderer(context);
|
||||
case "List": return new ListRenderer(context);
|
||||
case "Patient": return new PatientRenderer(context);
|
||||
case "QuestionnaireResponse": return new QuestionnaireResponseRenderer(context);
|
||||
}
|
||||
|
||||
return new ProfileDrivenRenderer(context, resourceContext);
|
||||
|
@ -152,7 +89,7 @@ public class RendererFactory {
|
|||
return Utilities.existsInList(rt,
|
||||
"CodeSystem", "ValueSet", "ConceptMap",
|
||||
"CapabilityStatement", "CompartmentDefinition", "ImplementationGuide", "Library", "NamingSystem", "OperationDefinition",
|
||||
"Questionnaire", "SearchParameter", "StructureDefinition", "ActorDefinition", "Requirements", "TestPlan");
|
||||
"Questionnaire", "SearchParameter", "StructureDefinition", "ActorDefinition", "Requirements", "TestPlan", "ExampleScenario");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,6 +76,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||
return render(x, (ValueSet) dr, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean render(XhtmlNode x, ValueSet vs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
|
||||
List<UsedConceptMap> maps = findReleventMaps(vs);
|
||||
|
||||
|
@ -1130,10 +1131,10 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||
boolean hasExtensions = false;
|
||||
XhtmlNode li;
|
||||
li = ul.li();
|
||||
CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
|
||||
Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
|
||||
|
||||
if (inc.hasSystem()) {
|
||||
CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
|
||||
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
|
||||
li.addText(type+" all codes defined in ");
|
||||
addCsRef(inc, li, e);
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package org.hl7.fhir.utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public abstract class ByteProvider {
|
||||
|
||||
public abstract byte[] getBytes() throws FileNotFoundException, IOException;
|
||||
|
||||
// this one needs to be deprecated - or try to to use it - get to the source
|
||||
public static ByteProvider forStream(InputStream stream) throws IOException {
|
||||
return new ByteProviderBytes(TextFile.streamToBytes(stream));
|
||||
}
|
||||
|
||||
public static ByteProvider forBytes(byte[] bytes) {
|
||||
return new ByteProviderBytes(bytes);
|
||||
}
|
||||
|
||||
public static ByteProvider forFile(File ff) {
|
||||
return new ByteProviderFile(ff);
|
||||
}
|
||||
|
||||
public static ByteProvider forFile(String src) {
|
||||
return new ByteProviderFile(new File(src));
|
||||
}
|
||||
|
||||
private static class ByteProviderBytes extends ByteProvider {
|
||||
|
||||
private byte[] cnt;
|
||||
|
||||
protected ByteProviderBytes(byte[] cnt) {
|
||||
this.cnt = cnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ByteProviderFile extends ByteProvider {
|
||||
|
||||
private File file;
|
||||
|
||||
protected ByteProviderFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws FileNotFoundException, IOException {
|
||||
return TextFile.fileToBytes(file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -65,6 +65,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
|||
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipParameters;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
|
||||
|
@ -252,6 +253,19 @@ public class NpmPackage {
|
|||
}
|
||||
}
|
||||
|
||||
public ByteProvider getProvider(String file) throws FileNotFoundException, IOException {
|
||||
if (folder != null) {
|
||||
File f = new File(Utilities.path(folder.getAbsolutePath(), file));
|
||||
if (f.exists()) {
|
||||
return ByteProvider.forFile(f);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return ByteProvider.forBytes(content.get(file));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFile(String file) throws IOException {
|
||||
if (folder != null) {
|
||||
return new File(Utilities.path(folder.getAbsolutePath(), file)).exists();
|
||||
|
@ -794,6 +808,7 @@ public class NpmPackage {
|
|||
public InputStream load(String file) throws IOException {
|
||||
return load("package", file);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a stream that contains the contents of one of the files in a folder
|
||||
*
|
||||
|
@ -814,6 +829,27 @@ public class NpmPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get a stream that contains the contents of one of the files in a folder
|
||||
*
|
||||
* @param folder
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public ByteProvider getProvider(String folder, String file) throws IOException {
|
||||
NpmPackageFolder f = folders.get(folder);
|
||||
if (f == null) {
|
||||
f = folders.get(Utilities.path("package", folder));
|
||||
}
|
||||
if (f != null && f.hasFile(file)) {
|
||||
return f.getProvider(file);
|
||||
} else {
|
||||
throw new IOException("Unable to find the file "+folder+"/"+file+" in the package "+name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean hasFile(String folder, String file) throws IOException {
|
||||
NpmPackageFolder f = folders.get(folder);
|
||||
if (f == null) {
|
||||
|
|
|
@ -925,8 +925,8 @@ UNKNOWN_CODESYSTEM = The CodeSystem {0} is unknown
|
|||
UNKNOWN_CODESYSTEM_VERSION = The CodeSystem {0} version {1} is unknown. Valid versions: {2}
|
||||
UNABLE_TO_INFER_CODESYSTEM = The System URI could not be determined for the code {0} in the ValueSet {1}
|
||||
VALUESET_TOO_COSTLY = The value set {0} has too many codes to display ({1})
|
||||
NO_VALID_DISPLAY_FOUND_one = No valid Display Names found for {1}#{2} in the language {3}
|
||||
NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {1}#{2} in the languages {3}
|
||||
NO_VALID_DISPLAY_FOUND_one = No valid Display Names found for {0}#{1} in the language {3}
|
||||
NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {0}#{1} in the languages {3}
|
||||
SD_NO_CONTEXT_WHEN_NOT_EXTENSION = The type is {0} so an extension context should not be specified
|
||||
SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = The type is {0} so an extension context invariants should not be specified
|
||||
SD_CONTEXT_SHOULD_NOT_BE_ELEMENT = Review the extension type: extensions should not have a context of {0} unless it''s really intended that they can be used anywhere
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package org.hl7.fhir.validation;
|
||||
|
||||
import org.hl7.fhir.r5.elementmodel.Manager;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
|
||||
public class Content {
|
||||
private byte[] focus = null;
|
||||
private ByteProvider focus = null;
|
||||
private Manager.FhirFormat cntType = null;
|
||||
|
||||
public byte[] getFocus() {
|
||||
public ByteProvider getFocus() {
|
||||
return focus;
|
||||
}
|
||||
public Manager.FhirFormat getCntType() {
|
||||
return cntType;
|
||||
}
|
||||
public void setFocus(byte[] focus) {
|
||||
public void setFocus(ByteProvider focus) {
|
||||
this.focus = focus;
|
||||
}
|
||||
public void setCntType(Manager.FhirFormat cntType) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hl7.fhir.r5.model.Constants;
|
|||
import org.hl7.fhir.r5.model.ImplementationGuide;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.hl7.fhir.utilities.IniFile;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
|
||||
|
@ -86,7 +87,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
* @see IgLoader#loadIgSource(String, boolean, boolean) loadIgSource for detailed description of the src parameter
|
||||
*/
|
||||
public void loadIg(List<ImplementationGuide> igs,
|
||||
Map<String, byte[]> binaries,
|
||||
Map<String, ByteProvider> binaries,
|
||||
String src,
|
||||
boolean recursive) throws IOException, FHIRException {
|
||||
|
||||
|
@ -124,7 +125,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
System.out.print(" Load " + srcPackage);
|
||||
String canonical = null;
|
||||
int count = 0;
|
||||
Map<String, byte[]> source = loadIgSource(srcPackage, recursive, true);
|
||||
Map<String, ByteProvider> source = loadIgSource(srcPackage, recursive, true);
|
||||
String version = Constants.VERSION;
|
||||
if (getVersion() != null) {
|
||||
version = getVersion();
|
||||
|
@ -136,7 +137,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
version = explicitFhirVersion;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, byte[]> t : source.entrySet()) {
|
||||
for (Map.Entry<String, ByteProvider> t : source.entrySet()) {
|
||||
String fn = t.getKey();
|
||||
if (!exemptFile(fn)) {
|
||||
Resource r = loadFileWithErrorChecking(version, t, fn);
|
||||
|
@ -175,14 +176,14 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
*/
|
||||
|
||||
public Content loadContent(String source, String opName, boolean asIg, boolean mustLoad) throws FHIRException, IOException {
|
||||
Map<String, byte[]> s = loadIgSource(source, false, asIg);
|
||||
Map<String, ByteProvider> s = loadIgSource(source, false, asIg);
|
||||
Content res = new Content();
|
||||
if (!mustLoad && s.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (s.size() != 1)
|
||||
throw new FHIRException("Unable to find resource " + source + " to " + opName);
|
||||
for (Map.Entry<String, byte[]> t : s.entrySet()) {
|
||||
for (Map.Entry<String, ByteProvider> t : s.entrySet()) {
|
||||
res.setFocus(t.getValue());
|
||||
if (t.getKey().endsWith(".json"))
|
||||
res.setCntType(Manager.FhirFormat.JSON);
|
||||
|
@ -216,7 +217,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
* @throws FHIRException
|
||||
* @throws IOException
|
||||
*/
|
||||
public Map<String, byte[]> loadIgSource(String src,
|
||||
public Map<String, ByteProvider> loadIgSource(String src,
|
||||
boolean recursive,
|
||||
boolean explore) throws FHIRException, IOException {
|
||||
//
|
||||
|
@ -265,7 +266,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
FileInputStream stream = new FileInputStream(src);
|
||||
try {
|
||||
if (src.endsWith(".tgz")) {
|
||||
Map<String, byte[]> res = loadPackage(stream, src, false);
|
||||
Map<String, ByteProvider> res = loadPackage(stream, src, false);
|
||||
return res;
|
||||
}
|
||||
if (src.endsWith(".pack")) {
|
||||
|
@ -280,8 +281,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
|
||||
Manager.FhirFormat fmt = ResourceChecker.checkIsResource(getContext(), isDebug(), TextFile.fileToBytes(f), src, true);
|
||||
if (fmt != null) {
|
||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), TextFile.fileToBytesNCS(src));
|
||||
Map<String, ByteProvider> res = new HashMap<String, ByteProvider>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), ByteProvider.forFile(src));
|
||||
return res;
|
||||
}
|
||||
} else if ((src.matches(FilesystemPackageCacheManager.PACKAGE_REGEX) || src.matches(FilesystemPackageCacheManager.PACKAGE_VERSION_REGEX)) && !src.endsWith(".zip") && !src.endsWith(".tgz")) {
|
||||
|
@ -293,12 +294,12 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
public void scanForIgVersion(String src,
|
||||
boolean recursive,
|
||||
VersionSourceInformation versions) throws Exception {
|
||||
Map<String, byte[]> source = loadIgSourceForVersion(src, recursive, true, versions);
|
||||
Map<String, ByteProvider> source = loadIgSourceForVersion(src, recursive, true, versions);
|
||||
if (source != null) {
|
||||
if (source.containsKey("version.info")) {
|
||||
versions.see(readInfoVersion(source.get("version.info")), "version.info in " + src);
|
||||
} else if (source.size() == 1) {
|
||||
for (byte[] v : source.values()) {
|
||||
for (ByteProvider v : source.values()) {
|
||||
scanForFhirVersion(versions, src, v);
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +315,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private void scanForFhirVersion(VersionSourceInformation versions, String ref, byte[] cnt) throws IOException {
|
||||
private void scanForFhirVersion(VersionSourceInformation versions, String ref, ByteProvider bp) throws IOException {
|
||||
byte[] cnt = bp.getBytes();
|
||||
String s = TextFile.bytesToString(cnt.length > SCAN_HEADER_SIZE ? Arrays.copyOfRange(cnt, 0, SCAN_HEADER_SIZE) : cnt).trim();
|
||||
try {
|
||||
int i = s.indexOf("fhirVersion");
|
||||
|
@ -377,8 +379,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
return i == s.length() ? -1 : i;
|
||||
}
|
||||
|
||||
protected Map<String, byte[]> readZip(InputStream stream) throws IOException {
|
||||
Map<String, byte[]> res = new HashMap<>();
|
||||
protected Map<String, ByteProvider> readZip(InputStream stream) throws IOException {
|
||||
Map<String, ByteProvider> res = new HashMap<>();
|
||||
ZipInputStream zip = new ZipInputStream(stream);
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = zip.getNextEntry()) != null) {
|
||||
|
@ -392,7 +394,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
while ((n = ((InputStream) zip).read(buf, 0, 1024)) > -1) {
|
||||
b.write(buf, 0, n);
|
||||
}
|
||||
res.put(entryName, b.toByteArray());
|
||||
res.put(entryName, ByteProvider.forBytes(b.toByteArray()));
|
||||
zip.closeEntry();
|
||||
}
|
||||
zip.close();
|
||||
|
@ -417,7 +419,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, byte[]> loadIgSourceForVersion(String src,
|
||||
private Map<String, ByteProvider> loadIgSourceForVersion(String src,
|
||||
boolean recursive,
|
||||
boolean explore,
|
||||
VersionSourceInformation versions) throws FHIRException, IOException {
|
||||
|
@ -458,8 +460,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
return readZip(new FileInputStream(src));
|
||||
Manager.FhirFormat fmt = ResourceChecker.checkIsResource(getContext(), isDebug(), TextFile.fileToBytes(f), src, true);
|
||||
if (fmt != null) {
|
||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), TextFile.fileToBytesNCS(src));
|
||||
Map<String, ByteProvider> res = new HashMap<String, ByteProvider>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), ByteProvider.forFile(src));
|
||||
return res;
|
||||
}
|
||||
} else if ((src.matches(FilesystemPackageCacheManager.PACKAGE_REGEX) || src.matches(FilesystemPackageCacheManager.PACKAGE_VERSION_REGEX)) && !src.endsWith(".zip") && !src.endsWith(".tgz")) {
|
||||
|
@ -470,7 +472,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
|
||||
|
||||
private Map<String, byte[]> fetchByPackage(String src, boolean loadInContext) throws FHIRException, IOException {
|
||||
private Map<String, ByteProvider> fetchByPackage(String src, boolean loadInContext) throws FHIRException, IOException {
|
||||
String id = src;
|
||||
String version = null;
|
||||
if (src.contains("#")) {
|
||||
|
@ -493,12 +495,12 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
return loadPackage(pi, loadInContext);
|
||||
}
|
||||
|
||||
private Map<String, byte[]> loadPackage(InputStream stream, String name, boolean loadInContext) throws FHIRException, IOException {
|
||||
private Map<String, ByteProvider> loadPackage(InputStream stream, String name, boolean loadInContext) throws FHIRException, IOException {
|
||||
return loadPackage(NpmPackage.fromPackage(stream), loadInContext);
|
||||
}
|
||||
|
||||
public Map<String, byte[]> loadPackage(NpmPackage pi, boolean loadInContext) throws FHIRException, IOException {
|
||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||
public Map<String, ByteProvider> loadPackage(NpmPackage pi, boolean loadInContext) throws FHIRException, IOException {
|
||||
Map<String, ByteProvider> res = new HashMap<String, ByteProvider>();
|
||||
for (String s : pi.dependencies()) {
|
||||
if (s.endsWith(".x") && s.length() > 2) {
|
||||
String packageMajorMinor = s.substring(0, s.length() - 2);
|
||||
|
@ -526,23 +528,23 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
getContext().loadFromPackage(pi, ValidatorUtils.loaderForVersion(pi.fhirVersion()));
|
||||
}
|
||||
for (String s : pi.listResources("CodeSystem", "ConceptMap", "ImplementationGuide", "CapabilityStatement", "SearchParameter", "Conformance", "StructureMap", "ValueSet", "StructureDefinition")) {
|
||||
res.put(s, TextFile.streamToBytes(pi.load("package", s)));
|
||||
res.put(s, pi.getProvider("package", s));
|
||||
}
|
||||
}
|
||||
String ini = "[FHIR]\r\nversion=" + pi.fhirVersion() + "\r\n";
|
||||
res.put("version.info", ini.getBytes());
|
||||
res.put("version.info", ByteProvider.forBytes(ini.getBytes()));
|
||||
return res;
|
||||
}
|
||||
|
||||
private Map<String, byte[]> resolvePackage(String id, String v, boolean loadInContext) throws FHIRException, IOException {
|
||||
private Map<String, ByteProvider> resolvePackage(String id, String v, boolean loadInContext) throws FHIRException, IOException {
|
||||
NpmPackage pi = getPackageCacheManager().loadPackage(id, v);
|
||||
if (pi != null && v == null)
|
||||
System.out.println(" ... Using version " + pi.version());
|
||||
return loadPackage(pi, loadInContext);
|
||||
}
|
||||
|
||||
private String readInfoVersion(byte[] bs) throws IOException {
|
||||
String is = TextFile.bytesToString(bs);
|
||||
private String readInfoVersion(ByteProvider bs) throws IOException {
|
||||
String is = TextFile.bytesToString(bs.getBytes());
|
||||
is = is.trim();
|
||||
IniFile ini = new IniFile(new ByteArrayInputStream(TextFile.stringToBytes(is, false)));
|
||||
return ini.getStringProperty("FHIR", "version");
|
||||
|
@ -572,7 +574,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, byte[]> fetchVersionFromUrl(String src,
|
||||
private Map<String, ByteProvider> fetchVersionFromUrl(String src,
|
||||
boolean explore,
|
||||
VersionSourceInformation versions) throws FHIRException, IOException {
|
||||
if (src.endsWith(".tgz")) {
|
||||
|
@ -611,8 +613,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
|
||||
Manager.FhirFormat fmt = ResourceChecker.checkIsResource(getContext(), isDebug(), cnt, src, true);
|
||||
if (fmt != null) {
|
||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), cnt);
|
||||
Map<String, ByteProvider> res = new HashMap<String, ByteProvider>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), ByteProvider.forBytes(cnt));
|
||||
return res;
|
||||
}
|
||||
String fn = Utilities.path("[tmp]", "fetch-resource-error-content.bin");
|
||||
|
@ -647,7 +649,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, byte[]> fetchFromUrl(String src, boolean explore) throws FHIRException, IOException {
|
||||
private Map<String, ByteProvider> fetchFromUrl(String src, boolean explore) throws FHIRException, IOException {
|
||||
if (src.endsWith(".tgz"))
|
||||
return loadPackage(fetchFromUrlSpecific(src, false), src, false);
|
||||
if (src.endsWith(".pack"))
|
||||
|
@ -688,8 +690,8 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
}
|
||||
Manager.FhirFormat fmt = checkFormat(cnt, src);
|
||||
if (fmt != null) {
|
||||
Map<String, byte[]> res = new HashMap<>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), cnt);
|
||||
Map<String, ByteProvider> res = new HashMap<>();
|
||||
res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), ByteProvider.forBytes(cnt));
|
||||
return res;
|
||||
}
|
||||
throw new FHIRException("Unable to read content from " + src + ": cannot determine format");
|
||||
|
@ -702,15 +704,15 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
return Utilities.existsInList(Utilities.getFileExtension(ff.getName()).toLowerCase(), IGNORED_EXTENSIONS);
|
||||
}
|
||||
|
||||
private Map<String, byte[]> scanDirectory(File f, boolean recursive) throws IOException {
|
||||
Map<String, byte[]> res = new HashMap<>();
|
||||
private Map<String, ByteProvider> scanDirectory(File f, boolean recursive) throws IOException {
|
||||
Map<String, ByteProvider> res = new HashMap<>();
|
||||
for (File ff : f.listFiles()) {
|
||||
if (ff.isDirectory() && recursive) {
|
||||
res.putAll(scanDirectory(ff, true));
|
||||
} else if (!ff.isDirectory() && !isIgnoreFile(ff)) {
|
||||
Manager.FhirFormat fmt = ResourceChecker.checkIsResource(getContext(), isDebug(), TextFile.fileToBytes(ff), ff.getAbsolutePath(), true);
|
||||
if (fmt != null) {
|
||||
res.put(Utilities.changeFileExt(ff.getName(), "." + fmt.getExtension()), TextFile.fileToBytes(ff.getAbsolutePath()));
|
||||
res.put(Utilities.changeFileExt(ff.getName(), "." + fmt.getExtension()), ByteProvider.forFile(ff));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -764,11 +766,11 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
return Utilities.existsInList(fn, EXEMPT_FILES);
|
||||
}
|
||||
|
||||
protected Resource loadFileWithErrorChecking(String version, Map.Entry<String, byte[]> t, String fn) {
|
||||
protected Resource loadFileWithErrorChecking(String version, Map.Entry<String, ByteProvider> t, String fn) {
|
||||
log("* load file: " + fn);
|
||||
Resource r = null;
|
||||
try {
|
||||
r = loadResourceByVersion(version, t.getValue(), fn);
|
||||
r = loadResourceByVersion(version, t.getValue().getBytes(), fn);
|
||||
log(" .. success");
|
||||
} catch (Exception e) {
|
||||
if (!isDebug()) {
|
||||
|
@ -858,7 +860,7 @@ public class IgLoader implements IValidationEngineLoader {
|
|||
|
||||
@Override
|
||||
public void load(Content cnt) throws FHIRException, IOException {
|
||||
Resource res = loadResourceByVersion(version, cnt.getFocus(), cnt.getExampleFileName());
|
||||
Resource res = loadResourceByVersion(version, cnt.getFocus().getBytes(), cnt.getExampleFileName());
|
||||
context.cacheResource(res);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class Scanner {
|
|||
try {
|
||||
System.out.println("Validate " + ref);
|
||||
messages.clear();
|
||||
e = getValidator().validate(null, messages, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
e = getValidator().validate(null, messages, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
res.add(new ScanOutputItem(ref.getRef(), null, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
|
||||
} catch (Exception ex) {
|
||||
res.add(new ScanOutputItem(ref.getRef(), null, null, exceptionToOutcome(ex)));
|
||||
|
@ -104,7 +104,7 @@ public class Scanner {
|
|||
try {
|
||||
System.out.println("Validate " + ref + " against " + ig.getUrl());
|
||||
messages.clear();
|
||||
getValidator().validate(null, messages, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType(), url);
|
||||
getValidator().validate(null, messages, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType(), url);
|
||||
res.add(new ScanOutputItem(ref.getRef(), ig, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
|
||||
} catch (Exception ex) {
|
||||
res.add(new ScanOutputItem(ref.getRef(), ig, null, exceptionToOutcome(ex)));
|
||||
|
@ -118,7 +118,7 @@ public class Scanner {
|
|||
try {
|
||||
System.out.println("Validate " + ref + " against " + sd.getUrl());
|
||||
messages.clear();
|
||||
validator.validate(null, messages, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType(), Collections.singletonList(sd));
|
||||
validator.validate(null, messages, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType(), Collections.singletonList(sd));
|
||||
res.add(new ScanOutputItem(ref.getRef(), ig, sd, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
|
||||
} catch (Exception ex) {
|
||||
res.add(new ScanOutputItem(ref.getRef(), ig, sd, exceptionToOutcome(ex)));
|
||||
|
|
|
@ -101,6 +101,7 @@ import org.hl7.fhir.validation.cli.utils.SchemaValidator;
|
|||
import org.hl7.fhir.validation.cli.utils.ValidationLevel;
|
||||
import org.hl7.fhir.validation.instance.InstanceValidator;
|
||||
import org.hl7.fhir.validation.instance.utils.ValidatorHostContext;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -189,7 +190,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
}
|
||||
|
||||
@Getter @Setter private SimpleWorkerContext context;
|
||||
@Getter @Setter private Map<String, byte[]> binaries = new HashMap<>();
|
||||
@Getter @Setter private Map<String, ByteProvider> binaries = new HashMap<>();
|
||||
@Getter @Setter private boolean doNative;
|
||||
@Getter @Setter private boolean noInvariantChecks;
|
||||
@Getter @Setter private boolean displayWarnings;
|
||||
|
@ -445,7 +446,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
}
|
||||
context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version), false);
|
||||
} else {
|
||||
Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
|
||||
Map<String, ByteProvider> source = igLoader.loadIgSource(src, recursive, true);
|
||||
if (version == null) {
|
||||
version = getVersionFromPack(source);
|
||||
}
|
||||
|
@ -485,9 +486,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
this.fhirPathEngine.setAllowDoubleQuotes(false);
|
||||
}
|
||||
|
||||
private String getVersionFromPack(Map<String, byte[]> source) {
|
||||
private String getVersionFromPack(Map<String, ByteProvider> source) throws FileNotFoundException, IOException {
|
||||
if (source.containsKey("version.info")) {
|
||||
IniFile vi = new IniFile(new ByteArrayInputStream(removeBom(source.get("version.info"))));
|
||||
IniFile vi = new IniFile(new ByteArrayInputStream(removeBom(source.get("version.info").getBytes())));
|
||||
return vi.getStringProperty("FHIR", "version");
|
||||
} else {
|
||||
throw new Error("Missing version.info?");
|
||||
|
@ -640,13 +641,13 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
|
||||
}
|
||||
|
||||
public OperationOutcome validate(String location, byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationRecord> record) throws FHIRException, IOException, EOperationOutcome, SAXException {
|
||||
public OperationOutcome validate(String location, ByteProvider source, FhirFormat cntType, List<String> profiles, List<ValidationRecord> record) throws FHIRException, IOException, EOperationOutcome, SAXException {
|
||||
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
|
||||
if (doNative) {
|
||||
SchemaValidator.validateSchema(location, cntType, messages);
|
||||
}
|
||||
InstanceValidator validator = getValidator(cntType);
|
||||
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
|
||||
validator.validate(null, messages, new ByteArrayInputStream(source.getBytes()), cntType, asSdList(profiles));
|
||||
if (showTimes) {
|
||||
System.out.println(location + ": " + validator.reportTimes());
|
||||
}
|
||||
|
@ -688,7 +689,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
return map;
|
||||
}
|
||||
|
||||
public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri) throws FHIRException, IOException {
|
||||
public org.hl7.fhir.r5.elementmodel.Element transform(ByteProvider source, FhirFormat cntType, String mapUri) throws FHIRException, IOException {
|
||||
List<Base> outputs = new ArrayList<>();
|
||||
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs, mapLog, context));
|
||||
StructureMap map = context.fetchResource(StructureMap.class, mapUri);
|
||||
|
@ -699,7 +700,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
if (sourceSD.getKind() == StructureDefinition.StructureDefinitionKind.LOGICAL) {
|
||||
parser.setLogical(sourceSD);
|
||||
}
|
||||
org.hl7.fhir.r5.elementmodel.Element src = parser.parseSingle(new ByteArrayInputStream(source));
|
||||
org.hl7.fhir.r5.elementmodel.Element src = parser.parseSingle(new ByteArrayInputStream(source.getBytes()));
|
||||
scu.transform(null, src, map, resource);
|
||||
resource.populatePaths(null);
|
||||
return resource;
|
||||
|
@ -764,7 +765,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
|
||||
public Resource generate(String source, String version) throws FHIRException, IOException, EOperationOutcome {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus(), source);
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus().getBytes(), source);
|
||||
RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER, GenerationRules.VALID_RESOURCE);
|
||||
genResource(res, rc);
|
||||
return (Resource) res;
|
||||
|
@ -785,21 +786,21 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
|
||||
public void convert(String source, String output) throws FHIRException, IOException {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
Element e = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
Element e = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
Manager.compose(context, e, new FileOutputStream(output), (output.endsWith(".json") ? FhirFormat.JSON : FhirFormat.XML), OutputStyle.PRETTY, null);
|
||||
}
|
||||
|
||||
public String evaluateFhirPath(String source, String expression) throws FHIRException, IOException {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
FHIRPathEngine fpe = this.getValidator(null).getFHIRPathEngine();
|
||||
Element e = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
Element e = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
ExpressionNode exp = fpe.parse(expression);
|
||||
return fpe.evaluateToString(new ValidatorHostContext(context, e), e, e, e, exp);
|
||||
}
|
||||
|
||||
public StructureDefinition snapshot(String source, String version) throws FHIRException, IOException {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus(), Utilities.getFileNameForName(source));
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus().getBytes(), Utilities.getFileNameForName(source));
|
||||
|
||||
if (!(res instanceof StructureDefinition))
|
||||
throw new FHIRException("Require a StructureDefinition for generating a snapshot");
|
||||
|
@ -812,7 +813,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
|
||||
public CanonicalResource loadCanonicalResource(String source, String version) throws FHIRException, IOException {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus(), Utilities.getFileNameForName(source));
|
||||
Resource res = igLoader.loadResourceByVersion(version, cnt.getFocus().getBytes(), Utilities.getFileNameForName(source));
|
||||
|
||||
if (!(res instanceof CanonicalResource))
|
||||
throw new FHIRException("Require a CanonicalResource");
|
||||
|
@ -959,7 +960,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
|
||||
public byte[] transformVersion(String source, String targetVer, FhirFormat format, Boolean canDoNative) throws FHIRException, IOException, Exception {
|
||||
Content cnt = igLoader.loadContent(source, "validate", false, true);
|
||||
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
|
||||
// if the src has a url, we try to use the java code
|
||||
if ((canDoNative == null && src.hasChild("url")) || (canDoNative != null && canDoNative)) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
|
|||
import org.hl7.fhir.r5.utils.EOperationOutcome;
|
||||
import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
||||
import org.hl7.fhir.r5.utils.OperationOutcomeUtilities;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.i18n.I18nConstants;
|
||||
|
@ -72,8 +73,8 @@ public class ValidatorUtils {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void grabNatives(Map<String, byte[]> source, Map<String, byte[]> binaries, String prefix) {
|
||||
for (Map.Entry<String, byte[]> e : source.entrySet()) {
|
||||
protected static void grabNatives(Map<String, ByteProvider> source, Map<String, ByteProvider> binaries, String prefix) {
|
||||
for (Map.Entry<String, ByteProvider> e : source.entrySet()) {
|
||||
if (e.getKey().endsWith(".zip"))
|
||||
binaries.put(prefix + "#" + e.getKey(), e.getValue());
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.dstu2.model.Resource r2;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r2 = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt.getFocus());
|
||||
r2 = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r2 = new org.hl7.fhir.dstu2.formats.XmlParser().parse(cnt.getFocus());
|
||||
r2 = new org.hl7.fhir.dstu2.formats.XmlParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
@ -53,10 +53,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.dstu2016may.model.Resource r2b;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r2b = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt.getFocus());
|
||||
r2b = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r2b = new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(cnt.getFocus());
|
||||
r2b = new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
@ -82,10 +82,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.dstu3.model.Resource r3;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt.getFocus());
|
||||
r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r3 = new org.hl7.fhir.dstu3.formats.XmlParser().parse(cnt.getFocus());
|
||||
r3 = new org.hl7.fhir.dstu3.formats.XmlParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
@ -109,10 +109,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.r4.model.Resource r4;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt.getFocus());
|
||||
r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r4 = new org.hl7.fhir.r4.formats.XmlParser().parse(cnt.getFocus());
|
||||
r4 = new org.hl7.fhir.r4.formats.XmlParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
@ -137,10 +137,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.r4b.model.Resource r4b;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r4b = new org.hl7.fhir.r4b.formats.JsonParser().parse(cnt.getFocus());
|
||||
r4b = new org.hl7.fhir.r4b.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r4b = new org.hl7.fhir.r4b.formats.XmlParser().parse(cnt.getFocus());
|
||||
r4b = new org.hl7.fhir.r4b.formats.XmlParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
@ -159,10 +159,10 @@ public class VersionConvertor {
|
|||
org.hl7.fhir.r5.model.Resource r5;
|
||||
switch (cnt.getCntType()) {
|
||||
case JSON:
|
||||
r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt.getFocus());
|
||||
r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt.getFocus().getBytes());
|
||||
break;
|
||||
case XML:
|
||||
r5 = new org.hl7.fhir.r5.formats.XmlParser().parse(cnt.getFocus());
|
||||
r5 = new org.hl7.fhir.r5.formats.XmlParser().parse(cnt.getFocus().getBytes() );
|
||||
break;
|
||||
default:
|
||||
throw new FHIRException("Unsupported input format: " + cnt.getCntType().toString());
|
||||
|
|
|
@ -579,7 +579,7 @@ public class ValidationService {
|
|||
for (SourceFile ref : refs) {
|
||||
System.out.println(" Extract Translations from " + ref);
|
||||
org.hl7.fhir.validation.Content cnt = validator.getIgLoader().loadContent(ref.getRef(), "translate", false, true);
|
||||
Element e = Manager.parseSingle(validator.getContext(), new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
Element e = Manager.parseSingle(validator.getContext(), new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
LanguageProducerSession ps = po.startSession(e.fhirType()+"-"+e.getIdBase(), cliContext.getSrcLang());
|
||||
LanguageProducerLanguageSession psl = ps.forLang(cliContext.getTgtLang());
|
||||
new LanguageUtils(validator.getContext()).generateTranslations(e, psl);
|
||||
|
@ -614,7 +614,7 @@ public class ValidationService {
|
|||
for (SourceFile ref : refs) {
|
||||
System.out.println(" Inject Translations into " + ref);
|
||||
org.hl7.fhir.validation.Content cnt = validator.getIgLoader().loadContent(ref.getRef(), "translate", false, true);
|
||||
Element e = Manager.parseSingle(validator.getContext(), new ByteArrayInputStream(cnt.getFocus()), cnt.getCntType());
|
||||
Element e = Manager.parseSingle(validator.getContext(), new ByteArrayInputStream(cnt.getFocus().getBytes()), cnt.getCntType());
|
||||
t = t + new LanguageUtils(validator.getContext()).importFromTranslations(e, translations);
|
||||
Manager.compose(validator.getContext(), e, new FileOutputStream(Utilities.path(dst, new File(ref.getRef()).getName())), cnt.getCntType(),
|
||||
OutputStyle.PRETTY, null);
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.hl7.fhir.r5.model.StructureMap;
|
|||
import org.hl7.fhir.r5.test.utils.CompareUtilities;
|
||||
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||
|
@ -95,7 +96,7 @@ public class StructureMappingTests {
|
|||
@MethodSource("data")
|
||||
public void test(String name, String source, String map, String output) throws Exception {
|
||||
|
||||
byte[] byteSource = TestingUtilities.loadTestResourceBytes("r5", "structure-mapping", source);
|
||||
ByteProvider byteSource = ByteProvider.forBytes(TestingUtilities.loadTestResourceBytes("r5", "structure-mapping", source));
|
||||
|
||||
String outputJson = TestingUtilities.loadTestResource("r5", "structure-mapping", output);
|
||||
String fileOutputRes = TestingUtilities.tempFile("structure-mapping", output) + ".out";
|
||||
|
@ -144,7 +145,7 @@ public class StructureMappingTests {
|
|||
try {
|
||||
r = new StructureMapUtilities(context).parse(map, "cda2qr");
|
||||
context.cacheResource(r);
|
||||
byte[] byteSource = "{}".getBytes();
|
||||
ByteProvider byteSource = ByteProvider.forBytes("{}".getBytes());
|
||||
org.hl7.fhir.r5.elementmodel.Element element = validationEngine.transform(byteSource, FhirFormat.JSON, r.getUrl());
|
||||
Assertions.assertNotNull(element);
|
||||
} finally {
|
||||
|
@ -164,7 +165,7 @@ public class StructureMappingTests {
|
|||
StructureDefinition structureDefinition = new StructureDefinition().setUrl("testGetSourceResourceFromStructureMapDefinitionExceptionTarget");
|
||||
structureDefinition.getSnapshot().addElement().setPath("testGetSourceResourceFromStructureMapDefinitionExceptionTarget");
|
||||
context.cacheResource(structureDefinition);
|
||||
byte[] byteSource = "testGetSourceResourceFromStructureMapDefinitionException".getBytes();
|
||||
ByteProvider byteSource = ByteProvider.forBytes("testGetSourceResourceFromStructureMapDefinitionException".getBytes());
|
||||
DefinitionException thrown = assertThrows(
|
||||
DefinitionException.class,
|
||||
() -> validationEngine.transform(byteSource, FhirFormat.JSON, r.getUrl()),
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.hl7.fhir.exceptions.FHIRException;
|
|||
import org.hl7.fhir.r5.context.SimpleWorkerContext;
|
||||
import org.hl7.fhir.r5.model.ImplementationGuide;
|
||||
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
|
||||
import org.hl7.fhir.utilities.ByteProvider;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
@ -63,8 +64,8 @@ public class IgLoaderTests {
|
|||
final byte[] dummyBytes = {};
|
||||
final String dummyKey = "dummyKey";
|
||||
|
||||
final Map<String, byte[]> dummyMap = new HashMap<>();
|
||||
dummyMap.put(dummyKey, dummyBytes);
|
||||
final Map<String, ByteProvider> dummyMap = new HashMap<>();
|
||||
dummyMap.put(dummyKey, ByteProvider.forBytes(dummyBytes));
|
||||
|
||||
|
||||
IgLoader igLoader = Mockito.spy(new IgLoader(
|
||||
|
@ -136,10 +137,10 @@ public class IgLoaderTests {
|
|||
simpleWorkerContext,
|
||||
"4.0.1"
|
||||
));
|
||||
Map<String, byte[]> map = igLoader.readZip(IgLoaderTests.class.getResourceAsStream("/zip-slip/zip-normal.zip"));
|
||||
Map<String, ByteProvider> map = igLoader.readZip(IgLoaderTests.class.getResourceAsStream("/zip-slip/zip-normal.zip"));
|
||||
final String testPath = "zip-normal/depth1/test.txt";
|
||||
assertTrue(map.containsKey(testPath));
|
||||
String testFileContent = new String(map.get(testPath), StandardCharsets.UTF_8);
|
||||
String testFileContent = new String(map.get(testPath).getBytes(), StandardCharsets.UTF_8);
|
||||
Assertions.assertEquals("dummy file content", testFileContent);
|
||||
}
|
||||
}
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -20,7 +20,7 @@
|
|||
<properties>
|
||||
<guava_version>32.0.1-jre</guava_version>
|
||||
<hapi_fhir_version>6.4.1</hapi_fhir_version>
|
||||
<validator_test_case_version>1.3.25</validator_test_case_version>
|
||||
<validator_test_case_version>1.3.26-SNAPSHOT</validator_test_case_version>
|
||||
<jackson_version>2.15.2</jackson_version>
|
||||
<junit_jupiter_version>5.9.2</junit_jupiter_version>
|
||||
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>
|
||||
|
|
Loading…
Reference in New Issue