Created
August 22, 2022 17:10
-
-
Save joergreichert/8d0c714cfb2d3c5a7eef1bdc0e9be097 to your computer and use it in GitHub Desktop.
Reproduce endless loop during erezeptabrechnungsdaten validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ca.uhn.fhir.context.FhirContext; | |
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; | |
import ca.uhn.fhir.validation.FhirValidator; | |
import de.abda.fhir.validator.core.support.IgnoreMissingValueSetValidationSupport; | |
import org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport; | |
import org.hl7.fhir.common.hapi.validation.support.NpmPackageValidationSupport; | |
import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport; | |
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; | |
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; | |
import org.hl7.fhir.r4.model.Bundle; | |
import org.junit.jupiter.api.Test; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.net.URLConnection; | |
public class MemoryBugReproduceTest { | |
@Test | |
public void testMemory() throws IOException { | |
FhirContext fhirContext = FhirContext.forR4(); | |
NpmPackageValidationSupport npmPackageSupport = new NpmPackageValidationSupport(fhirContext); | |
// download via npm --registry https://packages.simplifier.net install de.gkvsv.eRezeptAbrechnungsdaten@1.2.0 | |
// or download via https://simplifier.net/packages/de.gkvsv.erezeptabrechnungsdaten/1.2.0/download (requires free login) | |
npmPackageSupport.loadPackageFromClasspath("classpath:package/de.gkvsv.erezeptabrechnungsdaten-1.2.0.tgz"); | |
ValidationSupportChain validationSupportChain = new ValidationSupportChain( | |
npmPackageSupport, | |
new DefaultProfileValidationSupport(fhirContext), | |
new SnapshotGeneratingValidationSupport(fhirContext), | |
new IgnoreMissingValueSetValidationSupport(fhirContext) | |
); | |
CachingValidationSupport validationSupport = new CachingValidationSupport(validationSupportChain); | |
FhirInstanceValidator instanceValidator = new FhirInstanceValidator(validationSupport); | |
instanceValidator.setAnyExtensionsAllowed(false); | |
instanceValidator.setNoTerminologyChecks(false); | |
FhirValidator fhirValidator = new FhirValidator(fhirContext); | |
fhirValidator.registerValidatorModule(instanceValidator); | |
URLConnection urlcon = new URL("https://raw.githubusercontent.com/DAV-ABDA/eRezept-Beispiele/main/Freitext-Verordnung/Freitext-Verordnung_V1/FT_V1_TA7_Sammelrechnung_Bundle.xml").openConnection(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(urlcon.getInputStream())); | |
StringBuilder sb = new StringBuilder(); | |
String i; | |
while ((i = br.readLine()) != null) { | |
sb.append(i).append("\n"); | |
} | |
var content = sb.toString(); | |
var iParser = FhirContext.forR4().newXmlParser().setPrettyPrint(true); | |
var bundle = iParser.parseResource(Bundle.class, content); | |
fhirValidator.validateWithResult(bundle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will end in