Demo entry 6349901

Update doc

   

Submitted by anonymous on Mar 01, 2017 at 14:35
Language: C#. Code size: 2.9 kB.

public void Update(UpdatePatientDocumentCommand command)
        {
            Contract.Requires<ArgumentNullException>(command != null, "command");

            var document = _patientDocumentRepository.LoadPatientDocument(command.PatientDocumentId);

            using (var scope = new ApplicationServiceScope())
            {
                /*
                PatientDocument newDocument;

                if (PatientCmnDocument.CmnDocumentTypes.Contains(command.DocumentTypeId))
                {
                    var cmnDocument = document as PatientCmnDocument;

                    if (cmnDocument != null)
                        cmnDocument.Update(command.DocumentTypeId, command.Description, command.ExpiredDate.Value);
                    else
                    {
                        newDocument = document.ToPatientCmnDocument(command.DocumentTypeId,
                            command.ExpiredDate.Value, command.Description);
                        document = null;
                    }
                }
                else
                {
                    var cmnDocument = document as PatientCmnDocument;

                    if (cmnDocument != null)
                    {
                        newDocument = cmnDocument.ToPatientDocument(command.DocumentTypeId, command.Description);
                        newDocument.Update(command.DocumentTypeId, command.Description);
                        document = null;
                    }
                    else
                    {
                        document.Update(command.DocumentTypeId, command.Description);
                    }
                }
                */

                var documentIsCmn = document is PatientCmnDocument;

                PatientDocument newDocument = null;
                if (documentIsCmn && !PatientCmnDocument.CmnDocumentTypes.Contains(command.DocumentTypeId) ||
                    !documentIsCmn && PatientCmnDocument.CmnDocumentTypes.Contains(command.DocumentTypeId)) //if types changes
                {
                    newDocument = documentIsCmn 
                        ? ((PatientCmnDocument) document).ToPatientDocument(command.DocumentTypeId, command.Description) 
                        : document.ToPatientCmnDocument(command.DocumentTypeId, command.ExpiredDate.Value, command.Description);

                    document = null;
                }
                else
                {
                    if (documentIsCmn)
                        ((PatientCmnDocument) document).Update(command.DocumentTypeId, command.ExpiredDate.Value, command.Description);
                    else
                        document.Update(command.DocumentTypeId, command.Description);
                }

                _patientDocumentRepository.Save(newDocument ?? document);
                scope.Complete();
            }
        }  

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).