Skip to content

Commit

Permalink
Merge branch 'master' into HIV-626
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzentic authored Jan 24, 2023
2 parents 0799f68 + f0ffb33 commit 1446465
Show file tree
Hide file tree
Showing 20 changed files with 3,550 additions and 681 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

This a formentry module for use with AMPATH's medical records system, [AMPATH POC](https://github.com/ampath/ng2-amrs).

You can find the documentation for AMPATH forms (conceptually, this library as well as the [Form builder](https://github.com/ampath/ngx-openmrs-formbuilder)) here - [AMPATH Forms docs](https://ampath-forms.vercel.app).

# Development

## Build the library by running:
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-openmrs-formentry",
"name": "@ampath-kenya/ngx-openmrs-formentry",
"main": "ngx-openmrs-formentry/dist/ngx-formentry",
"version": "2.12.9",
"version": "2.12.17",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down Expand Up @@ -40,7 +40,7 @@
"reflect-metadata": "^0.1.9",
"rxjs": "~6.3.3",
"rxjs-compat": "^6.2.1",
"shelljs": "^0.7.0",
"shelljs": "^0.8.5",
"slick-carousel": "^1.6.0",
"time-ago-pipe": "^1.3.2",
"tree-model": "^1.0.5",
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-formentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-openmrs-formentry",
"version": "2.12.9",
"name": "@ampath-kenya/ngx-openmrs-formentry",
"version": "2.12.17",
"peerDependencies": {
"@angular/common": "^6.1.0",
"@angular/core": "^6.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ import * as moment_ from 'moment';

const moment = moment_;

interface DailyScheduled {
date: string;
count: {
scheduled: number;
};
}
interface WeeeklyScheduleReport {
reports: {
attended: any;
hasNotReturned: any;
scheduled: any;
};
results: DailyScheduled[];
totals: {
attended: number;
hasNotReturned: number;
scheduled: number;
};
}
interface DayCount {
date: string;
count: number;
}

@Component({
selector: 'appointments-overview',
templateUrl: './appointments-overview.component.html',
Expand Down Expand Up @@ -55,49 +79,53 @@ export class AppointmentsOverviewComponent implements OnInit, OnChanges {
.subtract(1, 'day')
.format('YYYY-MM-DD');
this.today = moment(v).format('DD-MM-YYYY');
// create 5 week days
const _data = [];
const programTypes = [
'781d85b0-1359-11df-a1f1-0026b9348838',
'781d897a-1359-11df-a1f1-0026b9348838',
'96047aaf-7ab3-45e9-be6a-b61810fe617d',
'c19aec66-1a40-4588-9b03-b6be55a8dd1d',
'f7793d42-11ac-4cfd-9b35-e0a21a7a7c31',
'334c9e98-173f-4454-a8ce-f80b20b7fdf0',
'96ba279b-b23b-4e78-aba9-dcbd46a96b7b',
'781d8880-1359-11df-a1f1-0026b9348838'
];
const programTypeParams = programTypes.join();
for (let i = 1; i <= 5; i++) {
_data.push({
date: moment(v)
.startOf('week')
.add(i, 'day')
.format('DD-MM-YYYY'),
count: 0
});
}
dataSource
.getMonthlySchedule({
startDate: startDate,
endDate: endDate,
limit: 5,
locationUuids: locationUuid,
programType: programTypeParams
department: 'HIV',
groupBy: 'groupByPerson,groupByAttendedDate,groupByRtcDate'
})
.subscribe(
(data) => {
(data: WeeeklyScheduleReport) => {
const _data: DayCount[] = [];
const weeklyMap = new Map();
// create the weeks schedule with zero appointments
for (let i = 0; i < 5; i++) {
const scheduleDate = moment(v)
.startOf('week')
.add(i, 'day')
.format('YYYY-MM-DD');
const scheduledObj: DailyScheduled = {
date: scheduleDate,
count: {
scheduled: 0
}
};
weeklyMap.set(scheduleDate, scheduledObj);
}

const results: DailyScheduled[] = data.results || [];
// replace placeholder schedules with actual schedules in the map obj
results.forEach((scheduled: DailyScheduled) => {
weeklyMap.set(scheduled.date, scheduled);
});
// retrieve scheduled obj from map to data array
weeklyMap.forEach((value: DailyScheduled, key: string) => {
const dayCount: DayCount = {
date: key,
count: value.count.scheduled || 0
};
_data.push(dayCount);
});
this.appointmentsLoaded = true;
this.loadingAppointments = false;
_data.map((appointment, index) => {
appointment.count =
data[index] !== undefined
? data[index].count.scheduled
: 0;
});

this.appointments = _data;
},
(error) => {
(error: any) => {
this.loadingAppointments = false;
this.errorLoadingAppointments = true;
this.showAppointments = false;
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<input
type="time"
class="form-control"
[ngModel]="value"
(ngModelChange)="onTimeSelect($event)"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Component, OnInit, forwardRef } from '@angular/core';
import * as moment_ from 'moment';
const moment = moment_;

@Component({
selector: 'ngx-time-picker',
templateUrl: './ngx-time-picker.component.html',
styleUrls: ['./ngx-time-picker.component.css'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
multi: true,
useExisting: forwardRef(() => NgxTimePickerComponent)
}
]
})
export class NgxTimePickerComponent implements OnInit, ControlValueAccessor {
public value: string = moment().format('HH:mm:ss');
public onChange: any = () => {};
public onTouched: any = () => {};

public ngOnInit() {}

public writeValue(value: any): void {
this.value = this.formatTimeValue(value);
}

public registerOnChange(fn: any): void {
this.onChange = fn;
}

public registerOnTouched(fn: any): void {}

public onTimeSelect($event: string): void {
const timeValue = this.formatTimeValue($event);
this.value = timeValue;
this.onChange(timeValue);
}

public formatTimeValue(timeInputString: string): string {
/*
Allows processing of data that comes in as date-time
or just time i.e '1970-03-01 12:32:21' or '12:32:21'
or '12:32' or '1970-01-01T13:03:00.000+0300'
*/
let timeArray = [];
let dateArray = [];
let timeValue = '';

if (typeof timeInputString === 'undefined' || timeInputString === null) {
} else {
timeArray = timeInputString.split(':');
dateArray = timeInputString.split('-');
}
if (timeArray.length === 1 && moment(timeInputString).isValid()) {
timeValue = moment(timeInputString).format('HH:mm:ss');
} else if (timeArray.length > 1 && timeArray.length < 2) {
timeValue = moment(timeInputString, moment.defaultFormat).format(
'HH:mm:ss'
);
} else if (timeArray.length >= 2 && dateArray.length > 1) {
timeValue = moment(timeInputString, moment.defaultFormat).format(
'HH:mm:ss'
);
} else if (timeArray.length >= 2 && dateArray.length <= 1) {
timeValue = moment(timeInputString, 'HH:mm:ss').format('HH:mm:ss');
} else {
timeValue = moment().format('HH:mm:ss');
}
return timeValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgxTimePickerComponent } from './ngx-time-picker.component';

@NgModule({
imports: [CommonModule, FormsModule, ReactiveFormsModule],
declarations: [NgxTimePickerComponent],
exports: [NgxTimePickerComponent],
providers: []
})
export class NgxTimePickerModule {}
5 changes: 4 additions & 1 deletion projects/ngx-formentry/src/form-entry/form-entry.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { EncounterViewerModule } from '../encounter-viewer/encounter-viewer.modu
import { CheckboxModule } from '../components/check-box/checkbox.module';
import { SharedModule } from '../shared.module';
import { TimeAgoPipe } from 'time-ago-pipe';
import { NgxTimePickerModule } from '../components/ngx-time-picker/ngx-time-picker.module';

@NgModule({
imports: [
Expand All @@ -56,6 +57,7 @@ import { TimeAgoPipe } from 'time-ago-pipe';
MatTabsModule,
MatCardModule,
NgxDateTimePickerModule,
NgxTimePickerModule,
SharedModule
],
declarations: [
Expand Down Expand Up @@ -94,7 +96,8 @@ import { TimeAgoPipe } from 'time-ago-pipe';
ErrorRendererComponent,
DateTimePickerModule,
EncounterViewerModule,
NgxDateTimePickerModule
NgxDateTimePickerModule,
NgxTimePickerModule
]
})
export class FormEntryModule {}
Loading

0 comments on commit 1446465

Please sign in to comment.