Exemplo n.º 1
0
        public int Create(DocumentModel documentModel)
        {
            IntakeForm intakeForm = _context.IntakeForm
                                    .Include("Questions.Answers")
                                    .Include(i => i.ICD10Codes)
                                    .Include(i => i.Physician.Address)
                                    .Include(i => i.Signatures)
                                    .First(i => i.IntakeFormId == documentModel.IntakeFormId);

            Patient patient = _context.Patient
                              .Include(p => p.Address)
                              .Include(p => p.PrivateInsurance)
                              .Include(p => p.Medicare)
                              .First(p => p.PatientId == intakeForm.PatientId);

            IntakeFormModel intakeFormModel = intakeForm.ToModel();
            PatientModel    patientModel    = patient.ToModel();
            PhysicianModel  physicianModel  = intakeForm.Physician.ToModel();
            ICollection <SignatureModel> signatureModels = intakeForm.Signatures.Select(s => s.ToModel()).ToList();

            var documentContent = _exporter.GenerateIntakeDocuments(
                intakeFormModel,
                patientModel,
                physicianModel,
                signatureModels);

            var document = new Document
            {
                IntakeFormId = documentModel.IntakeFormId,
                Content      = documentContent
            };

            intakeForm.Document = document;

            _context.SaveChanges();

            return(document.DocumentId);
        }