admin管理员组

文章数量:1297118

I have small app with Springboot WebFlux on OpenJDK 23. HAPI - FHIR Client to get Patient FHIR R4 resource. Here is the pom.xml

        <!-- HAPI FHIR JPA Server Dependency -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-client-okhttp</artifactId>
            <version>6.2.5</version>
        </dependency>
        <!-- Jackson for JSON parsing -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <!-- HAPI FHIR R4 Dependency -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r4</artifactId>
            <version>6.2.5</version>
        </dependency>

And here is the method which make the FHIR API Call, getPatient(), and createFhirClient() returns the fhirClient.

public Mono<Patient> getPatient() {
        return Mono.deferContextual(context -> {
            String labViewStateId = context.get(Constant.REQUEST_STATE_ID);
            return cacheManager.get(labViewStateId, SmartApp.class)
                    .flatMap(smartApp -> {
                        if (smartApp == null) {
                            return Mono.error(new IllegalArgumentException("Invalid Application ID"));
                        }
                        IGenericClient fhirClient = createFhirClient(smartApp);
                        return Mono.fromCallable(() -> fhirClient.read()
                                .resource(Patient.class)
                                .withId(smartApp.getAuthToken().getPatientIdentifier())
                                .execute());
                    });
        });
    }

private IGenericClient createFhirClient(SmartApp smartApp) {
        IGenericClient fhirClient = fhirContext.newRestfulGenericClient(smartApp.getIssuer());
        fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(smartApp.getAuthToken().getAccessToken()));
        fhirClient.registerInterceptor(new LoggingInterceptor(true));
        
        return fhirClient;
    }

This code always errors with below details, any clue where the problem is? I tested with four different FHIR endpoint all fails with error except , but this is just sandbox or sample from HAPI.

      at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
Caused by: com.fasterxml.jackson.core.exc.StreamConstraintsException: Document nesting depth (1001) exceeds the maximum allowed (1000, from `StreamWriteConstraints.getMaxNestingDepth()`)
        at com.fasterxml.jackson.core.StreamWriteConstraints._constructException(StreamWriteConstraints.java:177) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.core.StreamWriteConstraints.validateNestingDepth(StreamWriteConstraints.java:162) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeStartArray(UTF8JsonGenerator.java:347) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.impl.IndexedStringListSerializer.serialize(IndexedStringListSerializer.java:76) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.impl.IndexedStringListSerializer.serialize(IndexedStringListSerializer.java:22) ~[jackson-databind-2.18.2.jar:2.18.2]
        ... 1019 common frames omitted

I have small app with Springboot WebFlux on OpenJDK 23. HAPI - FHIR Client to get Patient FHIR R4 resource. Here is the pom.xml

        <!-- HAPI FHIR JPA Server Dependency -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-client-okhttp</artifactId>
            <version>6.2.5</version>
        </dependency>
        <!-- Jackson for JSON parsing -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <!-- HAPI FHIR R4 Dependency -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r4</artifactId>
            <version>6.2.5</version>
        </dependency>

And here is the method which make the FHIR API Call, getPatient(), and createFhirClient() returns the fhirClient.

public Mono<Patient> getPatient() {
        return Mono.deferContextual(context -> {
            String labViewStateId = context.get(Constant.REQUEST_STATE_ID);
            return cacheManager.get(labViewStateId, SmartApp.class)
                    .flatMap(smartApp -> {
                        if (smartApp == null) {
                            return Mono.error(new IllegalArgumentException("Invalid Application ID"));
                        }
                        IGenericClient fhirClient = createFhirClient(smartApp);
                        return Mono.fromCallable(() -> fhirClient.read()
                                .resource(Patient.class)
                                .withId(smartApp.getAuthToken().getPatientIdentifier())
                                .execute());
                    });
        });
    }

private IGenericClient createFhirClient(SmartApp smartApp) {
        IGenericClient fhirClient = fhirContext.newRestfulGenericClient(smartApp.getIssuer());
        fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(smartApp.getAuthToken().getAccessToken()));
        fhirClient.registerInterceptor(new LoggingInterceptor(true));
        
        return fhirClient;
    }

This code always errors with below details, any clue where the problem is? I tested with four different FHIR endpoint all fails with error except https://hapi.fhir./baseR4, but this is just sandbox or sample from HAPI.

      at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:184) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:732) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.18.2.jar:2.18.2]
Caused by: com.fasterxml.jackson.core.exc.StreamConstraintsException: Document nesting depth (1001) exceeds the maximum allowed (1000, from `StreamWriteConstraints.getMaxNestingDepth()`)
        at com.fasterxml.jackson.core.StreamWriteConstraints._constructException(StreamWriteConstraints.java:177) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.core.StreamWriteConstraints.validateNestingDepth(StreamWriteConstraints.java:162) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeStartArray(UTF8JsonGenerator.java:347) ~[jackson-core-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.impl.IndexedStringListSerializer.serialize(IndexedStringListSerializer.java:76) ~[jackson-databind-2.18.2.jar:2.18.2]
        at com.fasterxml.jackson.databind.ser.impl.IndexedStringListSerializer.serialize(IndexedStringListSerializer.java:22) ~[jackson-databind-2.18.2.jar:2.18.2]
        ... 1019 common frames omitted
Share Improve this question asked Feb 12 at 6:07 Hi10Hi10 5411 gold badge5 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
  1. List item

Instead of returning direct output of .execute() method, the Patient object output is returned and that resolved the error.

public Mono<AppPatient> getPatient() {
    return Mono.deferContextual(context -> {
        String labViewStateId = context.get(Constant.REQUEST_STATE_ID);
        return cacheService.get(labViewStateId, SmartApp.class).cast(SmartApp.class)
                .flatMap(smartApp -> {
                    if (smartApp == null) {
                        return Mono.error(new IllegalArgumentException("Invalid Application ID"));
                    }
                    IGenericClient fhirClient = createFhirClient(smartApp);
                    return Mono.fromCallable(() -> {
                        Patient patient = fhirClient.read()
                                .resource(Patient.class)
                                .withId(smartApp.getAuthToken().getPatientIdentifier())
                                .execute();
                        AppPatient appPatient = PatientProcessor.convertToAppPatient(patient);
                        return appPatient;
                    });
                });

    });
}

本文标签: