WIP return validation fragments

This commit is contained in:
dotasek 2023-09-21 09:50:08 -04:00
parent 14e6f210e6
commit ef6f92a21e
3 changed files with 33 additions and 6 deletions

View File

@ -50,5 +50,8 @@ public class ValidatedFragment {
public String getFilename() {
return name+"."+extension;
}
public String getExtension() {
return extension;
}
}

View File

@ -32,12 +32,8 @@ import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.IWorkerContextManager;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.context.SystemOutLoggingService;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.*;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.elementmodel.ObjectConverter;
import org.hl7.fhir.r5.elementmodel.ParserBase;
import org.hl7.fhir.r5.elementmodel.SHCParser;
import org.hl7.fhir.r5.formats.FormatUtilities;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
@ -635,6 +631,13 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
return results.getEntryFirstRep().getResource();
}
public List<ValidatedFragment> validateAsFragments(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
InstanceValidator validator = getValidator(cntType);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return validator.validatedContent;
}
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
InstanceValidator validator = getValidator(cntType);

View File

@ -29,6 +29,7 @@ import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.LanguageUtils;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.elementmodel.ValidatedFragment;
import org.hl7.fhir.r5.formats.IParser;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.Bundle;
@ -116,11 +117,31 @@ public class ValidationService {
for (FileInfo fp : request.getFilesToValidate()) {
List<ValidationMessage> messages = new ArrayList<>();
List<ValidatedFragment> validatedFragments = validator.validateAsFragments(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()),
request.getCliContext().getProfiles(), messages);
// TODO this chunk does not work for multi-file validation, as the fileName is overwritten
for (ValidatedFragment validatedFragment : validatedFragments) {
ValidationOutcome outcome = new ValidationOutcome();
FileInfo fileInfo = new FileInfo(
validatedFragment.getFilename(),
new String(validatedFragment.getContent()),
validatedFragment.getExtension());
outcome.setMessages(validatedFragment.getErrors());
outcome.setFileInfo(fileInfo);
response.addOutcome(outcome);
}
//TODO the code below works correctly for multi-file validation.
/*
validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()),
request.getCliContext().getProfiles(), messages);
ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp);
messages.forEach(outcome::addMessage);
response.addOutcome(outcome);
*/
}
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
return response;