"This does not appear to be a FHIR resource" when validating Patient

866 views
Skip to first unread message

Gatoke

unread,
Sep 16, 2019, 3:26:20 AM9/16/19
to HAPI FHIR
Hello. I need to check if incoming Patient with profile https://www.fhir.org/guides/argonaut/r2/StructureDefinition-argo-patient.html is valid.

- I created a class which implements IValidationSupport
- I override "fetchResource" method which returns custom StructureDefinition from a file (https://www.fhir.org/guides/argonaut/r2/StructureDefinition-argo-patient.html).

(my JPA Server is configured for DSTU2, but I've made a simple mapper - ca.uhn Patient to org.hl7 Patient)

- When I receive request I am passing org.hl7 Patient to the validator

private ValidationResult validatePatient(final Patient patient) {
   
final FhirValidator fhirValidator = FhirContext.forDstu2Hl7Org().newValidator();
   
final FhirInstanceValidator fhirInstanceValidator = new FhirInstanceValidator(new MyValidationSupport());
    fhirValidator
.registerValidatorModule(fhirInstanceValidator);

   
return fhirValidator.validateWithResult(mapper.toHl7Org(patient));
}
Now the problem is - the whole method always returns false with a message "This does not appear to be a FHIR resource (unknown namespace/name 'http://hl7.org/fhir::Patient')".

I've tested it with random Patient from hapi test server and with official Argonaut example: https://www.fhir.org/guides/argonaut/r2/Patient-peter-chalmers.json

notafhirresource.png


Does anyone know what am I doing wrong?

James Agnew

unread,
Sep 16, 2019, 7:26:00 AM9/16/19
to Gatoke, HAPI FHIR
Hmm. I'm not sure where that error message is coming from..

You could try putting a breakpoint in the constructor(s) of the following class:
org.hl7.fhir.utilities.validation.ValidationMessage
This should help at least pinpoint that, and then you could work backwards to see why it's being generated.

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/4eb63c1a-0a08-4fb4-b003-329c7a9d3666%40googlegroups.com.

Avanti Sunil Kopulwar

unread,
Jun 18, 2020, 2:38:18 PM6/18/20
to HAPI FHIR
Hello,

I am also getting the similar error while validating the FHIR resource against the custom profile.

Can you please share the solution or your observation?

Thanks,
Avanti

fan yihui

unread,
Sep 20, 2020, 6:29:06 AM9/20/20
to HAPI FHIR
Hi

I have same problem when validate a resource against custom profile. Do you have the solution?

Regards,
Yihui

Elano

unread,
Dec 8, 2020, 8:12:55 AM12/8/20
to HAPI FHIR
Hi everybody,

does anyone know the solution of this problem? Zihui, did you find a way to solve this issue?

Thanks
Elano

Yuriy Flyud

unread,
Jan 9, 2021, 4:48:32 PM1/9/21
to HAPI FHIR

Adding this dependency helped me:
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
<version>${hapi_version}</version>
</dependency>

Marc Dumontier

unread,
Feb 23, 2021, 8:20:29 PM2/23/21
to HAPI FHIR

I added the dependency but I still get this error message when validating against a profile

--

This does not appear to be a FHIR resource (unknown namespace/name 'http://hl7.org/fhir::Patient')


Elano

unread,
Feb 24, 2021, 4:43:34 AM2/24/21
to HAPI FHIR
Hi Marc,

Here is the list of the dependencies (gradle) I am using:

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-base
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-base', version: '5.2.0'

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-client
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-client', version: '5.2.0'

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-structures-r4
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-r4', version: '5.2.0'

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-validation-resources-r4
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-validation-resources-r4', version: '5.2.0'

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-validation
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-validation', version: '5.2.0'

// https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/org.hl7.fhir.utilities
compile group: 'ca.uhn.hapi.fhir', name: 'org.hl7.fhir.utilities', version: '5.2.0'


for me, it is working now.

Marc Dumontier

unread,
Feb 24, 2021, 2:30:14 PM2/24/21
to HAPI FHIR
Thanks
I have the same set of packages via maven

The code is really just based on what's in the documentation..I'm using a downloaded profile XML I published to simplifier.net



FhirContext ctx = FhirContext.forR4();

IParser parser = ctx.newXmlParser();
StructureDefinition sd = (StructureDefinition) parser.parseResource(
new FileInputStream(new File("/home/marc/Downloads/MyPatient.StructureDefinition.xml")));
List<StructureDefinition> definitions = new ArrayList<StructureDefinition>();
definitions.add(sd);
IValidationSupport valSupport = new MyValidationSupport(ctx, definitions);

ValidationSupportChain validationSupportChain = new ValidationSupportChain(valSupport,
new InMemoryTerminologyServerValidationSupport(ctx), new CommonCodeSystemsTerminologyService(ctx));

FhirValidator validator = ctx.newValidator();
IValidatorModule module = new FhirInstanceValidator(validationSupportChain);

validator.registerValidatorModule(module);

// Pass a resource instance as input to be validated
Patient resource = new Patient();
resource.addName().setFamily("Simpson").addGiven("Homer");
ValidationResult result = validator.validateWithResult(resource);

System.out.println("validation result = " + result.isSuccessful());

for (SingleValidationMessage msg : result.getMessages()) {
System.out.println(msg.getMessage());
}

---

validation result = false
This does not appear to be a FHIR resource (unknown namespace/name 'http://hl7.org/fhir::Patient')

James Agnew

unread,
Feb 24, 2021, 2:50:41 PM2/24/21
to Marc Dumontier, HAPI FHIR
I notice in that code snippet you don't have DefaultProfileValidationSupport as a part of your chain. I don't know for sure that this is the cause, but it may help unless your custom provider is also serving up the base definitions.

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.

Marc Dumontier

unread,
Feb 24, 2021, 3:56:23 PM2/24/21
to HAPI FHIR
Thanks James

So for reference to anyone else in the future..here's a working snippet of the most basic profile validator for a profile downloaded from simplifier (messy code version :P)


public static void main(String[] args) throws Exception {
String profileSnapshotXml = "my-profile.xml";
String profileUrl = "http://my.profile.url/xx";
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newXmlParser();

StructureDefinition sd = (StructureDefinition) parser.parseResource(
new FileInputStream(new File(profileSnapshotXml)));
PrePopulatedValidationSupport prePopulatedValidationSupport = new PrePopulatedValidationSupport(ctx);
prePopulatedValidationSupport.addStructureDefinition(sd);
ValidationSupportChain validationSupportChain = 
new ValidationSupportChain(new DefaultProfileValidationSupport(ctx), prePopulatedValidationSupport);
FhirValidator validator = ctx.newValidator();
validator.registerValidatorModule(new FhirInstanceValidator(validationSupportChain));
Patient resource = new Patient();
resource.addName().setFamily("Simpson").addGiven("Homer");
resource.getMeta().addProfile(profileUrl);
ValidationResult result = validator.validateWithResult(resource);

IParser jParser = ctx.newJsonParser().setPrettyPrint(true);
System.out.println(jParser.encodeResourceToString(validator.validateWithResult(resource).toOperationOutcome()));
}

Andrey Pismenetsky

unread,
Jan 31, 2022, 5:46:15 AM1/31/22
to HAPI FHIR
Good day. I am working with R4 validation against my test structure definition at the moment. The structure definition is at the simplifier.net.  There is an example in 12.2.3 Running the Validator part of HAPI FHIR documentation. According to this snippets I can add my profile to ValidationOptions object and then call validateWithResult method. I.e.:

/*
 * Note: You can also explicitly declare a profile to validate against
 * using the block below.
 */
// ValidationResult result = validator.validateWithResult(obs, new ValidationOptions().addProfile("https://fhir.simplifier.net/…/StructureDefinition/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"));

But this part of the code is under comment. What does it mean ?  Does it mean that this approach is wrong  and it is  better to use Marc's approach ?
Kind regards
Andrii

среда, 24 февраля 2021 г. в 22:56:23 UTC+2, Marc Dumontier:
Reply all
Reply to author
Forward
0 new messages