node
12/20/2023, 5:21 PM_filter option as:
Resource?_filter=extension ni {url}
But I get an error
Unknown search parameter: 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 an unknown search parameter {search-param-name} error.rahul1
12/21/2023, 12:00 AMrahul1
12/21/2023, 12:00 AMrahul1
12/21/2023, 8:12 AMrahul1
12/21/2023, 6:09 PMnode
12/21/2023, 10:48 PMts
import { BotEvent, MedplumClient } from '@medplum/core';
import { Communication, Subscription } from '@medplum/fhirtypes';
import Sentiment from 'sentiment';
const sentiment = new Sentiment();
const SENTIMENT_EXTENSION_URL = 'http://example.com/extensions/sentiment';
export const subscription: Subscription = {
resourceType: 'Subscription',
reason: 'Communication sentiment analysis',
status: 'active',
criteria: `Communication`,
extension: [
{
// https://www.medplum.com/docs/subscriptions/subscription-extensions#expression-based-criteria
url: 'https://medplum.com/fhir/StructureDefinition/fhir-path-criteria-expression',
valueString: `not %previous.extension.exists(url = "${SENTIMENT_EXTENSION_URL}")`,
},
],
};
export async function handler(medplum: MedplumClient, event: BotEvent<Communication>): Promise<any> {
const communication = event.input;
const content = communication.payload?.at(0)?.contentString;
if (!content) {
return;
}
const extension = communication.extension ?? [];
const sentimentExt = extension.some((ext) => ext.url === SENTIMENT_EXTENSION_URL);
if (sentimentExt) {
return;
}
// possibly find & filter by patient language depending on your sentiment analysis implementations language support
const sentiment = await getSentiment(content);
await medplum.updateResource({
...communication,
extension: extension.concat({
url: SENTIMENT_EXTENSION_URL,
valueString: JSON.stringify(sentiment),
}),
});
}
const getSentiment = async (message: string): Promise<{ score: number; comparative: number }> => {
return sentiment.analyze(message);
};
Although, I suppose a more appropriate check would be if the previous payload content string is different than the current so sentiment can be reanalyzed on content change (assuming the client allowed it)rahul1
12/22/2023, 8:58 PMCommunications that don't a sentiment extension present ?node
12/22/2023, 9:14 PMkhonlieu
05/22/2024, 5:55 PMreshma
05/22/2024, 10:18 PM