FHIR Chat · Need help with create request · hapi

Stream: hapi

Topic: Need help with create request


view this post on Zulip Olivia Bellamou-Huet (Jan 04 2021 at 14:15):

Hi,
I created my first client and my first server running locally. The server can correctly process the requests sent from Postman for creating and searching patients. The client can create a new patient in the server http://hapi.fhir.org/baseR4. But when I try to have my client create a new patient in my server (http://localhost:9999) I get the following error message:

Invalid request: The FHIR endpoint on this server does not know how to handle GET operation[Patient/metadata] with parameters [[]].

What I do in the client:

FhirContext ctx = FhirContext.forR4();
IGenericClient client = ctx.newRestfulGenericClient("http://localhost:9999/Patient");

Patient newPatient = new Patient();
newPatient.addName().setFamily("Green").addGiven("Marc");
newPatient.addIdentifier().setSystem("http://acme.org/mrns").setValue("456456");
newPatient.setGender(Enumerations.AdministrativeGender.MALE);

MethodOutcome outcome = client.create().resource(newPatient).prettyPrint().encodedXml().execute();

And in the server:

@Create()
public MethodOutcome createPatient(@ResourceParam Patient thePatient) {
    FhirContext ctxV4 = FhirContext.forR4();
    ctxV4.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
    IGenericClient clientHAPI = ctxV4.newRestfulGenericClient("http://hapi.fhir.org/baseR4");
    MethodOutcome outcome = clientHAPI.create().resource(thePatient).execute();
    return outcome;
}

Do you know what I am doing wrong or missing?

Thanks a lot!

view this post on Zulip Oliver Egger (Jan 04 2021 at 14:43):

for the client you need to provide the FHIR endpoint, I assume your server is running on http://localhost:9999? then you need to add ctx.newRestfulGenericClient("http://localhost:9999"); I guess.

view this post on Zulip Olivia Bellamou-Huet (Jan 04 2021 at 14:55):

Thanks @Oliver Egger . Yes the server is running on this port. Do you mean in addition to the line:

IGenericClient client = ctx.newRestfulGenericClient("http://localhost:9999/Patient");

?

view this post on Zulip Oliver Egger (Jan 04 2021 at 15:05):

not in addition, you need to replace in the client ctx.newRestfulGenericClient("http://localhost:9999/Patient") with ctx.newRestfulGenericClient("http://localhost:9999")

view this post on Zulip Olivia Bellamou-Huet (Jan 04 2021 at 15:19):

Thank you very much, that solved the problem indeed!


Last updated: Apr 12 2022 at 19:14 UTC