add medreport schema
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use server'
|
||||
|
||||
'use server';
|
||||
|
||||
import logRequestResult from '@/lib/services/audit.service';
|
||||
import { RequestStatus } from '@/lib/types/audit';
|
||||
import {
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
ConnectedOnlineMethodName,
|
||||
} from '@/lib/types/connected-online';
|
||||
import { ExternalApi } from '@/lib/types/external';
|
||||
import { Tables } from '@/supabase/database.types';
|
||||
import { Tables } from '@/packages/supabase/src/database.types';
|
||||
import { createClient } from '@/utils/supabase/server';
|
||||
import axios from 'axios';
|
||||
|
||||
@@ -106,11 +106,13 @@ export async function bookAppointment(
|
||||
{ data: dbService, error: serviceError },
|
||||
] = await Promise.all([
|
||||
supabase
|
||||
.schema('medreport')
|
||||
.from('connected_online_providers')
|
||||
.select('*')
|
||||
.eq('id', clinicId)
|
||||
.limit(1),
|
||||
supabase
|
||||
.schema('medreport')
|
||||
.from('connected_online_services')
|
||||
.select('*')
|
||||
.eq('sync_id', serviceSyncId)
|
||||
@@ -132,8 +134,14 @@ export async function bookAppointment(
|
||||
);
|
||||
}
|
||||
|
||||
const clinic: Tables<'connected_online_providers'> = dbClinic![0];
|
||||
const service: Tables<'connected_online_services'> = dbService![0];
|
||||
const clinic: Tables<
|
||||
{ schema: 'medreport' },
|
||||
'connected_online_providers'
|
||||
> = dbClinic![0];
|
||||
const service: Tables<
|
||||
{ schema: 'medreport' },
|
||||
'connected_online_services'
|
||||
> = dbService![0];
|
||||
|
||||
// TODO the dummy data needs to be replaced with real values once they're present on the user/account
|
||||
const response = await axios.post(
|
||||
@@ -183,6 +191,7 @@ export async function bookAppointment(
|
||||
const responseParts = responseData.Value.split(',');
|
||||
|
||||
const { error } = await supabase
|
||||
.schema('medreport')
|
||||
.from('connected_online_reservation')
|
||||
.insert({
|
||||
booking_code: responseParts[1],
|
||||
|
||||
@@ -32,6 +32,7 @@ import { toArray } from '@/lib/utils';
|
||||
import axios from 'axios';
|
||||
import { XMLParser } from 'fast-xml-parser';
|
||||
import { uniqBy } from 'lodash';
|
||||
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
const BASE_URL = process.env.MEDIPOST_URL!;
|
||||
@@ -196,6 +197,7 @@ async function saveAnalysisGroup(
|
||||
supabase: SupabaseClient,
|
||||
) {
|
||||
const { data: insertedAnalysisGroup, error } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_groups')
|
||||
.upsert(
|
||||
{
|
||||
@@ -215,13 +217,14 @@ async function saveAnalysisGroup(
|
||||
const analysisGroupId = insertedAnalysisGroup[0].id;
|
||||
|
||||
const analysisGroupCodes = toArray(analysisGroup.Kood);
|
||||
const codes: Partial<Tables<'codes'>>[] = analysisGroupCodes.map((kood) => ({
|
||||
hk_code: kood.HkKood,
|
||||
hk_code_multiplier: kood.HkKoodiKordaja,
|
||||
coefficient: kood.Koefitsient,
|
||||
price: kood.Hind,
|
||||
analysis_group_id: analysisGroupId,
|
||||
}));
|
||||
const codes: Partial<Tables<{ schema: 'medreport' }, 'codes'>>[] =
|
||||
analysisGroupCodes.map((kood) => ({
|
||||
hk_code: kood.HkKood,
|
||||
hk_code_multiplier: kood.HkKoodiKordaja,
|
||||
coefficient: kood.Koefitsient,
|
||||
price: kood.Hind,
|
||||
analysis_group_id: analysisGroupId,
|
||||
}));
|
||||
|
||||
const analysisGroupItems = toArray(analysisGroup.Uuring);
|
||||
|
||||
@@ -229,6 +232,7 @@ async function saveAnalysisGroup(
|
||||
const analysisElement = item.UuringuElement;
|
||||
|
||||
const { data: insertedAnalysisElement, error } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.upsert(
|
||||
{
|
||||
@@ -270,6 +274,7 @@ async function saveAnalysisGroup(
|
||||
if (analyses?.length) {
|
||||
for (const analysis of analyses) {
|
||||
const { data: insertedAnalysis, error } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analyses')
|
||||
.upsert(
|
||||
{
|
||||
@@ -310,6 +315,7 @@ async function saveAnalysisGroup(
|
||||
}
|
||||
|
||||
const { error: codesError } = await supabase
|
||||
.schema('medreport')
|
||||
.from('codes')
|
||||
.upsert(codes, { ignoreDuplicates: false });
|
||||
|
||||
@@ -404,34 +410,41 @@ export async function composeOrderXML(
|
||||
};
|
||||
|
||||
const { data: analysisElements } = (await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.select(`*, analysis_groups(*)`)
|
||||
.in('id', orderedElements)) as {
|
||||
data: ({
|
||||
analysis_groups: Tables<'analysis_groups'>;
|
||||
} & Tables<'analysis_elements'>)[];
|
||||
analysis_groups: Tables<{ schema: 'medreport' }, 'analysis_groups'>;
|
||||
} & Tables<{ schema: 'medreport' }, 'analysis_elements'>)[];
|
||||
};
|
||||
const { data: analyses } = (await supabase
|
||||
.schema('medreport')
|
||||
.from('analyses')
|
||||
.select(`*, analysis_elements(*, analysis_groups(*))`)
|
||||
.in('id', orderedAnalyses)) as {
|
||||
data: ({
|
||||
analysis_elements: Tables<'analysis_elements'> & {
|
||||
analysis_groups: Tables<'analysis_groups'>;
|
||||
analysis_elements: Tables<
|
||||
{ schema: 'medreport' },
|
||||
'analysis_elements'
|
||||
> & {
|
||||
analysis_groups: Tables<{ schema: 'medreport' }, 'analysis_groups'>;
|
||||
};
|
||||
} & Tables<'analyses'>)[];
|
||||
} & Tables<{ schema: 'medreport' }, 'analyses'>)[];
|
||||
};
|
||||
|
||||
const analysisGroups: Tables<'analysis_groups'>[] = uniqBy(
|
||||
(
|
||||
analysisElements?.flatMap(({ analysis_groups }) => analysis_groups) ?? []
|
||||
).concat(
|
||||
analyses?.flatMap(
|
||||
({ analysis_elements }) => analysis_elements.analysis_groups,
|
||||
) ?? [],
|
||||
),
|
||||
'id',
|
||||
);
|
||||
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
||||
uniqBy(
|
||||
(
|
||||
analysisElements?.flatMap(({ analysis_groups }) => analysis_groups) ??
|
||||
[]
|
||||
).concat(
|
||||
analyses?.flatMap(
|
||||
({ analysis_elements }) => analysis_elements.analysis_groups,
|
||||
) ?? [],
|
||||
),
|
||||
'id',
|
||||
);
|
||||
|
||||
const specimenSection = [];
|
||||
const analysisSection = [];
|
||||
@@ -545,6 +558,7 @@ export async function syncPrivateMessage(
|
||||
const status = response.TellimuseOlek;
|
||||
|
||||
const { data: analysisOrder, error: analysisOrderError } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_orders')
|
||||
.select('user_id')
|
||||
.eq('id', response.ValisTellimuseId);
|
||||
@@ -556,6 +570,7 @@ export async function syncPrivateMessage(
|
||||
}
|
||||
|
||||
const { data: analysisResponse, error } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
.upsert(
|
||||
{
|
||||
@@ -576,7 +591,7 @@ export async function syncPrivateMessage(
|
||||
const analysisGroups = toArray(response.UuringuGrupp);
|
||||
|
||||
const responses: Omit<
|
||||
Tables<'analysis_response_elements'>,
|
||||
Tables<{ schema: 'medreport' }, 'analysis_response_elements'>,
|
||||
'id' | 'created_at' | 'updated_at'
|
||||
>[] = [];
|
||||
for (const analysisGroup of analysisGroups) {
|
||||
@@ -608,6 +623,7 @@ export async function syncPrivateMessage(
|
||||
}
|
||||
|
||||
const { error: deleteError } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_response_elements')
|
||||
.delete()
|
||||
.eq('analysis_response_id', analysisResponse[0].id);
|
||||
@@ -619,6 +635,7 @@ export async function syncPrivateMessage(
|
||||
}
|
||||
|
||||
const { error: elementInsertError } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_response_elements')
|
||||
.insert(responses);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user