Conditional creates based on name and DOB

18 views
Skip to first unread message

Jordan Force

unread,
Oct 31, 2022, 4:55:53 PM10/31/22
to HAPI FHIR
Hi,

I'm using HAPI, and I'm trying to do conditional creates, where the condition (that prevents the create) is exact matching of first name, last name and date of birth. This is to prevent duplicates; it may not be the best way, but it's what we're going to do for now at least.

Anyways, I've come to this:

MethodOutcome outcome = client.create()
.resource(patient)
.conditional()
.where(Patient.NAME.matchesExactly().value(patient.getName().get(0).getGivenAsSingleString()))
.where(Patient.NAME.matchesExactly().value(patient.getName().get(0).getFamily()))
.where(Patient.BIRTHDATE.exactly().day(patient.getBirthDate()))
.prettyPrint()
.encodedJson()
.execute();

This sort of works -- if I try to insert Bob Smith with birthdate 1999-12-14 multiple times, it only shows up once. But if I insert Bob Smith and Smith Bob, only Bob Smith is created. This isn't suprising, since the code doesn't indicate to the value function that it wants to match to the Patient's first or last name (since getFamily() and getGivenAsSingleString() only return strings, there would be no way to do this). How can I get the conditional create to match specifically on first name and last name separately?

Thanks,

Jordan

James Agnew

unread,
Oct 31, 2022, 5:07:32 PM10/31/22
to Jordan Force, HAPI FHIR
You probably want to use the FAMILY and GIVEN search parameters instead of the NAME parameter, that's the root of the problem here.

One other thought - This will work as-is if you aren't worried about concurrency, which is fine if you control the client. If you need to defend against people concurrently creating the same record, you may also want to add a composite unique searchparameter in order to enforce uniqueness for your combination.

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/b8597165-4b47-4ee4-9879-18e32c9262dbn%40googlegroups.com.

Jordan Force

unread,
Oct 31, 2022, 5:34:41 PM10/31/22
to HAPI FHIR
Oh, I didn't notice those parameters. Thanks!
Reply all
Reply to author
Forward
0 new messages