public async Task <IActionResult> CreatePatientMedication(int patientId, [FromBody] PatientMedicationForUpdateDto medicationForUpdate) { if (medicationForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new medication"); return(BadRequest(ModelState)); } var command = new AddMedicationToPatientCommand(patientId, medicationForUpdate.SourceDescription, medicationForUpdate.ConceptId, medicationForUpdate.ProductId, medicationForUpdate.StartDate, medicationForUpdate.EndDate, medicationForUpdate.Dose, medicationForUpdate.DoseFrequency, medicationForUpdate.DoseUnit, medicationForUpdate.Attributes.ToDictionary(x => x.Id, x => x.Value)); _logger.LogInformation( "----- Sending command: AddMedicationToPatientCommand - {conceptId}", command.ConceptId); var commandResult = await _mediator.Send(command); if (commandResult == null) { return(BadRequest("Command not created")); } return(CreatedAtAction("GetPatientMedicationByIdentifier", new { patientId, id = commandResult.Id }, commandResult)); }
public async Task <IActionResult> UpdatePatientMedication(int patientId, int id, [FromBody] PatientMedicationForUpdateDto medicationForUpdate) { if (medicationForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); } var command = new ChangeMedicationDetailsCommand(patientId, id, medicationForUpdate.StartDate, medicationForUpdate.EndDate, medicationForUpdate.Dose, medicationForUpdate.DoseFrequency, medicationForUpdate.DoseUnit, medicationForUpdate.Attributes.ToDictionary(x => x.Id, x => x.Value)); _logger.LogInformation( "----- Sending command: ChangeMedicationDetailsCommand - {patientId}: {patientMedicationId}", command.PatientId, command.PatientMedicationId); var commandResult = await _mediator.Send(command); if (!commandResult) { return(BadRequest("Command not created")); } return(Ok()); }