Skip to content

Commit

Permalink
enable pagination on medical history page.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Nov 26, 2023
1 parent a8be7f3 commit 7a77dcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ng-container [ngTemplateOutlet]="loading ? isLoadingTemplate : (encounters.length == 0) ? emptyReport : report"></ng-container>

<ng-template #report>

<!-- Editor Button -->
<div class="row mt-5 mb-3">
<div class="col-12">
Expand Down Expand Up @@ -43,7 +44,7 @@ <h1 class="az-dashboard-title">Condition</h1>
<div class="row">
<div class="col-12 d-flex justify-content-center flex-nowrap">
<ngb-pagination
[collectionSize]="allEncounterGroups.length"
[collectionSize]="allEncountersIds.length"
[(page)]="currentPage"
[pageSize]="pageSize"
(pageChange)="pageChange()"
Expand Down
35 changes: 18 additions & 17 deletions frontend/src/app/pages/medical-history/medical-history.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MedicalHistoryComponent implements OnInit {

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

closeResult = '';
// conditions: ResourceFhir[] = []
Expand All @@ -39,40 +39,41 @@ export class MedicalHistoryComponent implements OnInit {
//load the first page
this.loading = true

this.pageChange(1)
}

pageChange(page: number){
this.loading = true

this.fastenApi.getResources('Encounter').subscribe(
(response: ResourceFhir[]) => {

let selectedResourceIds = response.map((resource: ResourceFhir): Partial<ResourceFhir> => {
this.allEncountersIds = response.map((resource: ResourceFhir): Partial<ResourceFhir> => {
return {
source_id: resource.source_id,
source_resource_type: resource.source_resource_type,
source_resource_id: resource.source_resource_id,
}
})

this.fastenApi.getResourceGraph(null, selectedResourceIds).subscribe((graphResponse: ResourceGraphResponse) => {
this.loading = false
this.pageChange()

console.log("FLATTENED RESOURCES RESPONSE", graphResponse)
this.encounters = graphResponse.results["Encounter"] || []

},
error => {
this.loading = false
})

})

}

pageChange(){
this.loading = true

let encounterIds = this.allEncountersIds.slice((this.currentPage-1) * this.pageSize, this.currentPage * this.pageSize)

this.fastenApi.getResourceGraph(null, encounterIds).subscribe((graphResponse: ResourceGraphResponse) => {
this.loading = false

console.log("FLATTENED RESOURCES RESPONSE", graphResponse)
this.encounters = graphResponse.results["Encounter"] || []

},
error => {
this.loading = false
}
)
})

// this.fastenApi.getResourceGraph(null, page).subscribe((response: ResourceGraphResponse) => {
// this.loading = false
Expand Down

0 comments on commit 7a77dcd

Please sign in to comment.