bool isValidGroup(mzk_mmtgroupcode mmtgroupcode, string patientguid) { bool ret = false; int patientGender = 0; DateTime patientBirthDate; AgeHelper ageHelper = new AgeHelper(DateTime.Now); Patient patient = new Patient(); PatientRepository patientRepo = new PatientRepository(); patient = new Patient().getPatientDetails(patientguid).Result; patientBirthDate = patient.dateOfBirth; patientGender = patient.genderValue; if (mmtgroupcode.mzk_FilteronGender.HasValue) { if (mmtgroupcode.mzk_FilteronGender.Value) { if (patientGender == mmtgroupcode.mzk_Gender.Value) { ret = true; } else { ret = false; } } else { ret = true; } } else { ret = true; } if (ret) { if (mmtgroupcode.mzk_FilteronAge.HasValue) { if (mmtgroupcode.mzk_FilteronAge.Value) { if (mmtgroupcode.mzk_AgeValidationId != null) { if (ageHelper.isAgeMatched(patientBirthDate, (Helper.Enum.DayWeekMthYr)((OptionSetValue)((AliasedValue)mmtgroupcode.Attributes["AgeValidation.mzk_agefromunit"]).Value).Value, (int)((AliasedValue)mmtgroupcode.Attributes["AgeValidation.mzk_agefromvalue"]).Value, (Helper.Enum.DayWeekMthYr)((OptionSetValue)((AliasedValue)mmtgroupcode.Attributes["AgeValidation.mzk_agetounit"]).Value).Value, (int)((AliasedValue)mmtgroupcode.Attributes["AgeValidation.mzk_agetovalue"]).Value)) { ret = true; } else { ret = false; } } } else { ret = true; } } else { ret = true; } } return(ret); }
public List <Products> getProduct(Products product, int pageNumber = 0) { try { List <Products> Products = new List <Products>(); #region Product QueryExpression query = new QueryExpression("product"); query.Criteria.AddCondition("productstructure", ConditionOperator.NotEqual, (int)ProductProductStructure.ProductFamily); query.Criteria.AddCondition("statecode", ConditionOperator.Equal, (int)ProductState.Active); ConditionExpression condition1 = new ConditionExpression(); condition1.AttributeName = "name"; condition1.Operator = ConditionOperator.Like; ConditionExpression condition2 = new ConditionExpression(); condition2.AttributeName = "mzk_producttype"; condition2.Operator = ConditionOperator.Equal; if (!string.IsNullOrEmpty(product.Type)) { condition2.Values.Add(product.Type); } FilterExpression filter1 = new FilterExpression(LogicalOperator.And); FilterExpression filter2 = new FilterExpression(); if (!string.IsNullOrEmpty(product.Name.ToLower())) { if (product.Type == "4") { if (product.Name.Contains(' ')) { try { string[] words = product.Name.Split(new Char[] { ' ' }); if (words.Length > 1 && words.Length < 3) { // filter1 = entityTypeDetails.LinkCriteria.AddFilter(LogicalOperator.Or); condition1.Values.Add("%" + words[0] + "%"); filter1.Conditions.Add(new ConditionExpression("name", ConditionOperator.Like, "%" + words[1] + "%")); filter1.Conditions.Add(condition1); } else if (words.Length > 2) { condition1.Values.Add("%" + words[0] + "%"); filter1.Conditions.Add(condition1); filter1.Conditions.Add(new ConditionExpression("name", ConditionOperator.Like, "%" + words[1] + "%")); filter1.Conditions.Add(new ConditionExpression("name", ConditionOperator.Like, "%" + words[2] + "%")); } } catch (Exception ex) { condition1.Values.Add("%" + product.Name + "%"); filter1.Conditions.Add(condition1); } } else { condition1.Values.Add("%" + product.Name + "%"); filter1.Conditions.Add(condition1); } } else if (product.Type == ((int)Productmzk_ProductType.Lab).ToString()) { filter1 = new FilterExpression(LogicalOperator.Or); filter1.AddCondition("name", ConditionOperator.Like, ("%" + product.Name.ToLower() + "%")); filter1.AddCondition("productnumber", ConditionOperator.Like, ("%" + product.Name.ToLower() + "%")); } else { condition1.Values.Add("%" + product.Name + "%"); filter1.Conditions.Add(condition1); } } filter2.Conditions.Add(condition2); query.Criteria.AddFilter(filter1); query.Criteria.AddFilter(filter2); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("name", "mzk_dosageid", "productnumber", "productid", "mzk_available", "mzk_diagnosisid", "mzk_frequencyid", "mzk_unitid", "mzk_routeid", "mzk_duration", "mzk_instruction", "parentproductid", "mzk_contrast", "mzk_specimensource", "mzk_axitemid"); LinkEntity EntityDiagnosis = new LinkEntity("product", "mzk_concept", "mzk_diagnosisid", "mzk_conceptid", JoinOperator.LeftOuter); EntityDiagnosis.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_conceptname"); LinkEntity EntityFrequency = new LinkEntity("product", "mzk_ordersetup", "mzk_frequencyid", "mzk_ordersetupid", JoinOperator.LeftOuter); EntityFrequency.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); LinkEntity EntityRoute = new LinkEntity("product", "mzk_ordersetup", "mzk_routeid", "mzk_ordersetupid", JoinOperator.LeftOuter); EntityRoute.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); LinkEntity EntityUnit = new LinkEntity("product", "mzk_unit", "mzk_unitid", "mzk_unitid", JoinOperator.LeftOuter); EntityUnit.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); LinkEntity EntityDosage = new LinkEntity("product", "mzk_dosageform", "mzk_dosageid", "mzk_dosageformid", JoinOperator.LeftOuter); EntityDosage.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_dosageformid"); EntityDosage.EntityAlias = "Dosage"; LinkEntity EntityUserFavourite; if (!string.IsNullOrEmpty(product.filter) && product.filter == "favourite") { EntityUserFavourite = new LinkEntity("product", "mzk_userfavourite", "productid", "mzk_productid", JoinOperator.Inner); } else { EntityUserFavourite = new LinkEntity("product", "mzk_userfavourite", "productid", "mzk_productid", JoinOperator.LeftOuter); } EntityUserFavourite.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); EntityUserFavourite.EntityAlias = "ProductFavourite"; LinkEntity EntityFamily = new LinkEntity("product", "product", "parentproductid", "productid", JoinOperator.LeftOuter); EntityFamily.EntityAlias = "ProductFamily"; EntityFamily.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_antibioticmandatory", "mzk_commentsmandatory", "mzk_controlleddrug", "mzk_sedation", "mzk_agefromunit", "mzk_agefromvalue", "mzk_agetounit", "mzk_agetovalue"); query.LinkEntities.Add(EntityDiagnosis); query.LinkEntities.Add(EntityFrequency); query.LinkEntities.Add(EntityRoute); query.LinkEntities.Add(EntityUnit); // query.LinkEntities.Add(EntityImportance); query.LinkEntities.Add(EntityFamily); query.LinkEntities.Add(EntityDosage); if (!string.IsNullOrEmpty(product.UserId)) { EntityUserFavourite.LinkCriteria.AddCondition("mzk_userid", ConditionOperator.Equal, product.UserId); query.LinkEntities.Add(EntityUserFavourite); } if (pageNumber > 0) { query.PageInfo = new PagingInfo(); query.PageInfo.Count = Convert.ToInt32(AppSettings.GetByKey("PageSize")); query.PageInfo.PageNumber = product.currentpage; query.PageInfo.PagingCookie = null; query.PageInfo.ReturnTotalRecordCount = true; } #endregion SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); EntityCollection entitycollection = entityRepository.GetEntityCollection(query); CaseParameter caseParm = null; List <string> prodExistList = new List <string>(); if (!string.IsNullOrEmpty(product.EncounterId)) { caseParm = CaseParameter.getDefaultUrgency(PatientCase.getCaseType(product.EncounterId)); query = new QueryExpression(mzk_patientorder.EntityLogicalName); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); query.Criteria.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, product.EncounterId); query.Criteria.AddCondition("mzk_orderstatus", ConditionOperator.Equal, (int)mzk_orderstatus.Ordered); query.Criteria.AddCondition("mzk_productid", ConditionOperator.NotNull); EntityCollection entitycollectionOrders = entityRepository.GetEntityCollection(query); foreach (Entity entity in entitycollectionOrders.Entities) { mzk_patientorder order = (mzk_patientorder)entity; prodExistList.Add(order.mzk_ProductId.Id.ToString()); } } foreach (Entity entity in entitycollection.Entities) { Products model = new Products(); if (entity.Attributes.Contains("name")) { model.Name = entity.Attributes["name"].ToString(); } if (entity.Attributes.Contains("productnumber")) { model.ProductNumber = entity.Attributes["productnumber"].ToString(); } if (entity.Attributes.Contains("productid")) { model.ProductId = entity.Id.ToString(); } if (entity.Attributes.Contains("mzk_available")) { model.Available = Convert.ToBoolean(entity.Attributes["mzk_available"].ToString()); } if (entity.Attributes.Contains("mzk_contrast")) { model.contrastOrder = Convert.ToBoolean(entity.Attributes["mzk_contrast"].ToString()); } //Diagnosis if (entity.Attributes.Contains("mzk_diagnosisid")) { model.DiagnosisId = ((EntityReference)entity.Attributes["mzk_diagnosisid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_concept1.mzk_conceptname")) { model.DiagnosisName = (entity.Attributes["mzk_concept1.mzk_conceptname"] as AliasedValue).Value.ToString(); } //Frequency if (entity.Attributes.Contains("mzk_frequencyid")) { model.FrequencyId = ((EntityReference)entity.Attributes["mzk_frequencyid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_ordersetup2.mzk_description")) { model.FrequencyName = (entity.Attributes["mzk_ordersetup2.mzk_description"] as AliasedValue).Value.ToString(); } //Route if (entity.Attributes.Contains("mzk_routeid")) { model.RouteId = ((EntityReference)entity.Attributes["mzk_routeid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_ordersetup3.mzk_description")) { model.RouteName = (entity.Attributes["mzk_ordersetup3.mzk_description"] as AliasedValue).Value.ToString(); } //Unit if (entity.Attributes.Contains("mzk_unitid")) { model.UnitId = ((EntityReference)entity.Attributes["mzk_unitid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_unit4.mzk_description")) { model.UnitName = (entity.Attributes["mzk_unit4.mzk_description"] as AliasedValue).Value.ToString(); } if (!string.IsNullOrEmpty(product.EncounterId) && caseParm != null) { model.UrgencyId = caseParm.urgencyId; model.UrgencyName = caseParm.urgencyName; } //Instruction if (entity.Attributes.Contains("mzk_instruction")) { model.Instruction = entity.Attributes["mzk_instruction"].ToString(); } if (entity.Attributes.Contains("mzk_specimensource")) { model.IsSpecimenSource = (bool)entity.Attributes["mzk_specimensource"]; } if (model.IsSpecimenSource == false) { if (!string.IsNullOrEmpty(product.EncounterId)) { model.isAdded = !prodExistList.Exists(item => item == entity.Id.ToString()); //model.isAdded = new PatientEncounter().DuplicateDetection(product.EncounterId, entity.Id.ToString()); } } else { model.isAdded = true; } if (entity.Attributes.Contains("ProductFavourite.mzk_userfavouriteid")) { model.FavouriteId = (entity.Attributes["ProductFavourite.mzk_userfavouriteid"] as AliasedValue).Value.ToString(); } //Parameters if (entity.Attributes.Contains("ProductFamily.mzk_antibioticmandatory")) { model.antiBioticRequired = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_antibioticmandatory"]).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_controlleddrug")) { model.controlledDrugs = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_controlleddrug"]).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_commentsmandatory")) { model.commentsRequired = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_commentsmandatory"]).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_sedation") && !string.IsNullOrEmpty(product.patientId)) { model.sedationOrder = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_sedation"]).Value; if (model.sedationOrder) { AgeHelper ageHelper = new AgeHelper(DateTime.Now); DateTime patientBirthDate; Patient patient = new Patient(); Helper.Enum.DayWeekMthYr ageFromUnit = Helper.Enum.DayWeekMthYr.Days, ageToUnit = Helper.Enum.DayWeekMthYr.Days; int ageFromValue = 0, ageToValue = 0; patientBirthDate = patient.getPatientDetails(product.patientId).Result.dateOfBirth; if (entity.Attributes.Contains("ProductFamily.mzk_agefromunit") && (entity.Attributes["ProductFamily.mzk_agefromunit"] as AliasedValue) != null) { ageFromUnit = (Helper.Enum.DayWeekMthYr)((entity.Attributes["ProductFamily.mzk_agefromunit"] as AliasedValue).Value as OptionSetValue).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_agetounit") && (entity.Attributes["ProductFamily.mzk_agetounit"] as AliasedValue) != null) { ageToUnit = (Helper.Enum.DayWeekMthYr)((entity.Attributes["ProductFamily.mzk_agetounit"] as AliasedValue).Value as OptionSetValue).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_agefromvalue") && (entity.Attributes["ProductFamily.mzk_agefromvalue"] as AliasedValue) != null) { ageFromValue = (int)((entity.Attributes["ProductFamily.mzk_agefromvalue"] as AliasedValue).Value); } if (entity.Attributes.Contains("ProductFamily.mzk_agetovalue") && (entity.Attributes["ProductFamily.mzk_agetovalue"] as AliasedValue) != null) { ageToValue = (int)((entity.Attributes["ProductFamily.mzk_agetovalue"] as AliasedValue).Value); } model.sedationOrder = ageHelper.isAgeMatched(patientBirthDate, ageFromUnit, ageFromValue, ageToUnit, ageToValue); } } if (entity.Attributes.Contains("mzk_dosageid")) { model.Dosage = ((EntityReference)entity.Attributes["mzk_dosageid"]).Id.ToString(); } if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(product.clinicId) && entity.Attributes.Contains("mzk_axitemid") && !string.IsNullOrEmpty(entity.Attributes["mzk_axitemid"].ToString())) { CommonRepository comRepo = new CommonRepository(); Clinic clinic = new Clinic().getClinicDetails(product.clinicId); Dictionary <int, int> retStock = comRepo.checkItemInStock(entity.Attributes["mzk_axitemid"].ToString(), clinic.mzk_axclinicrefrecid); if (retStock != null && retStock.Count > 0) { int availableValue = 0; if (retStock.TryGetValue(0, out availableValue)) { model.availableForClinic = availableValue == 0 ? false : true; } if (retStock.TryGetValue(1, out availableValue)) { model.availableForPharmacy = availableValue == 0 ? false : true; } } } } Products.Add(model); } if (pageNumber > 0 && entitycollection != null) { Pagination.totalCount = entitycollection.TotalRecordCount; } return(Products); } catch (Exception ex) { throw ex; } }