import { Consult, Drug, TreatmentAssociatedConsultData, TreatmentPlan, TreatmentPlans, TreatmentPlansRequest, TreatmentPlansResponse, TreatmentPlanUpdateRequest, Uuid, } from '..' import { Diagnosis, Treatment, DiagnosisRequest, TreatmentAndDrugPrescriptionUpdateRequest, TreatmentRequest, PlanStatus, } from '../models/diagnosis' import { APIService } from './api' export class DiagnosisService { constructor(private api: APIService, private baseURL: string) {} public getDiagnoses(): Promise { return this.api.get(`${this.baseURL}/v1/diagnoses`) } /** * Get a diagnosis by uuid that belongs to your practice * @param uuidDiagnosis the uuid of the diagnosis * @returns a diagnosis */ public getDiagnosisByUuid(uuidDiagnosis: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/diagnoses/${uuidDiagnosis}`) } public createDiagnosis(diagnosis: DiagnosisRequest): Promise { return this.api.post(`${this.baseURL}/v1/diagnoses`, diagnosis) } public updateDiagnosis(uuid: string, diagnosis: DiagnosisRequest): Promise { return this.api.put(`${this.baseURL}/v1/diagnoses/${uuid}`, diagnosis) } public getTreatmentByUuid(uuidDiagnosis: Uuid, uuidTreatment: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/diagnoses/${uuidDiagnosis}/treatments/${uuidTreatment}`) } public getTreatmentsFromDiagnosisUuid(diagnosisUuid: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments`) } /** * This function returns treatment plans associated to a consult * @param uuidConsult the consult uuid to fetch * @returns an array of TreatmentPlan */ public getTreatmentPlansFromConsultUuid(uuidConsult: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/treatment-plans/`, { params: { uuidConsult } }) } /** * creates a new treatment for the specified diagnosis * @param diagnosisUuid uuid of the diagnosis that the treatment is linked to * @param treatmentRequest the treatment to be inserted */ public createTreatment(diagnosisUuid: string, treatmentRequest: TreatmentRequest) { return this.api.post(`${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments`, treatmentRequest) } /** * This function returns populated treatment plans associated to a consult * @param uuidConsult the consult uuid to fetch * @returns a TreatmentPlans object */ public getTreatmentPlansPopulatedFromConsultUuid(uuidConsult: Uuid): Promise { return this.api.get(`${this.baseURL}/v1/treatment-plans/`, { params: { uuidConsult, populated: true }, }) } /** * This function returns populated treatment plans associated consults in a list * @param arrUuidsConsults the list of consult uuid to fetch the treatments for * @param arrStatusesToInclude the PlanStatus to include * @param dateDecidedAfter the date after which the treatment must have been decided * @param dateDecidedBefore the date before which the treatment must have been decided * @returns a TreatmentPlans object */ public getTreatmentPlansWithStatusDecidedAfterDateForConsultsUuids( arrUuidsConsults: string[], arrStatusesToInclude?: PlanStatus[], dateDecidedAfter?: Date, dateDecidedBefore?: Date, ): Promise { return this.api.get(`${this.baseURL}/v1/treatment-plans/`, { params: { filterByConsultsUuids : arrUuidsConsults, statusesTreatmentPlanIncluded: arrStatusesToInclude, filterDecidedAfterDate: dateDecidedAfter, filterDecidedBeforeDate: dateDecidedBefore, }, }) } public postPlans(plans: TreatmentPlansRequest): Promise { return this.api.post(`${this.baseURL}/v1/treatment-plans`, plans) } public updateTreatmentPlan( uuidPlan: string, uuidConsult: string, diagnosisRequest: DiagnosisRequest, plan: TreatmentAndDrugPrescriptionUpdateRequest, refill?: boolean ): Promise { return this.api.put(`${this.baseURL}/v1/treatment-plans/${uuidPlan}`, < TreatmentPlanUpdateRequest >{ uuidConsult, diagnosis: diagnosisRequest, plan, refill, }) } public setAssociatedConsultsToTreatment( diagnosisUuid: string, treatmentUuid: string, arrAssociatedConsults: TreatmentAssociatedConsultData[] ): Promise { return this.api.post( `${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments/${treatmentUuid}/associated-consults`, arrAssociatedConsults ) } public updateAssociatedConsultsToTreatment( diagnosisUuid: string, treatmentUuid: string, arrAssociatedConsults: TreatmentAssociatedConsultData[] ): Promise { return this.api.put( `${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments/${treatmentUuid}/associated-consults`, arrAssociatedConsults ) } public getAssociatedConsultsOfTreatment( diagnosisUuid: string, treatmentUuid: string ): Promise { return this.api.get( `${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments/${treatmentUuid}/associated-consults` ) } public acceptTreatmentPlan(uuidPlan: string, uuidConsult: string): Promise { return this.api.put(`${this.baseURL}/v1/treatment-plans/${uuidPlan}/accept`, { uuidConsult }) } public updateTreatmentPlanStatusOnly(uuidPlan: string, uuidConsult: string, newStatus: PlanStatus): Promise { return this.api.put( `${this.baseURL}/v1/treatment-plans/${uuidPlan}`, { uuidConsult, status: newStatus }) } public updateTreatmentPlanNotesOnly(uuidPlan: string, uuidConsult: string, newNotes: string): Promise { return this.api.put( `${this.baseURL}/v1/treatment-plans/${uuidPlan}`, { uuidConsult, notes: newNotes }) } /** * retrieves all the drugs of the specified practice * @param uuidPractice */ public async getAllDrugs(uuidPractice: string): Promise { const res = await this.api.get<{ foundDrugs: Drug[] }>(`${this.baseURL}/v1/drugs/practice/${uuidPractice}`) if (res && res.foundDrugs) return res.foundDrugs return undefined } }