mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-09 14:31:17 +00:00
WIP return validation fragments
This commit is contained in:
parent
14e6f210e6
commit
ef6f92a21e
@ -51,4 +51,7 @@ public class ValidatedFragment {
|
||||
return name+"."+extension;
|
||||
}
|
||||
|
||||
public String getExtension() {
|
||||
return extension;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user