import { APIService } from './api' import { Uuid, Consult, ConsultRequest, MedicalStatus, ConsultTransmission, ClosedReasonType, TransmissionKind, TransmissionStatus, ConsultType, } from '../models' export class ConsultService { constructor(private api: APIService, private baseURL: string) {} public consultCreate(c: ConsultRequest): Promise { return this.api.post(`${this.baseURL}/v1/consults`, c) } /** * This function returns the number of consults using parameters * @param uuidPractice the practice uuid * @param uuidRequester the requester uuid * @param statusesMedical an array containing MedicalStatus to include * @param statusesExclude an array containing MedicalStatus to exclude * @param shortId a shortId matcher (will match all consult with a shortId starting with this `shortId`) * @param columnToSortTo the list of columns separated by commas, to sort to (in order of sorting) * @param orderToSortTo the type of sorting to do ('asc' for ascending or 'desc' for descending) * @param perPage the number of item to retrieve per "page" * @param indexPage the actual index of the page to retrieve (0 based: 0 is the first items) * @param filterAssignedDoctor the uuid of the doctor for which to filter with * @param filterCurrentPractitioner the uuid of the current assistant assigned to filter with * @param filterIsoLocality the of isoLocality to filter with * @param filterAssignee array of practitioner uuids with which you want to filter the consultations * @returns a number of consult */ public countConsults( uuidPractice?: Uuid, uuidRequester?: Uuid, statusesMedical?: MedicalStatus[], statusesExclude?: MedicalStatus[], shortId?: string, columnToSortTo?: string[], orderToSortTo?: string[], perPage?: number, indexPage?: number, filterAssignedDoctor?: string, filterCurrentPractitioner?: string, filterIsoLocality?: string[], filterAssignee?: string[], typesConsult?: ConsultType[], uuidParent?: Uuid ): Promise { return this.api .head( `${this.baseURL}/v1/consults`, { params: { uuidPractice, uuidRequester, statusesMedical, statusesExclude, shortId, perPage, page: indexPage, sortColumns: columnToSortTo, orderColumns: orderToSortTo, filterAssignedDoctor, filterCurrentPractitioner, filterIsoLocality, filterAssignee, typesConsult, uuidParent, }, }, 'Content-Range' ) .then((resContentRange) => { if (!resContentRange || (typeof resContentRange !== 'string' && typeof resContentRange !== 'number')) { return 0 } if (typeof resContentRange === 'number') { return resContentRange } return parseInt(resContentRange) }) } /** * This function get consults using parameters * @param uuidPractice the practice uuid * @param uuidRequester the requester uuid * @param statusesMedical an array containing MedicalStatus to include * @param statusesExclude an array containing MedicalStatus to exclude * @param shortId a shortId matcher (will match all consult with a shortId starting with this `shortId`) * @param columnToSortTo the list of columns separated by commas, to sort to (in order of sorting) * @param orderToSortTo the type of sorting to do ('asc' for ascending or 'desc' for descending) * @param perPage the number of item to retrieve per "page" * @param indexPage the actual index of the page to retrieve (0 based: 0 is the first items) * @param filterAssignedDoctor the uuid of the doctor for which to filter with * @param filterCurrentPractitioner the uuid of the current assistant assigned to filter with * @param filterIsoLocality the of isoLocality to filter with * @returns a list of consult */ public getConsults( uuidPractice?: Uuid, uuidRequester?: Uuid, statusesMedical?: MedicalStatus[], statusesExclude?: MedicalStatus[], shortId?: string, columnToSortTo?: string[], orderToSortTo?: string[], perPage?: number, indexPage?: number, filterAssignedDoctor?: string, filterCurrentPractitioner?: string, filterIsoLocality?: string[], filterAssignee?: string[], uuidParent?: Uuid, typesConsult?: ConsultType[], filterOnlyWithoutTransmission?: boolean, filterAfterDate?: Date, ): Promise { return this.api.get(`${this.baseURL}/v1/consults`, { params: { uuidPractice, uuidRequester, statusesMedical, statusesExclude, shortId, perPage, page: indexPage, sortColumns: columnToSortTo, orderColumns: orderToSortTo, filterAssignedDoctor, filterCurrentPractitioner, filterIsoLocality, filterAssignee, filterOnlyWithoutTransmission, filterAfterDate, typesConsult, uuidParent, }, }) } public getConsultByUUID(uuidConsult: Uuid, uuidPractice?: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/consults/${uuidConsult}`, { params: { uuidPractice } }) } public getConsultByPracticePaymentID(idPracticePayment: Number, uuidPractice?: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/consults/payment-${idPracticePayment}`, { params: { uuidPractice }, }) } public updateConsultByUUID( uuidConsult: Uuid, consult: { statusMedical?: MedicalStatus closedReasonType?: ClosedReasonType closedReasonDescription?: string uuidAssignedDoctor?: Uuid neverExpires?: boolean }, uuidPractice?: Uuid, uuidRequester?: Uuid ): Promise { return this.api.put(`${this.baseURL}/v1/consults/${uuidConsult}`, consult, { params: { uuidPractice, uuidRequester, }, }) } public getConsultFaxStatuses(uuidConsult: string): Promise { return this.api.get(`${this.baseURL}/v1/consults/${uuidConsult}/transmissions`, { params: { kind: TransmissionKind.Fax, }, }) } public postConsultTransmission( uuidConsult: string, nameDriver: string = 'Documo', addressOrPhoneToSendTo?: string, file?: File, nameReceiver?: string, txtTransmissionTitle?: string, txtTransmissionNotes?: string, uuidPatient?: string // numTry ?: number, // delay ?: number, ): Promise { let data = new FormData() data.append('nameDriverReceiver', nameDriver) if (uuidPatient) { data.append('uuidPatient', uuidPatient) } if (addressOrPhoneToSendTo) { data.append('addressReceiver', addressOrPhoneToSendTo) } if (file) { data.append('file', file) } if (nameReceiver) { data.append('nameReceiver', nameReceiver) } if (txtTransmissionTitle) { data.append('txtTransmissionTitle', txtTransmissionTitle) } if (txtTransmissionNotes) { data.append('txtTransmissionNotes', txtTransmissionNotes) } return this.api.post(`${this.baseURL}/v1/consults/${uuidConsult}/transmissions`, data, { headers: { 'Content-Type': 'multipart/form-data;' }, }) } public postConsultFax( uuidConsult: string, addressReceiver: string, file: File, uuidPatient?: string ): Promise { return this.postConsultTransmission( uuidConsult, 'Documo', addressReceiver, file, undefined, undefined, undefined, uuidPatient ) } public postConsultEmail(uuidConsult: string, file: File, uuidPatient?: string): Promise { return this.postConsultTransmission( uuidConsult, 'Pharmacierge', undefined, file, undefined, undefined, undefined, uuidPatient ) } public retryConsultFax(uuidConsult: string, transmissionId: string): Promise { return this.api.put( `${this.baseURL}/v1/consults/${uuidConsult}/transmissions/${transmissionId}`, { status: TransmissionStatus.Retrying } ) } public updateConsultTransmissionStatus( transmissionId: string, uuidConsult: string, newStatus: TransmissionStatus ): Promise { return this.api.put( `${this.baseURL}/v1/consults/${uuidConsult}/transmissions/${transmissionId}`, { status: newStatus } ) } }