feat(MED-131): update analyses on package logic
This commit is contained in:
@@ -9,10 +9,8 @@ export type AnalysisElement = Tables<{ schema: 'medreport' }, 'analysis_elements
|
||||
|
||||
export async function getAnalysisElements({
|
||||
originalIds,
|
||||
ids,
|
||||
}: {
|
||||
originalIds?: string[];
|
||||
ids?: number[];
|
||||
}): Promise<AnalysisElement[]> {
|
||||
const query = getSupabaseServerClient()
|
||||
.schema('medreport')
|
||||
@@ -24,11 +22,35 @@ export async function getAnalysisElements({
|
||||
query.in('analysis_id_original', [...new Set(originalIds)]);
|
||||
}
|
||||
|
||||
const { data: analysisElements, error } = await query;
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Failed to get analysis elements: ${error.message}`);
|
||||
}
|
||||
|
||||
return analysisElements ?? [];
|
||||
}
|
||||
|
||||
export async function getAnalysisElementsAdmin({
|
||||
ids,
|
||||
}: {
|
||||
ids?: number[];
|
||||
} = {}): Promise<AnalysisElement[]> {
|
||||
const query = getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.select(`*, analysis_groups(*)`)
|
||||
.order('order', { ascending: true });
|
||||
|
||||
if (Array.isArray(ids)) {
|
||||
query.in('id', ids);
|
||||
}
|
||||
|
||||
const { data: analysisElements } = await query;
|
||||
const { data: analysisElements, error } = await query;
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Failed to get analysis elements: ${error.message}`);
|
||||
}
|
||||
|
||||
return analysisElements ?? [];
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import { Tables } from '@kit/supabase/database';
|
||||
import { createAnalysisGroup } from './analysis-group.service';
|
||||
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
||||
import { getOrder } from './order.service';
|
||||
import { getAnalysisElements } from './analysis-element.service';
|
||||
import { getAnalysisElementsAdmin } from './analysis-element.service';
|
||||
import { getAnalyses } from './analyses.service';
|
||||
|
||||
const BASE_URL = process.env.MEDIPOST_URL!;
|
||||
@@ -407,7 +407,7 @@ export async function composeOrderXML({
|
||||
orderCreatedAt: Date;
|
||||
comment?: string;
|
||||
}) {
|
||||
const analysisElements = await getAnalysisElements({ ids: orderedAnalysisElementsIds });
|
||||
const analysisElements = await getAnalysisElementsAdmin({ ids: orderedAnalysisElementsIds });
|
||||
const analyses = await getAnalyses({ ids: orderedAnalysesIds });
|
||||
|
||||
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
||||
|
||||
@@ -16,7 +16,7 @@ import { uniqBy } from 'lodash';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { formatDate } from 'date-fns';
|
||||
import { getAnalyses } from './analyses.service';
|
||||
import { getAnalysisElements } from './analysis-element.service';
|
||||
import { getAnalysisElementsAdmin } from './analysis-element.service';
|
||||
import { validateMedipostResponse } from './medipost.service';
|
||||
|
||||
const BASE_URL = process.env.MEDIPOST_URL!;
|
||||
@@ -70,7 +70,7 @@ export async function composeOrderTestResponseXML({
|
||||
orderId: string;
|
||||
orderCreatedAt: Date;
|
||||
}) {
|
||||
const analysisElements = await getAnalysisElements({ ids: orderedAnalysisElementsIds });
|
||||
const analysisElements = await getAnalysisElementsAdmin({ ids: orderedAnalysisElementsIds });
|
||||
const analyses = await getAnalyses({ ids: orderedAnalysesIds });
|
||||
|
||||
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
||||
|
||||
Reference in New Issue
Block a user