hapi-fhir-cli upload examples command giving an error

672 views Asked by At

I'm trying to upload test data to the local JPA fhir server using hapi-fhir-cli. But while uploading the resources, I'm getting the following error.

2020-09-03 17:33:26.486 [main] INFO c.u.f.c.ExampleDataUploader 1 good references
2020-09-03 17:33:26.511 [main] INFO c.u.f.c.ExampleDataUploader Final bundle: 18 entries
2020-09-03 17:33:26.527 [main] INFO c.u.f.c.ExampleDataUploader About to upload 11 examples in a transaction, 2 remaining
2020-09-03 17:33:26.637 [main] INFO c.u.f.c.ExampleDataUploader Final bundle: 62 KB
2020-09-03 17:33:26.641 [main] INFO c.u.f.c.ExampleDataUploader Uploading bundle to server: http://127.0.0.1:8080/hapi-fhir-jpaserver/fhir
2020-09-03 17:33:26.960 [main] ERROR c.u.f.c.ExampleDataUploader Failed to upload bundle:HTTP 0: Failed to retrieve the server metadata statement during client initialization. URL used was http://127.0.0.1:8080/hapi-fhir-jpaserver/fhir/metadata

Even if I replace http://127.0.0.1:8080/hapi-fhir-jpaserver/fhir/metadata by public hapi fhir test server, i.e. http://hapi.fhir.org/baseR4, I'm getting the same error. I'm getting the above error after running the following hapi-fhir-cli command.

hapi-fhir-5.1.0-cli>hapi-fhir-cli upload-examples -t http://127.0.0.1:8080/hapi-fhir-jpaserver/fhir -v dstu2 -l 40

If I change the version to dstu3 or r4, I get the validation error, i.e. bundle type=transaction not found in valueset defined at hl7 website, even if it's defined.

Does anyone have any idea about both of these errors? Any help would be appreciated. Thanks.

1

There are 1 answers

0
granadaCoder On

Can you show where you are creating your client code (please).

But the two suggestions I have:

Are you setting the FhirContext to the right version? Do you need a bearer token?

//import ca.uhn.fhir.context.FhirContext;

private FhirContext getContext() {
    return FhirContext.forR4();
}

Note, creating the context (the call to "forR4" is expensive, so you want to minimize the number of times you call that).

//// import ca.uhn.fhir.rest.client.api.IGenericClient;

private IGenericClient generateIGenericClient(FhirContext fhirContext, GenericClientCreateArgs createArgs) {
    IGenericClient client = fhirContext.newRestfulGenericClient(createArgs.getServerBase());
    if (null != createArgs && createArgs.getBearerToken().isPresent()) {
        String token = createArgs.getBearerToken().get();
        if (StringUtils.isNotBlank(token)) {
            BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(token);
            client.registerInterceptor(authInterceptor);
        }
    }

    return client;
}

and my "args" holder class:

import java.util.Optional;

public final class GenericClientCreateArgs {

    private String serverBase;

    private Optional<String> bearerToken;

    public String getServerBase() {
        return serverBase;
    }

    public void setServerBase(String serverBase) {
        this.serverBase = serverBase;
    }

    public Optional<String> getBearerToken() {
        return bearerToken;
    }

    public void setBearerToken(Optional<String> bearerToken) {
        this.bearerToken = bearerToken;
    }
}