PrescriptionTransformer.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Repositories\Transformers\TCM;
  3. use Carbon\Carbon;
  4. use League\Fractal\TransformerAbstract;
  5. use App\Repositories\Models\TCM\Prescription;
  6. /**
  7. * Class PrescriptionTransformer.
  8. *
  9. * @package namespace App\Repositories\Transformers\TCM;
  10. */
  11. class PrescriptionTransformer extends TransformerAbstract
  12. {
  13. /**
  14. * Transform the Prescription entity.
  15. *
  16. * @param \App\Repositories\Models\TCM\Prescription $model
  17. *
  18. * @return array
  19. */
  20. public function transform(Prescription $model)
  21. {
  22. return [
  23. 'id' => (int)$model->id,
  24. "medical_record_id" => $model->prescription_id,
  25. 'medical_record' => $model->medical_record()->with(['department_category'])->select(['doctor', 'hospital', 'chief_complaint', 'chinese_tra_diagnosis', 'department'])->first(),
  26. "name" => $model->name,
  27. "drug_type" => $model->drug_type,
  28. "eat_type" => $model->eat_type,
  29. "number" => $model->number,
  30. "advice_type" => $model->advice_type,
  31. "advice_frequency" => $model->advice_frequency,
  32. "advice_frequency_text" => Prescription::$frequencyMap[$model->advice_frequency],
  33. "one_consumption" => $model->one_consumption,
  34. "use_unit" => $model->use_unit,
  35. "advice" => $model->advice,
  36. "drugs" => $model->drugs,
  37. "patient_id" => $model->patient_id,
  38. "patient" => $model->patient()->select(['name', 'sex', 'birth_date'])->first(),
  39. "status" => $model->status,
  40. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  41. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  42. ];
  43. }
  44. }