prettier fix
This commit is contained in:
@@ -11,15 +11,14 @@ import {
|
||||
getProviderInstitution,
|
||||
getSpecimen,
|
||||
} from '@/lib/templates/medipost-order';
|
||||
import {
|
||||
MaterjalideGrupp,
|
||||
} from '@/lib/types/medipost';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import { MaterjalideGrupp } from '@/lib/types/medipost';
|
||||
import { uniqBy } from 'lodash';
|
||||
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { AnalysisElement } from '../analysis-element.service';
|
||||
|
||||
import { AnalysesWithGroupsAndElements } from '../analyses.service';
|
||||
import { AnalysisElement } from '../analysis-element.service';
|
||||
|
||||
const USER = process.env.MEDIPOST_USER!;
|
||||
const RECIPIENT = process.env.MEDIPOST_RECIPIENT!;
|
||||
@@ -27,7 +26,7 @@ const RECIPIENT = process.env.MEDIPOST_RECIPIENT!;
|
||||
export type OrderedAnalysisElement = {
|
||||
analysisElementId?: number;
|
||||
analysisId?: number;
|
||||
}
|
||||
};
|
||||
|
||||
export async function composeOrderXML({
|
||||
analyses,
|
||||
@@ -63,24 +62,32 @@ export async function composeOrderXML({
|
||||
);
|
||||
|
||||
// First, collect all unique materials across all analysis groups
|
||||
const uniqueMaterials = new Map<string, {
|
||||
MaterjaliTyypOID: string;
|
||||
MaterjaliTyyp: string;
|
||||
MaterjaliNimi: string;
|
||||
ProovinouKoodOID?: string;
|
||||
ProovinouKood?: string;
|
||||
order: number;
|
||||
}>();
|
||||
const uniqueMaterials = new Map<
|
||||
string,
|
||||
{
|
||||
MaterjaliTyypOID: string;
|
||||
MaterjaliTyyp: string;
|
||||
MaterjaliNimi: string;
|
||||
ProovinouKoodOID?: string;
|
||||
ProovinouKood?: string;
|
||||
order: number;
|
||||
}
|
||||
>();
|
||||
|
||||
let specimenOrder = 1;
|
||||
|
||||
// Collect all materials from all analysis groups
|
||||
for (const currentGroup of analysisGroups) {
|
||||
let relatedAnalysisElements = analysisElements?.filter(({ analysis_groups }) => analysis_groups.id === currentGroup.id);
|
||||
let relatedAnalysisElements = analysisElements?.filter(
|
||||
({ analysis_groups }) => analysis_groups.id === currentGroup.id,
|
||||
);
|
||||
|
||||
if (!relatedAnalysisElements || relatedAnalysisElements.length === 0) {
|
||||
relatedAnalysisElements = analyses
|
||||
.filter(({ analysis_elements }) => analysis_elements.analysis_groups.id === currentGroup.id)
|
||||
.filter(
|
||||
({ analysis_elements }) =>
|
||||
analysis_elements.analysis_groups.id === currentGroup.id,
|
||||
)
|
||||
.flatMap(({ analysis_elements }) => analysis_elements);
|
||||
}
|
||||
|
||||
@@ -91,7 +98,9 @@ export async function composeOrderXML({
|
||||
}
|
||||
|
||||
for (const analysisElement of relatedAnalysisElements) {
|
||||
for (const { Materjal } of analysisElement.material_groups as MaterjalideGrupp[]) {
|
||||
for (const {
|
||||
Materjal,
|
||||
} of analysisElement.material_groups as MaterjalideGrupp[]) {
|
||||
for (const material of toArray(Materjal)) {
|
||||
const { MaterjaliTyyp } = material;
|
||||
|
||||
@@ -115,7 +124,7 @@ export async function composeOrderXML({
|
||||
}
|
||||
|
||||
// Generate specimen section from unique materials
|
||||
const specimenSection = Array.from(uniqueMaterials.values()).map(material =>
|
||||
const specimenSection = Array.from(uniqueMaterials.values()).map((material) =>
|
||||
getSpecimen(
|
||||
material.MaterjaliTyypOID,
|
||||
material.MaterjaliTyyp,
|
||||
@@ -123,7 +132,7 @@ export async function composeOrderXML({
|
||||
material.order,
|
||||
material.ProovinouKoodOID,
|
||||
material.ProovinouKood,
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
// Generate analysis section with correct specimen references
|
||||
@@ -135,7 +144,10 @@ export async function composeOrderXML({
|
||||
|
||||
if (!relatedAnalysisElements) {
|
||||
relatedAnalysisElements = analyses
|
||||
.filter(({ analysis_elements }) => analysis_elements.analysis_groups.id === currentGroup.id)
|
||||
.filter(
|
||||
({ analysis_elements }) =>
|
||||
analysis_elements.analysis_groups.id === currentGroup.id,
|
||||
)
|
||||
.flatMap(({ analysis_elements }) => analysis_elements);
|
||||
}
|
||||
|
||||
@@ -146,8 +158,8 @@ export async function composeOrderXML({
|
||||
}
|
||||
|
||||
const uuringElementInputs: {
|
||||
analysisElement: Tables<{ schema: 'medreport' }, 'analysis_elements'>,
|
||||
specimenOrderNr: number,
|
||||
analysisElement: Tables<{ schema: 'medreport' }, 'analysis_elements'>;
|
||||
specimenOrderNr: number;
|
||||
}[] = [];
|
||||
for (const analysisElement of relatedAnalysisElements) {
|
||||
for (const group of analysisElement.material_groups as MaterjalideGrupp[]) {
|
||||
@@ -155,7 +167,9 @@ export async function composeOrderXML({
|
||||
for (const material of materials) {
|
||||
const uniqueMaterial = uniqueMaterials.get(material.MaterjaliTyyp);
|
||||
if (!uniqueMaterial) {
|
||||
console.info(`Unique material not found for material: ${material.MaterjaliTyyp}, analysis element: ${analysisElement.id} ${analysisElement.analysis_id_original} ${analysisElement.analysis_name_lab}`);
|
||||
console.info(
|
||||
`Unique material not found for material: ${material.MaterjaliTyyp}, analysis element: ${analysisElement.id} ${analysisElement.analysis_id_original} ${analysisElement.analysis_name_lab}`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
uuringElementInputs.push({
|
||||
@@ -177,7 +191,7 @@ export async function composeOrderXML({
|
||||
|
||||
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, "OL")}
|
||||
${getPais(USER, RECIPIENT, orderId, 'OL')}
|
||||
<Tellimus cito="EI">
|
||||
<ValisTellimuseId>${orderId}</ValisTellimuseId>
|
||||
${getClientInstitution()}
|
||||
|
||||
Reference in New Issue
Block a user