prettier fix
This commit is contained in:
@@ -8,14 +8,13 @@ import {
|
||||
getPatient,
|
||||
getProviderInstitution,
|
||||
} from '@/lib/templates/medipost-order';
|
||||
import {
|
||||
MedipostAction,
|
||||
} from '@/lib/types/medipost';
|
||||
import { MedipostAction } from '@/lib/types/medipost';
|
||||
import axios from 'axios';
|
||||
import { formatDate } from 'date-fns';
|
||||
import { uniqBy } from 'lodash';
|
||||
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { formatDate } from 'date-fns';
|
||||
|
||||
import { getAnalyses } from '../analyses.service';
|
||||
import { getAnalysisElementsAdmin } from '../analysis-element.service';
|
||||
import { validateMedipostResponse } from './medipostValidate.service';
|
||||
@@ -71,7 +70,9 @@ export async function composeOrderTestResponseXML({
|
||||
orderId: number;
|
||||
orderCreatedAt: Date;
|
||||
}) {
|
||||
const analysisElements = await getAnalysisElementsAdmin({ ids: orderedAnalysisElementsIds });
|
||||
const analysisElements = await getAnalysisElementsAdmin({
|
||||
ids: orderedAnalysisElementsIds,
|
||||
});
|
||||
const analyses = await getAnalyses({ ids: orderedAnalysesIds });
|
||||
|
||||
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
||||
@@ -94,13 +95,15 @@ export async function composeOrderTestResponseXML({
|
||||
const orderNumber = orderId;
|
||||
|
||||
const allAnalysisElementsForGroups = analysisElements?.filter((element) => {
|
||||
return analysisGroups.some((group) => group.id === element.analysis_groups.id);
|
||||
return analysisGroups.some(
|
||||
(group) => group.id === element.analysis_groups.id,
|
||||
);
|
||||
});
|
||||
const addedIds = new Set<number>();
|
||||
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Saadetis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TellimusLOINC.xsd">
|
||||
${getPais(USER, RECIPIENT, orderId, "AL")}
|
||||
${getPais(USER, RECIPIENT, orderId, 'AL')}
|
||||
<Vastus>
|
||||
<ValisTellimuseId>${orderId}</ValisTellimuseId>
|
||||
${getClientInstitution({ index: 1 })}
|
||||
@@ -126,38 +129,54 @@ export async function composeOrderTestResponseXML({
|
||||
<TellimuseNumber>${orderNumber}</TellimuseNumber>
|
||||
|
||||
<TellimuseOlek>${orderStatus}</TellimuseOlek>
|
||||
${allAnalysisElementsForGroups.map((analysisElement) => {
|
||||
const group = analysisGroups.find((group) => group.id === analysisElement.analysis_groups.id);
|
||||
if (!group) {
|
||||
throw new Error(`Failed to find group for analysis element ${analysisElement.id}`);
|
||||
}
|
||||
${allAnalysisElementsForGroups
|
||||
.map((analysisElement) => {
|
||||
const group = analysisGroups.find(
|
||||
(group) => group.id === analysisElement.analysis_groups.id,
|
||||
);
|
||||
if (!group) {
|
||||
throw new Error(
|
||||
`Failed to find group for analysis element ${analysisElement.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
let relatedAnalysisElement = analysisElements?.find(
|
||||
(element) => element.analysis_groups.id === group.id && !addedIds.has(element.id),
|
||||
);
|
||||
const relatedAnalyses = analyses?.filter((analysis) => {
|
||||
return analysis.analysis_elements.analysis_groups.id === group.id && !addedIds.has(analysis.analysis_elements.id);
|
||||
});
|
||||
let relatedAnalysisElement = analysisElements?.find(
|
||||
(element) =>
|
||||
element.analysis_groups.id === group.id &&
|
||||
!addedIds.has(element.id),
|
||||
);
|
||||
const relatedAnalyses = analyses?.filter((analysis) => {
|
||||
return (
|
||||
analysis.analysis_elements.analysis_groups.id === group.id &&
|
||||
!addedIds.has(analysis.analysis_elements.id)
|
||||
);
|
||||
});
|
||||
|
||||
if (!relatedAnalysisElement) {
|
||||
relatedAnalysisElement = relatedAnalyses?.find(
|
||||
(relatedAnalysis) =>
|
||||
relatedAnalysis.analysis_elements.analysis_groups.id ===
|
||||
group.id,
|
||||
)?.analysis_elements;
|
||||
}
|
||||
if (!relatedAnalysisElement) {
|
||||
relatedAnalysisElement = relatedAnalyses?.find(
|
||||
(relatedAnalysis) =>
|
||||
relatedAnalysis.analysis_elements.analysis_groups.id ===
|
||||
group.id,
|
||||
)?.analysis_elements;
|
||||
}
|
||||
|
||||
if (!relatedAnalysisElement || !relatedAnalysisElement.material_groups) {
|
||||
throw new Error(
|
||||
`Failed to find related analysis element for group ${group.name} (id: ${group.id})`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
!relatedAnalysisElement ||
|
||||
!relatedAnalysisElement.material_groups
|
||||
) {
|
||||
throw new Error(
|
||||
`Failed to find related analysis element for group ${group.name} (id: ${group.id})`,
|
||||
);
|
||||
}
|
||||
|
||||
const lower = getRandomInt(0, 100);
|
||||
const upper = getRandomInt(lower + 1, 500);
|
||||
const result = getRandomInt(lower - Math.floor(lower * 0.1), upper + Math.floor(upper * 0.1));
|
||||
addedIds.add(relatedAnalysisElement.id);
|
||||
return (`
|
||||
const lower = getRandomInt(0, 100);
|
||||
const upper = getRandomInt(lower + 1, 500);
|
||||
const result = getRandomInt(
|
||||
lower - Math.floor(lower * 0.1),
|
||||
upper + Math.floor(upper * 0.1),
|
||||
);
|
||||
addedIds.add(relatedAnalysisElement.id);
|
||||
return `
|
||||
<UuringuGrupp>
|
||||
<UuringuGruppId>${group.original_id}</UuringuGruppId>
|
||||
<UuringuGruppNimi>${group.name}</UuringuGruppNimi>
|
||||
@@ -177,15 +196,16 @@ export async function composeOrderTestResponseXML({
|
||||
<VastuseAeg>${formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')}</VastuseAeg>
|
||||
<NormYlem kaasaarvatud=\"EI\">${upper}</NormYlem>
|
||||
<NormAlum kaasaarvatud=\"EI\">${lower}</NormAlum>
|
||||
<NormiStaatus>${result < lower ? 1 : (result > upper ? 1 : 0)}</NormiStaatus>
|
||||
<NormiStaatus>${result < lower ? 1 : result > upper ? 1 : 0}</NormiStaatus>
|
||||
<ProoviJarjenumber>1</ProoviJarjenumber>
|
||||
</UuringuVastus>
|
||||
</UuringuElement>
|
||||
<UuringuTaitjaAsutuseJnr>2</UuringuTaitjaAsutuseJnr>
|
||||
</Uuring>
|
||||
</UuringuGrupp>
|
||||
`);
|
||||
}).join('')}
|
||||
`;
|
||||
})
|
||||
.join('')}
|
||||
</Vastus>
|
||||
</Saadetis>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user