Skip to content

Commit

Permalink
lab report filtering is working.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Oct 3, 2023
1 parent 61528ac commit 74a3fd4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 14 deletions.
1 change: 1 addition & 0 deletions frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const routes: Routes = [
{ path: 'patient-profile', component: PatientProfileComponent, canActivate: [ IsAuthenticatedAuthGuard] },
{ path: 'medical-history', component: MedicalHistoryComponent, canActivate: [ IsAuthenticatedAuthGuard] },
{ path: 'labs', component: ReportLabsComponent, canActivate: [ IsAuthenticatedAuthGuard] },
{ path: 'labs/report/:source_id/:resource_type/:resource_id', component: ReportLabsComponent, canActivate: [ IsAuthenticatedAuthGuard] },

// { path: 'general-pages', loadChildren: () => import('./general-pages/general-pages.module').then(m => m.GeneralPagesModule) },
// { path: 'ui-elements', loadChildren: () => import('./ui-elements/ui-elements.module').then(m => m.UiElementsModule) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ <h1 class="az-dashboard-title">Observations</h1>
<div ngbDropdownMenu aria-labelledby="dropdownReports">
<button ngbDropdownItem>All</button>
<button ngbDropdownItem [disabled]="true">-----</button>
<button *ngFor="let diagnosticReport of diagnosticReports" ngbDropdownItem>{{diagnosticReport?.sort_title}} [{{diagnosticReport?.sort_date | amDateFormat: 'LL'}}]</button>
<button
*ngFor="let diagnosticReport of diagnosticReports" ngbDropdownItem
[routerLink]="'/labs/report/'+ diagnosticReport?.source_id + '/' + diagnosticReport?.source_resource_type + '/' + diagnosticReport?.source_resource_id"
>{{diagnosticReport?.sort_title}} [{{diagnosticReport?.sort_date | amDateFormat: 'LL'}}]</button>
</div>
</div>
<div ngbDropdown class="d-inline-block float-right">
Expand Down
86 changes: 73 additions & 13 deletions frontend/src/app/pages/report-labs/report-labs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {FastenApiService} from '../../services/fasten-api.service';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {ResourceFhir} from '../../models/fasten/resource_fhir';
import * as fhirpath from 'fhirpath';
import {Observable} from 'rxjs';
import {flatMap, map} from 'rxjs/operators';
import {forkJoin, Observable} from 'rxjs';
import {flatMap, map, mergeMap} from 'rxjs/operators';
import {ResponseWrapper} from '../../models/response-wrapper';
import {ActivatedRoute} from '@angular/router';
import {ActivatedRoute, Params} from '@angular/router';

class ObservationGroup {[key: string]: ResourceFhir[]}
class ObservationGroupInfo {
Expand All @@ -27,11 +27,16 @@ class LabResultCodeByDate {
export class ReportLabsComponent implements OnInit {
loading: boolean = false

currentPage: number = 0
currentPage: number = 1 //1-based index due to the way the pagination component works
pageSize: number = 10
allObservationGroups: string[] = []


//diagnostic report data
reportSourceId: string = ''
reportResourceType: string = ''
reportResourceId: string = ''

//currentPage data
observationGroups: ObservationGroup = {}
observationGroupTitles: {[key: string]: string} = {}
Expand All @@ -50,19 +55,43 @@ export class ReportLabsComponent implements OnInit {

this.populateReports()

this.findLabResultCodesSortedByLatest().subscribe((data) => {
// this.loading = false
console.log("ALL lab result codes", data)
this.allObservationGroups = data.map((item) => item.label)
return this.populateObservationsForCurrentPage()
})

//determine if we're requesting all results or just a single report
//source_id/:resource_type/:resource_id

this.activatedRoute.params.subscribe((routeParams: Params) => {
this.reportSourceId = routeParams['source_id']
this.reportResourceType = routeParams['resource_type']
this.reportResourceId = routeParams['resource_id']
console.log("Selected Report changed!", this.reportSourceId,this.reportResourceType, this.reportResourceId)

if(this.reportSourceId && this.reportResourceType && this.reportResourceId){
//we're requesting a single report
console.log("REQUSTING REPORT", this.reportSourceId, this.reportResourceType, this.reportResourceId)
this.findLabResultCodesFilteredToReport(this.reportSourceId, this.reportResourceType, this.reportResourceId).subscribe((data) => {
console.log("REPORT result codes", data)
this.allObservationGroups = data
this.currentPage = 1 //reset to first page when changing report
return this.populateObservationsForCurrentPage()
})
} else {
this.findLabResultCodesSortedByLatest().subscribe((data) => {
// this.loading = false
console.log("ALL lab result codes", data)
this.allObservationGroups = data.map((item) => item.label)
return this.populateObservationsForCurrentPage()
})
}
});

}

//using the current list of allObservationGroups, retrieve a list of observations, group them by observationGroup, and set the observationGroupTitles
populateObservationsForCurrentPage(){

let observationGroups = this.allObservationGroups.slice(this.currentPage * this.pageSize, (this.currentPage + 1) * this.pageSize)
let observationGroups = this.allObservationGroups.slice((this.currentPage-1) * this.pageSize, this.currentPage * this.pageSize)

console.log("FILTERED OBSERVATION GROUPS", observationGroups, (this.currentPage -1) * this.pageSize, this.currentPage * this.pageSize)
this.loading = true
this.getObservationsByCodes(observationGroups).subscribe((data) => {
this.loading = false
Expand All @@ -78,8 +107,39 @@ export class ReportLabsComponent implements OnInit {
}

//get a list of all lab codes associated with a diagnostic report
findLabResultCodesFilteredToReport(diagnosticReport: ResourceFhir): Observable<LabResultCodeByDate[]> {
return null
findLabResultCodesFilteredToReport(sourceId, resourceType, resourceId): Observable<any[]> {
return this.fastenApi.getResources(resourceType, sourceId, resourceId)
.pipe(
mergeMap((diagnosticReports) => {
let diagnosticReport = diagnosticReports?.[0]
console.log("diagnosticReport", diagnosticReport)

//get a list of all the observations associated with this report
let observationIds = fhirpath.evaluate(diagnosticReport.resource_raw, "DiagnosticReport.result.reference")

//request each observation, and find the lab codes associated with each
let requests = []
for(let observationId of observationIds){
let observationIdParts = observationId.split("/")
requests.push(this.fastenApi.getResources(observationIdParts[0], diagnosticReport.source_id, observationIdParts[1]))
}

return forkJoin(requests)
}),
map((results:ResourceFhir[][]) => {
let allObservationGroups = []

//for each result, loop through the observations and find the loinc code
for(let result of results){
for(let observation of result){
let observationGroup = fhirpath.evaluate(observation.resource_raw, "Observation.code.coding.where(system='http://loinc.org').first().code")[0]
allObservationGroups.push('http://loinc.org|' + observationGroup)
}
}
console.log("FOUND REPORT LAB CODES", allObservationGroups)
return allObservationGroups
})
)
}

//get a list of all unique lab codes ordered by latest date
Expand Down

0 comments on commit 74a3fd4

Please sign in to comment.