public bool hasDiagnosis(string encounterid) { bool diagnosis = false; if (!CaseParameter.getDiagnosisRequired(PatientCase.getCaseType(encounterid))) { return(true); } #region Patient Diadnosis Query QueryExpression query = new QueryExpression("mzk_patientencounterdiagnosis"); FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And); // Diagnosis childFilter.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, encounterid); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_patientencounterdiagnosisid"); #endregion SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); EntityCollection entitycollection = entityRepository.GetEntityCollection(query); if (entitycollection.Entities.Count > 0) { diagnosis = true; } return(diagnosis); }
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; } }
public async Task <List <PatientRadiologyOrder> > getPatientOrder(string patientguid, string patientEncounter, string SearchFilters, string searchOrder, DateTime startDate, DateTime endDate, bool forFulfillment, string orderId, string caseId = null, bool fromRIs = false, int pageNumber = 0) { List <PatientRadiologyOrder> PatientRadiologyOrder = new List <PatientRadiologyOrder>(); try { if (string.IsNullOrEmpty(patientguid) && string.IsNullOrEmpty(caseId) && string.IsNullOrEmpty(patientEncounter) && string.IsNullOrEmpty(orderId)) { throw new ValidationException("Parameter missing"); } #region Patient Radiology Order Query QueryExpression query = new QueryExpression("mzk_patientorder"); FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And); if (!string.IsNullOrEmpty(orderId)) { childFilter.AddCondition("mzk_patientorderid", ConditionOperator.Equal, new Guid(orderId)); } if (!fromRIs && SearchFilters != mzk_orderstatus.Cancelled.ToString()) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.NotEqual, (int)mzk_orderstatus.Cancelled); } if (!string.IsNullOrEmpty(caseId)) { childFilter.AddCondition("mzk_caseid", ConditionOperator.Equal, new Guid(caseId)); } if (!string.IsNullOrEmpty(patientguid)) { childFilter.AddCondition("mzk_customer", ConditionOperator.Equal, new Guid(patientguid)); } else { if (!string.IsNullOrEmpty(patientEncounter)) { childFilter.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, new Guid(patientEncounter)); } } childFilter.AddCondition("mzk_type", ConditionOperator.Equal, "3"); //Patient Order Type :: Radiology if (!string.IsNullOrEmpty(SearchFilters)) { if (SearchFilters == Convert.ToString(mzk_radiologyfilter.Ordered)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Ordered)); } if (SearchFilters == Convert.ToString(mzk_radiologyfilter.Paid)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Paid)); } if (SearchFilters == Convert.ToString(mzk_radiologyfilter.Cancelled)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Cancelled)); } } //Search Order if (!string.IsNullOrEmpty(searchOrder)) { childFilter.AddCondition("mzk_productidname", ConditionOperator.Like, ("%" + searchOrder + "%")); } //Search Date if (startDate != DateTime.MinValue && endDate != DateTime.MinValue) { childFilter.AddCondition("createdon", ConditionOperator.Between, new Object[] { startDate, endDate.AddHours(12) }); } query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_productid", "mzk_patientordernumber", "mzk_associateddiagnosisid", "mzk_frequencyid", "mzk_patientencounterid", "mzk_orderdate", "mzk_clinicalnotes", "mzk_studydate", "mzk_orderstatus", "createdby", "mzk_resultstatus", "mzk_reportpath", "mzk_reporturl", "mzk_axclinicrefrecid", "mzk_statusmanagerdetail", "createdon", "mzk_rislink", "mzk_fulfillmentdate", "mzk_fulfillmentappointment", "mzk_orderingappointment", "mzk_treatmentlocation", "mzk_orderinglocation"); if (!string.IsNullOrEmpty(orderId)) { LinkEntity Resource = new LinkEntity("mzk_patientorder", "systemuser", "createdby", "systemuserid", JoinOperator.Inner); Resource.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("fullname", "systemuserid"); Resource.EntityAlias = "Resource"; query.LinkEntities.Add(Resource); } LinkEntity EntityDiagnosis = new LinkEntity("mzk_patientorder", "mzk_concept", "mzk_associateddiagnosisid", "mzk_conceptid", JoinOperator.LeftOuter); EntityDiagnosis.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_conceptname", "mzk_icdcodeid"); LinkEntity EntityFrequecy = new LinkEntity("mzk_patientorder", "mzk_ordersetup", "mzk_frequencyid", "mzk_ordersetupid", JoinOperator.LeftOuter); EntityFrequecy.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); OrderExpression orderby = new OrderExpression(); orderby.AttributeName = "createdon"; orderby.OrderType = OrderType.Descending; LinkEntity ProductRecord = new LinkEntity("mzk_patientorder", "product", "mzk_productid", "productid", JoinOperator.LeftOuter); ProductRecord.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("productnumber"); ProductRecord.EntityAlias = "ProductRecord"; LinkEntity EntityFamily = new LinkEntity("product", "product", "parentproductid", "productid", JoinOperator.LeftOuter); EntityFamily.EntityAlias = "ProductFamily"; EntityFamily.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("productnumber"); ProductRecord.LinkEntities.Add(EntityFamily); query.LinkEntities.Add(EntityFrequecy); query.LinkEntities.Add(EntityDiagnosis); query.LinkEntities.Add(ProductRecord); query.Orders.Add(orderby); if (!forFulfillment && pageNumber > 0) { query.PageInfo = new Microsoft.Xrm.Sdk.Query.PagingInfo(); query.PageInfo.Count = Convert.ToInt32(AppSettings.GetByKey("PageSize")); query.PageInfo.PageNumber = pageNumber; query.PageInfo.PagingCookie = null; query.PageInfo.ReturnTotalRecordCount = true; } #endregion SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); EntityCollection entitycollection = entityRepository.GetEntityCollection(query); foreach (Entity entity in entitycollection.Entities) { PatientRadiologyOrder model = new PatientRadiologyOrder(); if (!this.getPatientOrder(model, entity, forFulfillment, orderId, mzk_entitytype.RadiologyOrder)) { continue; } if (entity.Attributes.Contains("mzk_productid")) { model.TestName = ((EntityReference)entity["mzk_productid"]).Name; } if (entity.Attributes.Contains("ProductRecord.productnumber")) { model.TestId = (entity.Attributes["ProductRecord.productnumber"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("ProductFamily.productnumber")) { model.ProductFamilyCode = (entity.Attributes["ProductFamily.productnumber"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_frequencyid")) { model.FrequencyId = ((EntityReference)entity["mzk_frequencyid"]).Id.ToString(); } if (entity.Attributes.Contains("createdon")) { model.CreatedOn = (DateTime)entity["createdon"]; } if (entity.Attributes.Contains("mzk_fulfillmentdate")) { model.FulfillmentDate = (DateTime)entity["mzk_fulfillmentdate"]; } if (entity.Attributes.Contains("mzk_ordersetup3.mzk_description")) { model.Frequency = (entity.Attributes["mzk_ordersetup3.mzk_description"] as AliasedValue).Value.ToString(); } else if (entity.Attributes.Contains("mzk_ordersetup1.mzk_description")) { model.Frequency = (entity.Attributes["mzk_ordersetup1.mzk_description"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_associateddiagnosisid")) { model.AssociatedDiagnosisId = ((EntityReference)entity["mzk_associateddiagnosisid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_concept4.mzk_conceptname")) { model.AssociatedDiagnosis = (entity.Attributes["mzk_concept4.mzk_conceptname"] as AliasedValue).Value.ToString(); } else if (entity.Attributes.Contains("mzk_concept2.mzk_conceptname")) { model.AssociatedDiagnosis = (entity.Attributes["mzk_concept2.mzk_conceptname"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_concept4.mzk_icdcodeid")) { model.ICDCode = ((EntityReference)((AliasedValue)entity.Attributes["mzk_concept4.mzk_icdcodeid"]).Value).Name; } else if (entity.Attributes.Contains("mzk_concept2.mzk_icdcodeid")) { model.ICDCode = ((EntityReference)((AliasedValue)entity.Attributes["mzk_concept2.mzk_icdcodeid"]).Value).Name; } if (entity.Attributes.Contains("mzk_clinicalnotes")) { model.ClinicalNotes = entity["mzk_clinicalnotes"].ToString(); } if (entity.Attributes.Contains("mzk_studydate")) { model.StudyDate = (entity["mzk_studydate"] as OptionSetValue).Value.ToString(); model.StudyDateText = entity.FormattedValues["mzk_studydate"].ToString(); } if (entity.Attributes.Contains("mzk_orderinglocation")) { model.orderingLocationId = entity.GetAttributeValue <EntityReference>("mzk_orderinglocation").Id.ToString(); model.orderingLocation = entity.GetAttributeValue <EntityReference>("mzk_orderinglocation").Name; } if (entity.Attributes.Contains("mzk_reporturl")) { model.RISLink = entity["mzk_reporturl"].ToString(); } if (entity.Attributes.Contains("mzk_resultstatus")) { model.ResultStatus = (entity["mzk_resultstatus"] as OptionSetValue).Value.ToString(); model.ResultStatusText = entity.FormattedValues["mzk_resultstatus"].ToString(); } if (entity.Attributes.Contains("mzk_reportpath")) { model.ReportPath = entity["mzk_reportpath"].ToString(); } if (!string.IsNullOrEmpty(orderId)) { if (entity.Attributes.Contains("createdby")) { orderingProvider = new User(); if (entity.Attributes.Contains("Resource.fullname")) { orderingProvider.Name = (entity.Attributes["Resource.fullname"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("Resource.systemuserid")) { orderingProvider.userId = (entity.Attributes["Resource.systemuserid"] as AliasedValue).Value.ToString(); } model.orderingProvider = orderingProvider; } if (string.IsNullOrEmpty(model.UrgencyId)) { if (string.IsNullOrEmpty(model.StudyDate)) { if (!string.IsNullOrEmpty(model.EncounterId)) { mzk_casetype caseType = PatientCase.getCaseType(model.EncounterId); model.UrgencyId = CaseParameter.getDefaultUrgency(caseType).urgencyId; } else if (entity.Attributes.Contains("mzk_fulfillmentappointment")) { mzk_casetype caseType = mzk_casetype.OutPatient; model.UrgencyId = CaseParameter.getDefaultUrgency(caseType).urgencyId; } } else { mzk_patientordermzk_StudyDate studyDate = (mzk_patientordermzk_StudyDate)Convert.ToInt32(model.StudyDate); switch (studyDate) { case mzk_patientordermzk_StudyDate.Routine: case mzk_patientordermzk_StudyDate.Thismonth: case mzk_patientordermzk_StudyDate._2weeks: model.UrgencyId = ((int)mzk_patientordermzk_Urgency.Routine).ToString(); break; case mzk_patientordermzk_StudyDate.Urgent: model.UrgencyId = ((int)mzk_patientordermzk_Urgency.Stat).ToString(); break; } } } if (entity.Attributes.Contains("mzk_fulfillmentappointment")) { Appointment appt = new Appointment().getAppointmentDetails((entity["mzk_fulfillmentappointment"] as EntityReference).Id.ToString()); if (appt != null) { model.ScheduleEndDateTime = Convert.ToDateTime(appt.endDateTime); model.ScheduleStartDateTime = Convert.ToDateTime(appt.startDateTime); } } } PatientRadiologyOrder.Add(model); } if (pageNumber > 0 && entitycollection != null) { Pagination.totalCount = entitycollection.TotalRecordCount; } } catch (Exception ex) { throw ex; } return(PatientRadiologyOrder); }
public async Task <List <PatientLabOrder> > getPatientOrder(string patientguid, string patientEncounter, string SearchFilters, string searchOrder, DateTime startDate, DateTime endDate, bool forFulfillment, string orderId, string caseId = null, int pageNumber = 0) { List <PatientLabOrder> PatientLabOrder = new List <PatientLabOrder>(); #region Patient Lab Order Query QueryExpression query = new QueryExpression("mzk_patientorder"); FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And); if (SearchFilters != mzk_orderstatus.Cancelled.ToString()) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.NotEqual, (int)mzk_orderstatus.Cancelled); } if (!string.IsNullOrEmpty(caseId)) { childFilter.AddCondition("mzk_caseid", ConditionOperator.Equal, new Guid(caseId)); } if (!string.IsNullOrEmpty(orderId)) { childFilter.AddCondition("mzk_patientorderid", ConditionOperator.Equal, new Guid(orderId)); } if (!string.IsNullOrEmpty(patientguid)) { childFilter.AddCondition("mzk_customer", ConditionOperator.Equal, new Guid(patientguid)); } else { if (!string.IsNullOrEmpty(patientEncounter)) { childFilter.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, new Guid(patientEncounter)); } } //Patient Order Type :: Laboratory childFilter.AddCondition("mzk_type", ConditionOperator.Equal, "2"); //Search Filter if (!string.IsNullOrEmpty(SearchFilters)) { if (SearchFilters == Convert.ToString(mzk_labfilter.Ordered)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Ordered)); } if (SearchFilters == Convert.ToString(mzk_labfilter.Paid)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Paid)); } if (SearchFilters == Convert.ToString(mzk_labfilter.Cancelled)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Cancelled)); } } //Search Order if (!string.IsNullOrEmpty(searchOrder)) { childFilter.AddCondition("mzk_productidname", ConditionOperator.Like, ("%" + searchOrder + "%")); } //Search Date if (startDate != DateTime.MinValue && endDate != DateTime.MinValue) { childFilter.AddCondition("createdon", ConditionOperator.Between, new Object[] { startDate, endDate.AddHours(12) }); } query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_productid", "mzk_patientordernumber", "mzk_associateddiagnosisid", "mzk_patientencounterid", "mzk_frequencyid", "mzk_orderdate", "mzk_customer", "createdby", "mzk_clinicalnotes", "mzk_resultstatus", "mzk_reportpath", "mzk_reporturl", "mzk_antibiotics", "mzk_orderstatus", "mzk_axclinicrefrecid", "mzk_statusmanagerdetail", "mzk_antibioticscomments", "createdon", "mzk_fulfillmentdate", "mzk_urgency", "mzk_lislink", "mzk_instructionstopatients", "mzk_specimensource", "mzk_treatmentlocation", "mzk_orderinglocation"); if (!string.IsNullOrEmpty(orderId)) { LinkEntity Resource = new LinkEntity("mzk_patientorder", "systemuser", "createdby", "systemuserid", JoinOperator.Inner); Resource.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("fullname", "systemuserid"); query.LinkEntities.Add(Resource); } LinkEntity EntityDiagnosis = new LinkEntity("mzk_patientorder", "mzk_concept", "mzk_associateddiagnosisid", "mzk_conceptid", JoinOperator.LeftOuter); EntityDiagnosis.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_conceptname", "mzk_icdcodeid"); LinkEntity EntityFrequecy = new LinkEntity("mzk_patientorder", "mzk_ordersetup", "mzk_frequencyid", "mzk_ordersetupid", JoinOperator.LeftOuter); EntityFrequecy.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); LinkEntity EntitySpecimenSource = new LinkEntity("mzk_patientorder", "mzk_ordersetup", "mzk_specimensource", "mzk_ordersetupid", JoinOperator.LeftOuter); EntitySpecimenSource.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_description"); EntitySpecimenSource.EntityAlias = "SpecimenSource"; OrderExpression orderby = new OrderExpression(); orderby.AttributeName = "createdon"; orderby.OrderType = OrderType.Descending; LinkEntity ProductRecord = new LinkEntity("mzk_patientorder", "product", "mzk_productid", "productid", JoinOperator.LeftOuter); ProductRecord.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("productnumber"); ProductRecord.EntityAlias = "ProductRecord"; 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"); ProductRecord.LinkEntities.Add(EntityFamily); query.LinkEntities.Add(EntityFrequecy); query.LinkEntities.Add(EntityDiagnosis); query.LinkEntities.Add(ProductRecord); query.LinkEntities.Add(EntitySpecimenSource); query.Orders.Add(orderby); if (!forFulfillment && pageNumber > 0) { query.PageInfo = new Microsoft.Xrm.Sdk.Query.PagingInfo(); query.PageInfo.Count = Convert.ToInt32(AppSettings.GetByKey("PageSize")); query.PageInfo.PageNumber = pageNumber; query.PageInfo.PagingCookie = null; query.PageInfo.ReturnTotalRecordCount = true; } #endregion SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); if (string.IsNullOrEmpty(patientguid) && string.IsNullOrEmpty(caseId) && string.IsNullOrEmpty(patientEncounter) && string.IsNullOrEmpty(orderId)) { throw new ValidationException("Parameter missing"); } EntityCollection entitycollection = entityRepository.GetEntityCollection(query); User orderingProvider; foreach (Entity entity in entitycollection.Entities) { PatientLabOrder model = new PatientLabOrder(); if (!this.getPatientOrder(model, entity, forFulfillment, orderId, mzk_entitytype.LabOrder)) { continue; } if (entity.Attributes.Contains("mzk_productid")) { model.TestName = ((EntityReference)entity["mzk_productid"]).Name; } if (entity.Attributes.Contains("ProductRecord.productnumber")) { model.TestId = (entity.Attributes["ProductRecord.productnumber"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_frequencyid")) { model.FrequencyId = ((EntityReference)entity["mzk_frequencyid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_customer")) { model.PatientId = ((EntityReference)entity["mzk_customer"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_ordersetup3.mzk_description")) { model.Frequency = (entity.Attributes["mzk_ordersetup3.mzk_description"] as AliasedValue).Value.ToString(); } else if (entity.Attributes.Contains("mzk_ordersetup1.mzk_description")) { model.Frequency = (entity.Attributes["mzk_ordersetup1.mzk_description"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("createdon")) { model.CreatedOn = (DateTime)entity["createdon"]; } if (entity.Attributes.Contains("mzk_fulfillmentdate")) { model.FulfillmentDate = (DateTime)entity["mzk_fulfillmentdate"]; } if (entity.Attributes.Contains("mzk_associateddiagnosisid")) { model.AssociatedDiagnosisId = ((EntityReference)entity["mzk_associateddiagnosisid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_concept5.mzk_conceptname")) { model.AssociatedDiagnosis = (entity.Attributes["mzk_concept5.mzk_conceptname"] as AliasedValue).Value.ToString(); } else if (entity.Attributes.Contains("mzk_concept3.mzk_conceptname")) { model.AssociatedDiagnosis = (entity.Attributes["mzk_concept3.mzk_conceptname"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_concept5.mzk_icdcodeid")) { model.ICDCode = ((EntityReference)((AliasedValue)entity.Attributes["mzk_concept5.mzk_icdcodeid"]).Value).Name; } else if (entity.Attributes.Contains("mzk_concept3.mzk_icdcodeid")) { model.ICDCode = ((EntityReference)((AliasedValue)entity.Attributes["mzk_concept3.mzk_icdcodeid"]).Value).Name; } if (entity.Attributes.Contains("mzk_clinicalnotes")) { model.ClinicalNotes = entity["mzk_clinicalnotes"].ToString(); } if (entity.Attributes.Contains("mzk_antibiotics") && entity.Attributes["mzk_antibiotics"].ToString() == "True") { model.Antibiotics = "1"; } else { model.Antibiotics = "0"; } if (entity.Attributes.Contains("mzk_antibioticscomments")) { model.AntibioticsComments = entity["mzk_antibioticscomments"].ToString(); } if (entity.Attributes.Contains("mzk_lislink")) { model.LISLink = entity["mzk_lislink"].ToString(); } if (entity.Attributes.Contains("mzk_urgency")) { model.UrgencyName = entity.FormattedValues["mzk_urgency"].ToString(); } //else // if (entity.Attributes.Contains("mzk_ordersetup2.mzk_description")) // model.UrgencyName = (entity.Attributes["mzk_ordersetup2.mzk_description"] as AliasedValue).Value.ToString(); if (entity.Attributes.Contains("mzk_urgency")) { model.UrgencyId = ((OptionSetValue)entity.Attributes["mzk_urgency"]).Value.ToString(); } if (entity.Attributes.Contains("ProductFamily.mzk_antibioticmandatory")) { model.antiBioticRequired = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_antibioticmandatory"]).Value; } if (entity.Attributes.Contains("ProductFamily.mzk_commentsmandatory")) { model.commentsRequired = (bool)((AliasedValue)entity.Attributes["ProductFamily.mzk_commentsmandatory"]).Value; } if (entity.Attributes.Contains("mzk_specimensource")) { model.SpecimenSourceId = ((EntityReference)entity["mzk_specimensource"]).Id.ToString(); } if (entity.Attributes.Contains("SpecimenSource.mzk_description")) { model.SpecimenSourceName = (entity.Attributes["SpecimenSource.mzk_description"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_instructionstopatients")) { model.Instructionstopatients = entity.Attributes["mzk_instructionstopatients"].ToString(); } if (entity.Attributes.Contains("mzk_reporturl")) { model.LISLink = entity["mzk_reporturl"].ToString(); } if (entity.Attributes.Contains("mzk_resultstatus")) { model.ResultStatus = (entity["mzk_resultstatus"] as OptionSetValue).Value.ToString(); model.ResultStatusText = entity.FormattedValues["mzk_resultstatus"].ToString(); } PatientOrderLog log = this.getOrderStatusLogDetails(Convert.ToInt32(model.OrderStatus), model.Id); if (log != null) { model.SampleLocation = log.Location; } if (!string.IsNullOrEmpty(orderId)) { if (entity.Attributes.Contains("createdby")) { orderingProvider = new User(); if (entity.Attributes.Contains("Resource.fullname")) { orderingProvider.Name = (entity.Attributes["Resource.fullname"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("Resource.systemuserid")) { orderingProvider.userId = (entity.Attributes["Resource.systemuserid"] as AliasedValue).Value.ToString(); } model.orderingProvider = orderingProvider; } if (string.IsNullOrEmpty(model.UrgencyId)) { mzk_casetype caseType = PatientCase.getCaseType(model.EncounterId); model.UrgencyId = CaseParameter.getDefaultUrgency(caseType).urgencyId; } if (entity.Attributes.Contains("mzk_orderinglocation")) { model.orderingLocationId = entity.GetAttributeValue <EntityReference>("mzk_orderinglocation").Id.ToString(); model.orderingLocation = entity.GetAttributeValue <EntityReference>("mzk_orderinglocation").Name.ToString(); } } PatientLabOrder.Add(model); } if (pageNumber > 0 && entitycollection != null) { Pagination.totalCount = entitycollection.TotalRecordCount; } return(PatientLabOrder); }
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; } }