Exemplo n.º 1
0
        public async Task <bool> updatePatientOrder(PatientReferralOrder patientReferral)
        {
            try
            {
                SoapEntityRepository entityRepository = SoapEntityRepository.GetService();
                Entity referralEntity = entityRepository.GetEntity(mzk_patientorder.EntityLogicalName, new Guid(patientReferral.Id)
                {
                },
                                                                   new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_customer",
                                                                                                         "mzk_appointmentrecommendation",
                                                                                                         "mzk_associateddiagnosisid",
                                                                                                         "mzk_patientaware",
                                                                                                         "mzk_comments",
                                                                                                         "mzk_orderstatus",
                                                                                                         "mzk_referraltoid",
                                                                                                         "mzk_referraltype",
                                                                                                         "mzk_specialityid",
                                                                                                         "ownerid",
                                                                                                         "mzk_patientordernumber",
                                                                                                         "createdon",
                                                                                                         "mzk_referralcategory",
                                                                                                         "mzk_referraltoexternalid"));

                if (!string.IsNullOrEmpty(patientReferral.PatientId))
                {
                    referralEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(patientReferral.PatientId));
                }

                if (!string.IsNullOrEmpty(patientReferral.Diagnosis))
                {
                    referralEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(patientReferral.Diagnosis));
                }

                if (!string.IsNullOrEmpty(patientReferral.ReferralComment))
                {
                    referralEntity.Attributes["mzk_comments"] = patientReferral.ReferralComment;
                }

                if (patientReferral.PatientAware.ToString() != "1")
                {
                    referralEntity.Attributes["mzk_patientaware"] = true;
                }
                else
                {
                    referralEntity.Attributes["mzk_patientaware"] = false;
                }

                if (patientReferral.Apptrecommendation != 0)
                {
                    referralEntity.Attributes["mzk_appointmentrecommendation"] = new OptionSetValue(patientReferral.Apptrecommendation);
                }

                //for ReferralType Consultation, Consultation & Treatment and Transfer of Care
                if (patientReferral.ReferralType != 0)
                {
                    referralEntity.Attributes["mzk_referraltype"] = new OptionSetValue(patientReferral.ReferralType);
                }

                //for Category Internal /External
                if (patientReferral.Category != 0 && patientReferral.Category == Convert.ToInt32(mzk_patientordermzk_ReferralCategory.Internal))
                {
                    referralEntity.Attributes["mzk_referralcategory"] = new OptionSetValue(Convert.ToInt32(patientReferral.Category));

                    if (!string.IsNullOrEmpty(patientReferral.ReferralId))
                    {
                        referralEntity.Attributes["mzk_referraltoid"] = new EntityReference("systemuser", new Guid(patientReferral.ReferralId));
                    }
                }
                else
                {
                    if (patientReferral.Category != 0 && patientReferral.Category == Convert.ToInt32(mzk_patientordermzk_ReferralCategory.External))
                    {
                        referralEntity.Attributes["mzk_referralcategory"] = new OptionSetValue(Convert.ToInt32(patientReferral.Category));

                        if (!string.IsNullOrEmpty(patientReferral.ReferralId))
                        {
                            referralEntity.Attributes["mzk_referraltoexternalid"] = new EntityReference("mzk_referringphysician", new Guid(patientReferral.ReferralId));
                        }
                    }
                }
                if (!string.IsNullOrEmpty(patientReferral.SpecialtyId))
                {
                    referralEntity.Attributes["mzk_specialityid"] = new EntityReference("characteristic", new Guid(patientReferral.SpecialtyId));

                    var specialityNameList = new List <string> {
                        patientReferral.SpecialtyId
                    };

                    Speciality speciality = new Speciality();

                    referralEntity.Attributes["mzk_specialtyname"] = speciality.getSpecialityList(specialityNameList).First <Speciality>().Description;
                }

                if (!string.IsNullOrEmpty(patientReferral.HospitalId))
                {
                    referralEntity.Attributes["mzk_hospitalid"] = new EntityReference("mzk_hospital", new Guid(patientReferral.HospitalId));
                }

                entityRepository.UpdateEntity(referralEntity);
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public async Task <string> addPatientOrder(PatientReferralOrder _patientReferral)
        {
            SoapEntityRepository entityRepository = SoapEntityRepository.GetService();
            mzk_patientorder     referralEntity   = new mzk_patientorder();

            try
            {
                referralEntity.mzk_appointable = true;

                if (!string.IsNullOrEmpty(_patientReferral.appointmentId))
                {
                    referralEntity.mzk_orderingappointment    = new EntityReference("mzk_patientorder", new Guid(_patientReferral.appointmentId));
                    referralEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(_patientReferral.appointmentId));
                }

                if (!string.IsNullOrEmpty(_patientReferral.PatientId))
                {
                    referralEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(_patientReferral.PatientId));
                }

                if (!string.IsNullOrEmpty(_patientReferral.EncounterId))
                {
                    referralEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(_patientReferral.EncounterId));
                    PatientEncounter encounter = new PatientEncounter();
                    encounter.EncounterId = _patientReferral.EncounterId;
                    //PatientId = new PatientCase().getCaseDetails(encounter.encounterDetails(encounter).Result.ToList().First<PatientEncounter>().CaseId).Result.PatientId;
                    PatientId = encounter.getEncounterDetails(encounter).Result.ToList().First <PatientEncounter>().PatientId;
                    referralEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId));
                }

                if (!string.IsNullOrEmpty(_patientReferral.Diagnosis))
                {
                    referralEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(_patientReferral.Diagnosis));
                }

                if (_patientReferral.clinicRecId > 0)
                {
                    referralEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(_patientReferral.clinicRecId);
                }

                if (!string.IsNullOrEmpty(_patientReferral.orderingLocationId))
                {
                    referralEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(_patientReferral.orderingLocationId));
                }

                if (!string.IsNullOrEmpty(_patientReferral.ReferralComment))
                {
                    referralEntity.Attributes["mzk_comments"] = _patientReferral.ReferralComment;
                }

                if (_patientReferral.PatientAware.ToString() != "1")
                {
                    referralEntity.Attributes["mzk_patientaware"] = true;
                }
                else
                {
                    referralEntity.Attributes["mzk_patientaware"] = false;
                }

                if (_patientReferral.Apptrecommendation != 0)
                {
                    referralEntity.Attributes["mzk_appointmentrecommendation"] = new OptionSetValue(_patientReferral.Apptrecommendation);
                }

                //for ReferralType Consultation, Consultation & Treatment and Transfer of Care
                if (_patientReferral.ReferralType != 0)
                {
                    referralEntity.Attributes["mzk_referraltype"] = new OptionSetValue(_patientReferral.ReferralType);
                }


                //for Category Internal /External
                if (_patientReferral.Category != 0 && _patientReferral.Category == Convert.ToInt32(mzk_patientordermzk_ReferralCategory.Internal))
                {
                    referralEntity.Attributes["mzk_referralcategory"] = new OptionSetValue(Convert.ToInt32(_patientReferral.Category));

                    if (!string.IsNullOrEmpty(_patientReferral.ReferralId))
                    {
                        referralEntity.Attributes["mzk_referraltoid"] = new EntityReference("systemuser", new Guid(_patientReferral.ReferralId));
                    }
                }
                else
                {
                    if (_patientReferral.Category != 0 && _patientReferral.Category == Convert.ToInt32(mzk_patientordermzk_ReferralCategory.External))
                    {
                        referralEntity.Attributes["mzk_referralcategory"] = new OptionSetValue(Convert.ToInt32(_patientReferral.Category));

                        if (!string.IsNullOrEmpty(_patientReferral.ReferralId))
                        {
                            referralEntity.Attributes["mzk_referraltoexternalid"] = new EntityReference("mzk_referringphysician", new Guid(_patientReferral.ReferralId));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(_patientReferral.SpecialtyId))
                {
                    referralEntity.Attributes["mzk_specialityid"] = new EntityReference("characteristic", new Guid(_patientReferral.SpecialtyId));

                    var specialityNameList = new List <string> {
                        _patientReferral.SpecialtyId
                    };

                    Speciality speciality = new Speciality();

                    referralEntity.Attributes["mzk_specialtyname"] = speciality.getSpecialityList(specialityNameList).First <Speciality>().Description;
                }

                if (!string.IsNullOrEmpty(_patientReferral.HospitalId) && _patientReferral.HospitalId != "0")
                {
                    referralEntity.Attributes["mzk_hospitalid"] = new EntityReference("mzk_hospital", new Guid(_patientReferral.HospitalId));
                }

                referralEntity.Attributes["mzk_type"]        = new OptionSetValue(Convert.ToInt32(mzk_patientordermzk_Type.Referral));
                referralEntity.Attributes["mzk_orderstatus"] = new OptionSetValue((int)mzk_orderstatus.Ordered);

                referralEntity.Attributes["mzk_orderdate"]       = DateTime.Now.Date;
                referralEntity.Attributes["mzk_fulfillmentdate"] = referralEntity.Attributes["mzk_orderdate"];


                Id = Convert.ToString(entityRepository.CreateEntity(referralEntity));

                if (!string.IsNullOrEmpty(_patientReferral.EncounterId) && !string.IsNullOrEmpty(_patientReferral.SpecialtyId))
                {
                    mzk_casetype caseType = PatientCase.getCaseType(_patientReferral.EncounterId);

                    if (caseType == mzk_casetype.Emergency && _patientReferral.Category == Convert.ToInt32(mzk_patientordermzk_ReferralCategory.Internal))
                    {
                        List <string> specialtyIdList = new List <string>();
                        specialtyIdList.Add(_patientReferral.SpecialtyId);

                        Speciality sp = new Speciality().getSpecialityList(specialtyIdList).FirstOrDefault();

                        if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower())
                        {
                            if (sp != null && sp.SpecialityRefRecId > 0)
                            {
                                await this.createCaseTrans(_patientReferral.EncounterId, Id, "", mzk_orderstatus.Ordered, 1, "", HMUrgency.None, "", "", "", sp.SpecialityRefRecId);
                            }
                        }
                    }
                }

                return(Id.ToString());
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrEmpty(Id))
                {
                    entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id));
                }

                throw ex;
            }
        }