enable pagination on medical history page.

This commit is contained in:
Jason Kulatunga 2023-11-25 19:31:49 -08:00
parent a8be7f33ca
commit 7a77dcdcd6
No known key found for this signature in database
2 changed files with 20 additions and 18 deletions

View File

@ -8,6 +8,7 @@
<ng-container [ngTemplateOutlet]="loading ? isLoadingTemplate : (encounters.length == 0) ? emptyReport : report"></ng-container> <ng-container [ngTemplateOutlet]="loading ? isLoadingTemplate : (encounters.length == 0) ? emptyReport : report"></ng-container>
<ng-template #report> <ng-template #report>
<!-- Editor Button --> <!-- Editor Button -->
<div class="row mt-5 mb-3"> <div class="row mt-5 mb-3">
<div class="col-12"> <div class="col-12">
@ -43,7 +44,7 @@
<div class="row"> <div class="row">
<div class="col-12 d-flex justify-content-center flex-nowrap"> <div class="col-12 d-flex justify-content-center flex-nowrap">
<ngb-pagination <ngb-pagination
[collectionSize]="allEncounterGroups.length" [collectionSize]="allEncountersIds.length"
[(page)]="currentPage" [(page)]="currentPage"
[pageSize]="pageSize" [pageSize]="pageSize"
(pageChange)="pageChange()" (pageChange)="pageChange()"

View File

@ -17,7 +17,7 @@ export class MedicalHistoryComponent implements OnInit {
currentPage: number = 1 //1-based index due to the way the pagination component works currentPage: number = 1 //1-based index due to the way the pagination component works
pageSize: number = 10 pageSize: number = 10
allEncounterGroups: string[] = [] allEncountersIds: any[] = []
closeResult = ''; closeResult = '';
// conditions: ResourceFhir[] = [] // conditions: ResourceFhir[] = []
@ -39,16 +39,11 @@ export class MedicalHistoryComponent implements OnInit {
//load the first page //load the first page
this.loading = true this.loading = true
this.pageChange(1)
}
pageChange(page: number){
this.loading = true
this.fastenApi.getResources('Encounter').subscribe( this.fastenApi.getResources('Encounter').subscribe(
(response: ResourceFhir[]) => { (response: ResourceFhir[]) => {
let selectedResourceIds = response.map((resource: ResourceFhir): Partial<ResourceFhir> => { this.allEncountersIds = response.map((resource: ResourceFhir): Partial<ResourceFhir> => {
return { return {
source_id: resource.source_id, source_id: resource.source_id,
source_resource_type: resource.source_resource_type, source_resource_type: resource.source_resource_type,
@ -56,23 +51,29 @@ export class MedicalHistoryComponent implements OnInit {
} }
}) })
this.fastenApi.getResourceGraph(null, selectedResourceIds).subscribe((graphResponse: ResourceGraphResponse) => { this.pageChange()
this.loading = false
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 => { error => {
this.loading = false this.loading = false
} })
)
// this.fastenApi.getResourceGraph(null, page).subscribe((response: ResourceGraphResponse) => { // this.fastenApi.getResourceGraph(null, page).subscribe((response: ResourceGraphResponse) => {
// this.loading = false // this.loading = false