Skip to content

Commit

Permalink
Merge pull request REAN-Foundation#872 from REAN-Foundation/feature/a…
Browse files Browse the repository at this point in the history
…dded_medication_update_in_queue

Added medication update logic in queue
  • Loading branch information
tabbasum-rean authored Jan 4, 2024
2 parents ea3de2d + 454488f commit cc211ea
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/api/clinical/medication/medication/medication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ResponseHandler } from '../../../../common/response.handler';
import { DrugDomainModel } from '../../../../domain.types/clinical/medication/drug/drug.domain.model';
import { MedicationStockImageDto } from '../../../../domain.types/clinical/medication/medication.stock.image/medication.stock.image.dto';
import { MedicationDomainModel } from '../../../../domain.types/clinical/medication/medication/medication.domain.model';
import { ConsumptionSummaryDto } from '../../../../domain.types/clinical/medication/medication/medication.dto';
import { ConsumptionSummaryDto, MedicationDto } from '../../../../domain.types/clinical/medication/medication/medication.dto';
import { MedicationAdministrationRoutesList, MedicationDosageUnitsList, MedicationDurationUnitsList, MedicationFrequencyUnitsList, MedicationTimeSchedulesList } from '../../../../domain.types/clinical/medication/medication/medication.types';
import { DrugService } from '../../../../services/clinical/medication/drug.service';
import { MedicationConsumptionService } from '../../../../services/clinical/medication/medication.consumption.service';
Expand Down Expand Up @@ -269,36 +269,10 @@ export class MedicationController {
throw new ApiError(400, 'Unable to update medication record!');
}

if (domainModel.DrugId !== null ||
domainModel.RefillCount !== null ||
domainModel.RefillNeeded !== null ||
domainModel.Duration !== null ||
domainModel.DurationUnit !== null ||
domainModel.Frequency !== null ||
domainModel.FrequencyUnit !== null ||
domainModel.TimeSchedules !== null ||
domainModel.StartDate !== null) {

await this._medicationConsumptionService.deleteFutureMedicationSchedules(id);

if (updated.FrequencyUnit !== 'Other') {
var stats = await this._medicationConsumptionService.create(updated);
var doseValue = Helper.parseIntegerFromString(updated.Dose.toString()) ?? 1;

var consumptionSummary: ConsumptionSummaryDto = {
TotalConsumptionCount : stats.TotalConsumptionCount,
TotalDoseCount : stats.TotalConsumptionCount * doseValue,
PendingConsumptionCount : stats.PendingConsumptionCount,
PendingDoseCount : stats.PendingConsumptionCount * doseValue,
};

updated.ConsumptionSummary = consumptionSummary;
}

}
this.updateMedicationConsumption(domainModel, id, updated);

Logger.instance().log(`[MedicationTime] Update - medication response returned`);
ResponseHandler.success(request, response, 'Medication record updated successfully!', 200, {
ResponseHandler.success(request, response, 'Medication record updated successfully! Updates will be available shortly.', 200, {
Medication : updated,
});
} catch (error) {
Expand Down Expand Up @@ -453,6 +427,37 @@ export class MedicationController {
}
}

private async updateMedicationConsumption(domainModel: MedicationDomainModel, id: string, updated: MedicationDto) {
if (domainModel.DrugId !== null ||
domainModel.RefillCount !== null ||
domainModel.RefillNeeded !== null ||
domainModel.Duration !== null ||
domainModel.DurationUnit !== null ||
domainModel.Frequency !== null ||
domainModel.FrequencyUnit !== null ||
domainModel.TimeSchedules !== null ||
domainModel.StartDate !== null) {

await this._medicationConsumptionService.deleteFutureMedicationSchedules(id);

if (updated.FrequencyUnit !== 'Other') {
await this._medicationConsumptionService.create(updated);
/*var doseValue = Helper.parseIntegerFromString(updated.Dose.toString()) ?? 1;
var consumptionSummary: ConsumptionSummaryDto = {
TotalConsumptionCount : stats.TotalConsumptionCount,
TotalDoseCount : stats.TotalConsumptionCount * doseValue,
PendingConsumptionCount : stats.PendingConsumptionCount,
PendingDoseCount : stats.PendingConsumptionCount * doseValue,
};
updated.ConsumptionSummary = consumptionSummary;*/
}

}

}

//#endregion

}

0 comments on commit cc211ea

Please sign in to comment.