feat(MED-168): keep medipost response data unique, no need for duplicate rows
This commit is contained in:
@@ -18,16 +18,32 @@ export async function getExistingAnalysisResponseElements({
|
||||
return data as AnalysisResponseElement[];
|
||||
}
|
||||
|
||||
export async function createAnalysisResponseElement({
|
||||
export async function upsertAnalysisResponseElement({
|
||||
element,
|
||||
}: {
|
||||
element: Omit<AnalysisResponseElement, 'created_at' | 'updated_at' | 'id'>;
|
||||
}) {
|
||||
await getSupabaseServerAdminClient()
|
||||
const { data } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_response_elements')
|
||||
.insert(element)
|
||||
.upsert(
|
||||
element,
|
||||
{
|
||||
onConflict: 'analysis_response_id,analysis_element_original_id',
|
||||
ignoreDuplicates: false
|
||||
}
|
||||
)
|
||||
.select('id')
|
||||
.throwOnError();
|
||||
|
||||
const analysisResponseElementId = data?.[0]?.id;
|
||||
if (!analysisResponseElementId) {
|
||||
throw new Error(
|
||||
`Failed to insert or update analysis response element (response id: ${element.analysis_response_id}, element id: ${element.analysis_element_original_id})`
|
||||
);
|
||||
}
|
||||
|
||||
return { analysisResponseElementId };
|
||||
}
|
||||
|
||||
export async function upsertAnalysisResponse({
|
||||
|
||||
Reference in New Issue
Block a user