Repository Validating Interceptor

582 views
Skip to first unread message

Ashwini Patil

unread,
Sep 1, 2021, 5:21:22 AM9/1/21
to HAPI FHIR
Hi,

I override the  RepositoryValidatingInterceptor to enable custom validation against the profiles.

But when I test it using the post data which is:
{
   "resourceType": "Patient",
     "meta": {
      "profile": [
      ]
   },
   "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n\t\t\t<p>Patient Donald D DUCK @ Acme Healthcare, Inc. MR = 123456</p>\n\t\t</div>"
  },
   "name": [ {
"family": "Jameson",
"given": [ "J", "Jonah" ]
} ]
}


It throws me an error:
issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "Profile reference 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient' has not been checked because it is unknown, and the validator is set to not fetch unknown profiles",
            "location": [
                "Patient.meta.profile[0]",
                "Line 1, Col 2"
            ]
        }
    ]


Please help me.

Thanks & Regards,
Ashwini Patil

Nayan Jain

unread,
Sep 27, 2021, 8:57:09 AM9/27/21
to HAPI FHIR
are you able to resolve this , If yes how ?

Baptiste Guilbert

unread,
Aug 2, 2022, 5:13:08 AM8/2/22
to HAPI FHIR
Hi,
I have the same problem, has anyone managed to resolve it?

Paul Jones

unread,
Aug 2, 2022, 7:16:21 AM8/2/22
to HAPI FHIR
If you are using the JpaRestfulServer, the factory class is loading its profile references (to StructureDefinition resources) from the database (using its resource dao).

It is unlikely that you have loaded the default profile resources.

Typically the meta.profile value references a SD that derives from the default definitions (applying one or more custom constraints).

Paul

Message has been deleted

Baptiste Guilbert

unread,
Aug 2, 2022, 12:06:58 PM8/2/22
to HAPI FHIR
Hi Paul, thank you for your answer.
Yes indeed, I use the JpaRestfulServer !
As you say, it doesn't seem to load the resource profiles, so what is missing to make it work?

Thank you for your help, I am new to HAPI FHIR. 

-------------------------------------------------------------------------------------------

package ca.uhn.fhir.jpa.starter;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.interceptor.validation.IRepositoryValidatingRule;
import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingInterceptor;
import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingRuleBuilder;

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.ValidationSupportChain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;

@Import(AppProperties.class)
public class JpaRestfulServer extends BaseJpaRestfulServer {

    @Autowired
    AppProperties appProperties;

    @Autowired
    CareTeamProvider provider;

    @Autowired
    RepositoryValidatingRuleBuilder ruleBuilder;

    private static final long serialVersionUID = 1L;

    public JpaRestfulServer() {
        super();
    }

    @Override
    protected void initialize() throws ServletException {
        super.initialize();
        registerProvider(provider);
        FhirContext context = getFhirContext();
        NpmPackageValidationSupport npmPackageValidationSupport = new NpmPackageValidationSupport(context);

        try {
            npmPackageValidationSupport.loadPackageFromClasspath("classpath:Package/hl7-france-fhir.administrative-11.2021.1.tgz");
            npmPackageValidationSupport.loadPackageFromClasspath("classpath:Package/ans.annuaire.fhir.r4-0.2.0.tgz");
            //npmPackageValidationSupport.loadPackageFromClasspath("classpath:Package/hl7.fhir.us.core-5.0.1.tgz");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        npmPackageValidationSupport.fetchAllConformanceResources();

        ValidationSupportChain validationSupportChain = new ValidationSupportChain(npmPackageValidationSupport);
        CachingValidationSupport validationSupport = new CachingValidationSupport(validationSupportChain);
        context.setValidationSupport(validationSupport);

// Add a simple rule requiring all Patient resources to declare conformance to the US Core
// Patient Profile, and to validate successfully.
        ruleBuilder
            .forResourcesOfType("Patient")
            .requireAtLeastProfile("http://interopsante.org/fhir/StructureDefinition/FrPatient")
            //.requireAtLeastProfile("http://hl7.org/fhir/us/core/StructureDefinition-us-core-patient.html")
            .and()
            .requireValidationToDeclaredProfiles();

// Build the rule list
        List<IRepositoryValidatingRule> rules = ruleBuilder.build();

// Create and register the interceptor
        RepositoryValidatingInterceptor interceptor = new RepositoryValidatingInterceptor(context, rules);
        registerInterceptor(interceptor);
    }

}

Paul Jones

unread,
Aug 2, 2022, 1:19:45 PM8/2/22
to Baptiste Guilbert, HAPI FHIR
ok, a couple of things:

First I'm not sure you need to be writing code to enable npm- and repository-based validation: both are available via configuration.

To enable repository validation, set this application.yaml property: 
hapi.fhir.enable_repository_validating_interceptor: true

To store and install a custom profile (e.g., hl7-france-fhir.administrative-11.2021.1.tgz), set these properties:
hapi:
  fhir:
    implementationguides:
       france-fhir-admin:
          url:  classpath:Package/hl7-france-fhir.administrative-11.2021.1.tgz
          name: <look in package.json>
          version: <look in package.json>

The profile will load on server startup, store package artifacts in both binary and fhir resource representations, and should be available for meta.profile referencing.

Let me know if you have any questions, it does not work for you, etc.

Paul


--
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/37ed9cda-6a27-4979-b6b3-f0102910fd75n%40googlegroups.com.


--

Paul Jones

Senior Developer

About Objects

240-388-5113
paul....@aboutobjects.com

Baptiste Guilbert

unread,
Aug 5, 2022, 4:45:28 AM8/5/22
to HAPI FHIR
Hi Paul,

Ok thank you, I'll test your solution.
Thanks for your explanation

John díaz

unread,
Jan 7, 2023, 12:12:08 PM1/7/23
to HAPI FHIR
Hi, I can't get the server to validate resources that have a meta profile, I turned on repository validation and inserted the implementation guide into the yaml. Do I require additional configuration?
Reply all
Reply to author
Forward
0 new messages