node
12/19/2023, 3:30 PMnode
12/19/2023, 4:20 PMisNotModified check is preventing an update loop https://github.com/medplum/medplum/blob/38c20342ec77c1c01ad718dace4432c72bf7ad7d/packages/server/src/fhir/repo.ts#L506-L512
However, there is still an unnecessary reinvokation of the Bot which no-ops
Depending on how quickly the reinvoking of the Bot occurs, an error will be encountered with too many versions.rahul1
12/19/2023, 7:44 PMnode
12/19/2023, 7:45 PMts
import { BotEvent, MedplumClient } from '@medplum/core';
import { Communication } from '@medplum/fhirtypes';
export async function handler(medplum: MedplumClient, event: BotEvent<Communication>): Promise<boolean> {
const communication = event.input;
const content = communication.payload?.at(0)?.contentString;
if (!content) {
return true;
}
const sentimentExt = communication.extension?.find((e) => e.url === 'sentiment');
if (sentimentExt) {
return true;
}
const extension = communication.extension ?? [];
const sentiment = await getSentiment(content);
await medplum.updateResource({
...communication,
extension: extension.concat({ url: 'sentiment', valueString: JSON.stringify(sentiment) }),
});
return true;
}
const getSentiment = async (message: string): Promise<{ magnitude: number; score: number }> => {
// TODO: implement
return {
magnitude: Math.random(),
score: message.length,
};
};
If BotEvent<T> exposed the subscription id that triggered it, the updateResource could take an optional list of subscriptions to not trigger as part of the update.
Assuming it's supported, another option is to specify a more detailed subscription criteria for this bot that omits Communicaions which already have a sentiment extension. This would provide less "colocation" but seems reasonable.rahul1
12/19/2023, 7:45 PMencounter propertyrahul1
12/19/2023, 7:46 PMnode
12/19/2023, 9:27 PMcriteria: 'Communication?encounter:missing=true'rahul1
12/19/2023, 10:16 PMnode
12/20/2023, 3:45 PM_filter option as:
Communication?_filter=extension ni {url}
But I get an error
Unknown search paramter: extension
Wasn't have much success searching existing support items or docs for searching/querying by extension
I wonder if this is a use case for a custom SearchParameter? I tried setting one up but am getting unknown search parameter.rahul1
12/20/2023, 5:19 PMnode
12/20/2023, 5:21 PM