'FHIR validation with Schematron in Android
I am trying to create a simple android application which will be used to validate FHIR resources. I am trying to use and implement the code provided by hapi fhir found below using Schema/Schematron Validator:
https://hapifhir.io/hapi-fhir/docs/validation/schema_validator.html
The issue here is that I am trying to run the exact same code given in the example end I get an IllegalArgumentException.
My code is this:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Patient p = new Patient();
p.addName().setFamily("Smith").addGiven("John").addGiven("Q");
p.addIdentifier().setSystem("urn:foo:identifiers").setValue("12345");
p.addTelecom().setSystem(ContactPoint.ContactPointSystem.PHONE).setValue("416 123-4567");
validateResource(p);
}
private void validateResource(Patient patient) {
FhirContext ctx = FhirContext.forR4();
FhirValidator val = ctx.newValidator();
IValidatorModule module1 = new SchemaBaseValidator(ctx);
IValidatorModule module2 = new SchematronBaseValidator(ctx);
val.registerValidatorModule(module1);
val.registerValidatorModule(module2);
ValidationResult result = val.validateWithResult(patient);
if (result.isSuccessful()) {
System.out.println("Validation passed");
} else {
// We failed validation!
System.out.println("Validation failed");
}
}
}
Which is the same code as used in the example. However I get the following error.
E/AndroidRuntime: FATAL EXCEPTION: main Process: fhirvalidation, PID: 2365 java.lang.RuntimeException: Unable to start activity ComponentInfo{fhirvalidation/fhirvalidation.MainActivity}: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5456) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5362) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:58) at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5415) at android.app.ActivityThread.access$3300(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2076) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:192) at ca.uhn.fhir.validation.SchemaBaseValidator.loadSchema(SchemaBaseValidator.java:125) at ca.uhn.fhir.validation.SchemaBaseValidator.doValidate(SchemaBaseValidator.java:76) at ca.uhn.fhir.validation.SchemaBaseValidator.validateResource(SchemaBaseValidator.java:168) at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:219) at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:186) at fhirvalidation.MainActivity.validateResource(MainActivity.java:48) at fhirvalidation.MainActivity.onCreate(MainActivity.java:32) at android.app.Activity.performCreate(Activity.java:8000) at android.app.Activity.performCreate(Activity.java:7984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5456) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5362) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:58) at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5415) at android.app.ActivityThread.access$3300(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2076) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) I/Process: Sending signal. PID: 2365 SIG: 9
Is there something obvious I am missing? Because I can't figure something out. Any hint would be useful, thank you!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
