Skip to content

Commit 4db999b

Browse files
authored
Add more stats (#3)
* Add tracing * update
1 parent 08b7885 commit 4db999b

File tree

18 files changed

+382
-216
lines changed

18 files changed

+382
-216
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jquery = "3.2.1"
1111
hapiFhir = "6.8.0"
1212
hapiFhirCore = "6.0.22"
1313
jackson = "2.13.5"
14-
jacksonCore = "2.15.2"
14+
jacksonCore = "2.18.0"
1515
slf4j = "2.0.12"
1616
okhttp = "4.9.1"
1717
coroutines = "1.2.1"

server/src/main/kotlin/org/dtree/fhir/server/controller/StatsController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.dtree.fhir.server.controller
22

3-
import org.dtree.fhir.server.services.FacilityResultData
4-
import org.dtree.fhir.server.services.StatsService
3+
import org.dtree.fhir.server.services.stats.FacilityResultData
4+
import org.dtree.fhir.server.services.stats.StatsService
55
import org.koin.core.component.KoinComponent
66
import org.koin.core.component.inject
77

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.dtree.fhir.server.controller
2+
3+
import org.dtree.fhir.server.services.tracing.AppointmentListResults
4+
import org.dtree.fhir.server.services.tracing.TracingService
5+
import org.dtree.fhir.server.services.tracing.TracingStatsResults
6+
import org.koin.core.component.KoinComponent
7+
import org.koin.core.component.inject
8+
import java.time.LocalDate
9+
10+
class TracingControllerImpl : TracingController, BaseController(), KoinComponent {
11+
private val tracingService by inject<TracingService>()
12+
override fun getStats(id: String): TracingStatsResults {
13+
return tracingService.getStats(id)
14+
}
15+
16+
override fun getAppointmentList(facilityId: String, date: LocalDate): AppointmentListResults {
17+
return tracingService.getAppointmentList(facilityId, date)
18+
}
19+
}
20+
21+
interface TracingController {
22+
fun getStats(id: String): TracingStatsResults
23+
24+
fun getAppointmentList(facilityId: String, date: LocalDate) : AppointmentListResults
25+
}

server/src/main/kotlin/org/dtree/fhir/server/core/models/FilterFormData.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.dtree.fhir.server.core.models
22

3+
import org.dtree.fhir.server.services.formatDate
34
import org.hl7.fhir.r4.model.Bundle
45
import java.time.LocalDate
56

@@ -25,7 +26,17 @@ data class FilterFormParamData(
2526
val value: String? = null,
2627
val valueDate: LocalDate? = null,
2728
val valueDateRange: DateRange? = null,
28-
)
29+
) {
30+
fun valueString(): String? {
31+
if (type == FilterParamType.string) {
32+
return value
33+
} else if (type == FilterParamType.date) {
34+
return valueDate?.let { formatDate(it, true) }
35+
} else {
36+
return valueDateRange?.toString()
37+
}
38+
}
39+
}
2940

3041
data class DateRange(
3142
val from: LocalDate?,

server/src/main/kotlin/org/dtree/fhir/server/core/search/filters/General.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ fun filterByDateCreated(dateCreated: LocalDate) = filterByPredefined(
2626
),
2727
)
2828

29+
fun filterByDate(date: LocalDate) = FilterFormItem(
30+
filterId = "filter-by-date-created",
31+
template = "date={date}",
32+
filterType = FilterTemplateType.template,
33+
params = listOf(
34+
FilterFormParamData(
35+
name = "date", type = FilterParamType.date, valueDate = date
36+
)
37+
),
38+
)
39+
2940
fun filterByDateCreatedRange(date: DateRange) = filterByPredefined(
3041
id = "filter-by-date-created-range",
3142
template = "filter-by-date-created-range",
@@ -53,6 +64,32 @@ fun filterSummary() = FilterFormItem(
5364
)
5465
)
5566

67+
fun filterAddCount(count: Int) = FilterFormItem(
68+
filterId = "_count",
69+
template = "_count={value}",
70+
filterType = FilterTemplateType.template,
71+
params = listOf(
72+
FilterFormParamData(
73+
name = "value",
74+
type = FilterParamType.string,
75+
value = count.toString()
76+
)
77+
)
78+
)
79+
80+
fun filterRevInclude() = FilterFormItem(
81+
filterId = "_include",
82+
template = "_include={value}",
83+
filterType = FilterTemplateType.template,
84+
params = listOf(
85+
FilterFormParamData(
86+
name = "value",
87+
type = FilterParamType.string,
88+
value = "Appointment:patient"
89+
)
90+
)
91+
)
92+
5693
fun addPatientFilter(patients: List<PatientType>, inSubject: Boolean = false): FilterFormItem {
5794
return FilterFormItem(
5895
filterId = "patient_filter",

server/src/main/kotlin/org/dtree/fhir/server/plugins/Routing.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.ktor.server.response.*
1212
import io.ktor.server.routing.*
1313
import io.ktor.server.routing.get
1414
import org.dtree.fhir.server.plugins.stats.statsModule
15+
import org.dtree.fhir.server.plugins.tracing.tracingModule
1516

1617
fun Application.configureRouting() {
1718
install(Resources)
@@ -45,6 +46,7 @@ fun Application.configureRouting() {
4546
}
4647

4748
statsModule()
49+
tracingModule()
4850

4951
get("/") {
5052
call.respondText("Hello, World!")

server/src/main/kotlin/org/dtree/fhir/server/plugins/injection/ModulesInjection.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import org.dtree.fhir.core.di.FhirProvider
55
import org.dtree.fhir.core.uploader.general.FhirClient
66
import org.dtree.fhir.server.controller.StatsController
77
import org.dtree.fhir.server.controller.StatsControllerImpl
8+
import org.dtree.fhir.server.controller.TracingController
9+
import org.dtree.fhir.server.controller.TracingControllerImpl
810
import org.koin.dsl.module
911

1012
object ModulesInjection {
1113
val koinBeans = module {
1214
single<StatsController> { StatsControllerImpl() }
15+
single<TracingController> { TracingControllerImpl() }
1316
single<FhirClient> { FhirClient(this.get<Dotenv>(), this.get<FhirProvider>().parser()) }
1417
}
1518
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.dtree.fhir.server.plugins.tracing
2+
3+
import io.ktor.resources.*
4+
import java.time.LocalDate
5+
6+
@Resource("/tracing")
7+
class Tracing() {
8+
@Resource("facility")
9+
class Facility(val parent: Tracing = Tracing()) {
10+
@Resource("{id}")
11+
class Id(val parent: Facility = Facility(), val id: String = "") {
12+
@Resource("appointments")
13+
class List(val parent: Id = Facility.Id(), val date: String? = "")
14+
}
15+
}
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.dtree.fhir.server.plugins.tracing
2+
3+
import io.ktor.server.application.*
4+
import io.ktor.server.resources.*
5+
import io.ktor.server.response.*
6+
import io.ktor.server.routing.*
7+
import org.dtree.fhir.server.controller.TracingController
8+
import org.koin.ktor.ext.inject
9+
import java.time.LocalDate
10+
import java.time.format.DateTimeFormatter
11+
12+
fun Route.tracingModule() {
13+
val controller by inject<TracingController>()
14+
15+
get<Tracing.Facility.Id> { facility ->
16+
val result = controller.getStats(facility.id)
17+
call.respond(result)
18+
}
19+
20+
get<Tracing.Facility.Id.List> { appointment ->
21+
println("Jeff")
22+
val formatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
23+
val result = controller.getAppointmentList(appointment.parent.id, if(appointment.date.isNullOrBlank()) LocalDate.now() else LocalDate.parse(appointment.date, formatter))
24+
call.respond(result)
25+
}
26+
}

0 commit comments

Comments
 (0)