feat(MED-161): create analysis-order service
This commit is contained in:
17
lib/services/analysis-order.service.ts
Normal file
17
lib/services/analysis-order.service.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { getSupabaseServerAdminClient } from "@/packages/supabase/src/clients/server-admin-client";
|
||||||
|
import type { AnalysisResponseElement } from "../types/analysis-response-element";
|
||||||
|
|
||||||
|
export async function getExistingAnalysisResponseElements({
|
||||||
|
analysisResponseId,
|
||||||
|
}: {
|
||||||
|
analysisResponseId: number;
|
||||||
|
}) {
|
||||||
|
const { data } = await getSupabaseServerAdminClient()
|
||||||
|
.schema('medreport')
|
||||||
|
.from('analysis_response_elements')
|
||||||
|
.select('*')
|
||||||
|
.eq('analysis_response_id', analysisResponseId)
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
return data as AnalysisResponseElement[];
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import { composeOrderXML, OrderedAnalysisElement } from './medipostXML.service';
|
|||||||
import { getAccountAdmin } from '../account.service';
|
import { getAccountAdmin } from '../account.service';
|
||||||
import { logMedipostDispatch } from '../audit.service';
|
import { logMedipostDispatch } from '../audit.service';
|
||||||
import { MedipostValidationError } from './MedipostValidationError';
|
import { MedipostValidationError } from './MedipostValidationError';
|
||||||
|
import { getExistingAnalysisResponseElements } from '../analysis-order.service';
|
||||||
|
|
||||||
const BASE_URL = process.env.MEDIPOST_URL!;
|
const BASE_URL = process.env.MEDIPOST_URL!;
|
||||||
const USER = process.env.MEDIPOST_USER!;
|
const USER = process.env.MEDIPOST_USER!;
|
||||||
@@ -152,14 +153,9 @@ export async function syncPrivateMessage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: allOrderResponseElements } = await supabase
|
const existingAnalysisResponseElements = await getExistingAnalysisResponseElements({ analysisResponseId });
|
||||||
.schema('medreport')
|
|
||||||
.from('analysis_response_elements')
|
|
||||||
.select('*')
|
|
||||||
.eq('analysis_response_id', analysisResponseId)
|
|
||||||
.throwOnError();
|
|
||||||
const expectedOrderResponseElements = order.analysis_element_ids?.length ?? 0;
|
const expectedOrderResponseElements = order.analysis_element_ids?.length ?? 0;
|
||||||
if (allOrderResponseElements.length !== expectedOrderResponseElements) {
|
if (existingAnalysisResponseElements.length !== expectedOrderResponseElements) {
|
||||||
return { isPartial: true };
|
return { isPartial: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
lib/types/analysis-response-element.ts
Normal file
3
lib/types/analysis-response-element.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import type { Database } from "@/packages/supabase/src/database.types";
|
||||||
|
|
||||||
|
export type AnalysisResponseElement = Database['medreport']['Tables']['analysis_response_elements']['Row'];
|
||||||
Reference in New Issue
Block a user