From c9a8f2266cd551b7f89ce4168c8e0a1b98b577e9 Mon Sep 17 00:00:00 2001 From: Christopher Seven Phiri Date: Tue, 16 Jul 2024 14:19:31 +0200 Subject: [PATCH] update --- src/app/(dashboard)/stats/actions.ts | 6 ++++-- src/app/(dashboard)/stats/filters.ts | 4 ++-- src/app/(dashboard)/stats/model.ts | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/(dashboard)/stats/actions.ts b/src/app/(dashboard)/stats/actions.ts index d6602ac..a94501b 100644 --- a/src/app/(dashboard)/stats/actions.ts +++ b/src/app/(dashboard)/stats/actions.ts @@ -4,8 +4,7 @@ import { fetchBundle } from "@/lib/fhir/bundle"; import { LocationData, SummaryItem } from "@/lib/models/types"; import { FilterFormData } from "@/model/filters"; import { fhirR4 } from "@smile-cdr/fhirts"; -import { format } from "date-fns"; -import { QueryParam, fixDate } from "./model"; +import { fixDate } from "./model"; import { createPatientFilters, createQuestionnaireResponseFilters, @@ -34,7 +33,9 @@ export async function fetchData(formData: FormData) { let rawDate: string | null = null; const baseFilter = data.filters.map((filter) => { const temp: Record = {}; + if (filter.template == "_tag_location") { + console.log(filter); const template = `http://smartregister.org/fhir/location-tag|${ filter.params[0].value ?? "" }`; @@ -53,6 +54,7 @@ export async function fetchData(formData: FormData) { if (rawDate) { rawDate = fixDate(rawDate); } + const bundle = await fetchBundle([ createQuestionnaireResponseFilters( diff --git a/src/app/(dashboard)/stats/filters.ts b/src/app/(dashboard)/stats/filters.ts index cdeb610..c8e96a3 100644 --- a/src/app/(dashboard)/stats/filters.ts +++ b/src/app/(dashboard)/stats/filters.ts @@ -23,7 +23,7 @@ export const createQuestionnaireResponseFilters = ( query.remove("date"); if (date) { - query.set( + query.add( "_tag", `https://d-tree.org/fhir/created-on-tag|${format(date, "dd/MM/yyyy")}` ); @@ -44,7 +44,7 @@ export const createPatientFilters = ( query.remove("date"); if (date) { - query.set( + query.add( "_tag", `https://d-tree.org/fhir/created-on-tag|${format(date, "dd/MM/yyyy")}` ); diff --git a/src/app/(dashboard)/stats/model.ts b/src/app/(dashboard)/stats/model.ts index 35f40fd..eada71d 100644 --- a/src/app/(dashboard)/stats/model.ts +++ b/src/app/(dashboard)/stats/model.ts @@ -13,8 +13,10 @@ export class QueryParam { } add(key: string, value: any) { + console.log(key,this.queries.has(key) ); + if (this.queries.has(key)) { - this.queries.set(`${key}[${randomInt(100)}]`, value); + this.queries.set(`${key}[${Math.random()}]`, value); } else { this.queries.set(key, value); } @@ -46,9 +48,13 @@ export class QueryParam { for (const key in values) { this.from(values[key]); } + console.log(values); + console.log(this.queries); + } toUrl( resources: string,) { + console.log(this.queries); const query = Array.from(this.queries) .map(([key, value]) => { if (key.includes("[")) {