import moment from 'moment';
import uuidv4 from 'uuid/v4';
import { isEmpty, pick } from 'lodash';
import * as api from './utils/api.util.test';
import {
initialTestSetup, badRequestResponse, checkCommonResponse, internalServerErrorResponse,
} from './utils/helpers/common.helper';
import {
checkAppointmentResponse, checkAppDoctor, checkUpdateNotes, cancelApp, createApp,
} from './utils/helpers/appointment.helper';
import { getPatientApp } from './utils/helpers/admission.helper';
import { mySiloamAppointments } from '../variables/tableName.variable';
import { channel } from '../variables/common.variable';
const env = process.env.NODE_ENV || 'test';
const token = env === 'prodExt' ? initialTestSetup() : '';
describe('Appointments', async () => {
let params = {
name: 'ALBERT',
birth: '1989-01-25',
mr: 798084,
fromDate: moment.tz('Asia/Jakarta').format('YYYY-MM-DD'),
toDate: moment.tz('Asia/Jakarta').add(7, 'days').format('YYYY-MM-DD'),
isActiveOnly: true,
appDate: moment.tz('Asia/Jakarta').format('YYYY-MM-DD'),
hospitalId: '39764039-37b9-4176-a025-ef7b2e124ba4',
isWaitingList: false,
modifiedName: 'anil baswedan',
specialityId: '8646beb4-3cc4-4c62-bdd7-51529311bf11',
channelId: channel.BPJS,
};
const additionalPayload = {
userId: uuidv4(),
source: '127.0.0.1',
userName: 'Front Office Testing',
};
const endpoint = `/hospital/${params.hospitalId}`;
let appointment;
before(async () => {
appointment = await getPatientApp({
attributes: [
'appointment_id',
`${mySiloamAppointments.TM_CONTACT}.name`,
`${mySiloamAppointments.TM_CONTACT}.birth_date`,
`${mySiloamAppointments.TM_CONTACT}->${mySiloamAppointments.TM_PATIENT}->${mySiloamAppointments.TX_PATIENT_HOSPITAL}s.medical_record_number`,
'appointment_date',
'hospital_id',
'modified_name',
'is_waiting_list',
'doctor_id',
],
appDate: moment.tz('Asia/Jakarta').add(1, 'day').format('YYYY-MM-DD'),
patient: true,
patientHospital: true,
hospitalId: params.hospitalId,
});
if (isEmpty(appointment)) appointment = await createApp({ ...additionalPayload, ...params });
params = {
...params,
doctorId: appointment.doctor_id,
fromDate: appointment.appointment_date,
toDate: moment(appointment.appointment_date, 'YYYY-MM-DD').add(7, 'day').format('YYYY-MM-DD'),
appDate: appointment.appointment_date,
name: String(appointment.name).substring(0, 10),
birth: appointment.birth_date,
mr: appointment.medical_record_number,
isActiveOnly: true,
hospital: appointment.hospital_id,
isWaitingList: appointment.is_waiting_list,
modifiedName: appointment.modified_name,
channelId: appointment.channel_id,
};
});
describe('Successfull Scenario Testing', () => {
it('it should return of list appointment without filter', async () => {
const query = `?date=${params.appDate}`;
const res = await api.getAppointmentList(token, endpoint, query);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['appDate']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by name, birth, mr, doctor', async () => {
const query = `?name=${params.name}&birth=${params.birth}&mr=${params.mr}&doctor=${params.doctorId}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['name', 'birth', 'mr', 'doctorId']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by name, birth, mr', async () => {
const query = `?name=${params.name}&birth=${params.birth}&mr=${params.mr}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['name', 'birth', 'mr']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by name, birth', async () => {
const query = `?name=${params.name}&birth=${params.birth}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['name', 'birth']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by name', async () => {
const query = `?name=${params.name}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['name']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by doctor', async () => {
const query = `?doctor=${params.doctorId}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['doctorId']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by mr', async () => {
const query = `?mr=${params.mr}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['mr']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter by birth date', async () => {
const query = `?birth=${params.birth}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['birth']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with from date, to date', async () => {
const query = `?fromDate=${params.fromDate}&toDate=${params.toDate}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['fromDate', 'toDate']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment only for active appointment', async () => {
const query = `?isActiveOnly=${params.isActiveOnly}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['isActiveOnly']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter waiting list', async () => {
const query = `?isWaitingList=${params.isWaitingList}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['isWaitingList']));
res.body.should.have.property('message').eql('List of appointment');
});
it('it should return of list appointment with filter modified name', async () => {
const query = `?modifiedName=${params.modifiedName}`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, pick(params, ['modifiedName']));
res.body.should.have.property('message').eql('List of appointment');
await cancelApp(appointment, additionalPayload);
});
it('it should return of list appointment with filter channel ID & exclude true', async () => {
const query = `?channelId=${params.channelId}&exclude=true`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, { ...pick(params, ['channelId']), exclude: true });
res.body.should.have.property('message').eql('List of appointment');
await cancelApp(appointment, additionalPayload);
});
it('it should return of list appointment with filter channel ID & exclude false', async () => {
const query = `?channelId=${params.channelId}&exclude=false`;
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
checkCommonResponse(res);
checkAppointmentResponse(res, { ...pick(params, ['channelId']), exclude: false });
res.body.should.have.property('message').eql('List of appointment');
await cancelApp(appointment, additionalPayload);
});
});
describe('Failed Scenario Testing', () => {
it('it should failed when give invalid doctor id guid', async () => {
const query = '?doctor=87329-hdkshd';
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
badRequestResponse(res);
});
it('it should failed when give invalid medical record', async () => {
const query = '?mr=hdkshd';
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
badRequestResponse(res);
});
it('it should failed when give invalid birthdate', async () => {
const query = '?birth=27-05-1996';
const uri = endpoint + query;
const res = await api.getAppointmentList(token, uri);
badRequestResponse(res);
});
});
});