Skip to content

Commit

Permalink
feat: initial mtb domains, pages etc + initial type refactoring + fix…
Browse files Browse the repository at this point in the history
… page schema generation
  • Loading branch information
tada5hi committed Jan 3, 2024
1 parent becfa81 commit 2befba6
Show file tree
Hide file tree
Showing 40 changed files with 714 additions and 86 deletions.
20 changes: 20 additions & 0 deletions packages/core/src/domains/query/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { ObjectLiteral } from '../../types';
import type { Coding } from '../coding';
import type { PatientFilter } from '../patient';
import type { MinMaxRange } from '../utility';

export type ConceptCount<CONCEPT = any> = {
concept: CONCEPT,
count: number
};

export type ConceptsCount<CONCEPT = any> = ConceptCount<CONCEPT>[];

export type DiagnosisFilter = {
category?: Coding[],
Expand Down Expand Up @@ -35,3 +43,15 @@ export type QueryBase<
expiresAfter: number,
lastUpdate: string
};

export type QuerySummaryDemographics = {
siteDistribution: ConceptsCount<Coding>,
genderDistribution: ConceptsCount<Coding>,
ageDistribution: ConceptsCount<MinMaxRange>,
};

export type QuerySummaryBase = {
id: string,
patientCount: number,
demographics: QuerySummaryDemographics
};
25 changes: 4 additions & 21 deletions packages/kit/src/core/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
encodePath,
joinURL,
withLeadingSlash,
withTrailingSlash,
withoutLeadingSlash,
withoutTrailingSlash,
} from 'ufo';
import { SegmentTokenType } from './constants';
Expand All @@ -32,6 +30,8 @@ export async function generateNuxtPages(context: NuxtPagesGenerateContext) : Pro
b,
) => a.relativePath.localeCompare(b.relativePath));

const prefix = withoutTrailingSlash(context.prefix);

const routes: NuxtPage[] = [];

for (let i = 0; i < files.length; i++) {
Expand All @@ -42,8 +42,8 @@ export async function generateNuxtPages(context: NuxtPagesGenerateContext) : Pro
.split('/');

const route: NuxtPage = {
name: '',
path: '',
name: prefix,
path: prefix,
file: file.absolutePath,
children: [],
};
Expand Down Expand Up @@ -78,20 +78,8 @@ export async function generateNuxtPages(context: NuxtPagesGenerateContext) : Pro
parent.push(route);
}

const prefix = withoutTrailingSlash(context.prefix);

return prepareRoutes({
routes,
names: new Set<string>(),
}).map((route) => {
if (route.name) {
route.name = withoutLeadingSlash(withTrailingSlash(context.prefix))
.replaceAll('/', '-') + route.name;
}

route.path = `${prefix}/${withoutLeadingSlash(route.path)}`;

return route;
});
}

Expand All @@ -116,7 +104,6 @@ function prepareRoutes(context : RoutesPrepareContext) {
route.children = prepareRoutes({
routes: route.children,
parent: route,
names: context.names,
});
}

Expand All @@ -129,10 +116,6 @@ function prepareRoutes(context : RoutesPrepareContext) {
}
}

if (route.name) {
context.names.add(route.name);
}

context.routes[i] = route;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/core/pages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ export type NuxtPagesGenerateContext = {

export type RoutesPrepareContext = {
routes: NuxtPage[],
parent?: NuxtPage,
names: Set<string>
parent?: NuxtPage
};
Empty file removed packages/mtb/src/domains/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions packages/mtb/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { register } from '@dnpm-dip/kit';
import {
addImportsSources, addPlugin, createResolver,
defineNuxtModule,
} from '@nuxt/kit';

Expand All @@ -13,6 +14,8 @@ export default defineNuxtModule<ModuleOptions>({
},
defaults: {},
async setup(_options, _nuxt) {
const resolver = createResolver(import.meta.url);

await register({
name: 'MTB',
baseURL: '/mtb/',
Expand All @@ -34,5 +37,12 @@ export default defineNuxtModule<ModuleOptions>({
],
navigationTopId: 'mtb',
});

addImportsSources({
from: resolver.resolve('./runtime/composables/index'),
imports: ['useAPIClient', 'useMTBAPIClient'],
});

addPlugin(resolver.resolve('./runtime/plugins/api'));
},
});
Empty file removed packages/mtb/src/pages/.gitkeep
Empty file.
42 changes: 42 additions & 0 deletions packages/mtb/src/runtime/components/core/MQuerySummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { URLQueryRecord } from '@dnpm-dip/core';
import {
createResourceRecordManager,
} from '@dnpm-dip/core';
import type { PropType } from 'vue';
import { defineComponent, toRef } from 'vue';
import { useMTBAPIClient } from '#imports';

export default defineComponent({
props: {
queryId: {
type: String,
required: true,
},
queryRecord: {
type: Object as PropType<URLQueryRecord>,
},
lazy: {
type: Boolean,
default: false,
},
},
async setup(props, setup) {
const apiClient = useMTBAPIClient();
const id = toRef(props, 'queryId');

const manager = createResourceRecordManager({
load: (id) => apiClient.query.getSummary(id, props.queryRecord),
slots: setup.slots,
id,
});

if (props.lazy) {
Promise.resolve()
.then(() => manager.load());
} else {
await manager.load();
}

return () => manager.render();
},
});
147 changes: 147 additions & 0 deletions packages/mtb/src/runtime/components/core/MSearchForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<script lang="ts">
import type { CodeSystemConcept, ValueSetCoding } from '@dnpm-dip/core';
import {
QueryRequestMode,
} from '@dnpm-dip/core';
import type { FormSelectOption } from '@vuecs/form-controls';
import type { PropType } from 'vue';
import {
defineComponent, ref,
} from 'vue';
import { useMTBAPIClient } from '#imports';
export default defineComponent({
props: {
queryId: {
type: String,
},
queryMode: {
type: String as PropType<QueryRequestMode>,
},
},
emits: [
'failed',
'preparedQueryCreated',
'preparedQueryUpdated',
'queryCreated',
'queryUpdated',
],
async setup(props, { emit, expose }) {
const apiClient = useMTBAPIClient();
const mode = ref<QueryRequestMode>(QueryRequestMode.FEDERATED);
const modeOptions : FormSelectOption[] = [
{ id: QueryRequestMode.LOCAL, value: 'Lokal' },
{ id: QueryRequestMode.FEDERATED, value: 'Föderiert' },
];
const busy = ref(false);
const reset = async () => {
if (busy.value) return;
busy.value = true;
busy.value = false;
};
expose({
reset,
});
Promise.resolve()
.then(() => reset());
const submit = async () => {
if (busy.value) return;
busy.value = true;
const payload = {};
try {
let query : any;
if (props.queryId) {
query = await apiClient.query.update(props.queryId, {
criteria: payload,
mode: {
code: mode.value,
},
});
emit('queryUpdated', query);
} else {
query = await apiClient.query.submit({
criteria: payload,
mode: {
code: mode.value,
},
});
emit('queryCreated', query);
}
} catch (e) {
if (e instanceof Error) {
emit('failed', e);
}
} finally {
busy.value = false;
}
};
const transformCodings = (coding: ValueSetCoding) => ({
id: coding.code,
value: coding.display ? `${coding.code}: ${coding.display}` : coding.code,
});
const transformConcepts = (concept: CodeSystemConcept) => ({
id: concept.code,
value: `${concept.properties.Symbol}: ${concept.display}`,
});
return {
mode,
modeOptions,
busy,
submit,
};
},
});
</script>
<template>
<div>
<form>
<div>
<h6>Suchmodus</h6>

<VCFormSelect
v-model="mode"
:options="modeOptions"
:option-default="false"
/>
</div>

<hr>

<div>
<div class="row">
<div class="col">
<button
:disabled="busy"
type="button"
class="btn btn-block btn-dark"
@click.prevent="submit()"
>
<i class="fa fa-search me-1" /> Suchen
</button>
</div>
</div>
</div>
</form>
</div>
</template>
10 changes: 10 additions & 0 deletions packages/mtb/src/runtime/composables/api-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { APIClient } from '@dnpm-dip/core';
import { useNuxtApp } from '#imports';
import type { MTBAPIClient } from '../core/api-client';

export function useAPIClient() {
return useNuxtApp().$api as APIClient;
}
export function useMTBAPIClient() {
return useNuxtApp().$mtbApi as MTBAPIClient;
}
4 changes: 4 additions & 0 deletions packages/mtb/src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
useAPIClient,
useMTBAPIClient,
} from './api-client';
1 change: 1 addition & 0 deletions packages/mtb/src/runtime/core/api-client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './module';
12 changes: 12 additions & 0 deletions packages/mtb/src/runtime/core/api-client/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { APIClient } from '@dnpm-dip/core';
import {
QueryAPI,
} from '../../domains';

export class MTBAPIClient {
readonly query : QueryAPI;

constructor(client: APIClient) {
this.query = new QueryAPI({ client });
}
}
1 change: 1 addition & 0 deletions packages/mtb/src/runtime/domains/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './query';
Loading

0 comments on commit 2befba6

Please sign in to comment.