public async Task <List <PatientProcedure> > getPatientOrder(string patientguid, string patientEncounter, string SearchFilters, string searchOrder, DateTime startDate, DateTime endDate, bool forFulfillment, string orderId, string caseId = null, bool isCancel = true, int pageNumber = 0) { if (string.IsNullOrEmpty(patientguid) && string.IsNullOrEmpty(caseId) && string.IsNullOrEmpty(patientEncounter) && string.IsNullOrEmpty(orderId)) { throw new ValidationException("Parameter missing"); } List <PatientProcedure> PatientProcedure = new List <PatientProcedure>(); mzk_patientorder patientOrderEntity = new mzk_patientorder(); #region Patient Procedure Query QueryExpression query = new QueryExpression(mzk_patientorder.EntityLogicalName); FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And); if (!string.IsNullOrEmpty(orderId)) { childFilter.AddCondition("mzk_patientorderid", ConditionOperator.Equal, new Guid(orderId)); } 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(patientguid)) { childFilter.AddCondition("mzk_customer", ConditionOperator.Equal, new Guid(patientguid)); } else if (!string.IsNullOrEmpty(patientEncounter)) { childFilter.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, new Guid(patientEncounter)); } if (isCancel == false) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.NotEqual, Convert.ToInt32(mzk_orderstatus.Cancelled)); } //Search Filter if (!string.IsNullOrEmpty(SearchFilters)) { if (SearchFilters == Convert.ToString(mzk_procedurefilter.Ordered)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Ordered)); } if (SearchFilters == Convert.ToString(mzk_procedurefilter.Started)) { childFilter.AddCondition("mzk_orderstatus", ConditionOperator.Equal, Convert.ToInt32(mzk_orderstatus.Started)); } if (SearchFilters == Convert.ToString(mzk_procedurefilter.Canceled)) { 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) }); } //Patient Order Type :: Procedure childFilter.AddCondition("mzk_type", ConditionOperator.Equal, (int)mzk_patientordermzk_Type.Procedure); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_patientorderid", "mzk_productid", "mzk_patientencounterid", "mzk_patientordernumber", "mzk_orderdate", "mzk_orderstatus", "mzk_comments", "mzk_userid", "createdon", "mzk_statusmanagerdetail", "mzk_treatmentlocation", "mzk_orderinglocation"); LinkEntity EntityProduct = new LinkEntity("mzk_patientorder", "product", "mzk_productid", "productid", JoinOperator.LeftOuter); EntityProduct.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_cptcodeid"); LinkEntity EntityUser = new LinkEntity("mzk_patientorderid", "systemuser", "mzk_userid", "systemuserid", JoinOperator.LeftOuter); EntityUser.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("positionid"); query.LinkEntities.Add(EntityProduct); query.LinkEntities.Add(EntityUser); 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) { PatientProcedure model = new PatientProcedure(); if (!this.getPatientOrder(model, entity, forFulfillment, orderId, mzk_entitytype.ProcedureOrder)) { continue; } if (entity.Attributes.Contains("mzk_productid")) { model.Title = ((EntityReference)entity.Attributes["mzk_productid"]).Name; } if (entity.Attributes.Contains("product3.mzk_cptcodeid")) { model.CPTCode = ((EntityReference)(entity.Attributes["product3.mzk_cptcodeid"] as AliasedValue).Value).Name; } else if (entity.Attributes.Contains("product1.mzk_cptcodeid")) { model.CPTCode = ((EntityReference)(entity.Attributes["product1.mzk_cptcodeid"] as AliasedValue).Value).Name; } if (entity.Attributes.Contains("mzk_userid")) { model.CareProvider = ((EntityReference)entity.Attributes["mzk_userid"]).Name; model.CareProviderId = ((EntityReference)entity.Attributes["mzk_userid"]).Id.ToString(); } if (entity.Attributes.Contains("systemuser4.positionid")) { model.Designation = ((EntityReference)(entity.Attributes["systemuser4.positionid"] as AliasedValue).Value).Name; } else if (entity.Attributes.Contains("systemuser2.positionid")) { model.Designation = ((EntityReference)(entity.Attributes["systemuser2.positionid"] as AliasedValue).Value).Name; } if (entity.Attributes.Contains("mzk_comments")) { model.Notes = entity.Attributes["mzk_comments"].ToString(); } if (entity.Attributes.Contains("mzk_treatmentlocation")) { model.treatmentLocationId = entity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Id.ToString(); model.treatmentLocation = entity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Name; } PatientOrderLog log = this.getOrderStatusLogDetails(Convert.ToInt32(model.OrderStatus), model.Id); if (log != null) { model.StatusNotes = log.Comments; } PatientProcedure.Add(model); } if (pageNumber > 0 && entitycollection != null) { Pagination.totalCount = entitycollection.TotalRecordCount; } return(PatientProcedure); }
public async Task <List <PatientSpecialTest> > getPatientOrder(string patientguid, string patientEncounter, string SearchFilters, string searchOrder, DateTime startDate, DateTime endDate, bool forFulfillment, string orderId, string caseId = null, int pageNumber = 0) { List <PatientSpecialTest> patientSpecialTestList = new List <PatientSpecialTest>(); if (string.IsNullOrEmpty(patientguid) && string.IsNullOrEmpty(caseId) && string.IsNullOrEmpty(patientEncounter) && string.IsNullOrEmpty(orderId)) { throw new ValidationException("Parameter missing"); } SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); EntityCollection entitycollection = entityRepository.GetEntityCollection(this.getSpecialTestQuery(patientguid, patientEncounter, SearchFilters, searchOrder, startDate, endDate, forFulfillment, orderId, caseId, pageNumber)); foreach (Entity entity in entitycollection.Entities) { PatientSpecialTest model = new PatientSpecialTest(); if (!this.getPatientOrder(model, entity, forFulfillment, orderId, mzk_entitytype.SpecialTestOrder)) { continue; } if (entity.Attributes.Contains("mzk_productid")) { model.TestName = ((EntityReference)entity["mzk_productid"]).Name; } if (entity.Attributes.Contains("mzk_associateddiagnosisid")) { model.DiagnosisId = ((EntityReference)entity["mzk_associateddiagnosisid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_concept5.mzk_conceptname")) { model.Diagnosis = (entity.Attributes["mzk_concept5.mzk_conceptname"] as AliasedValue).Value.ToString(); } else if (entity.Attributes.Contains("mzk_concept3.mzk_conceptname")) { model.Diagnosis = (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_frequencyid")) { model.FrequencyId = ((EntityReference)entity["mzk_frequencyid"]).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("mzk_urgency")) { model.UrgencyName = entity.FormattedValues["mzk_urgency"].ToString(); model.UrgencyId = ((OptionSetValue)entity["mzk_urgency"]).Value.ToString(); } if (entity.Attributes.Contains("mzk_treatmentlocation")) { model.treatmentLocationId = entity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Id.ToString(); model.treatmentLocation = entity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Name; } if (entity.Attributes.Contains("ownerid")) { model.OrderingPhysician = ((EntityReference)entity.Attributes["ownerid"]).Name; model.OrderingPhysicianId = ((EntityReference)entity.Attributes["ownerid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_clinicalnotes")) { model.ClinicalNotes = entity.Attributes["mzk_clinicalnotes"].ToString(); } PatientOrderLog log = this.getOrderStatusLogDetails(Convert.ToInt32(model.OrderStatus), model.Id); if (log != null) { model.StatusNotes = log.Comments; } patientSpecialTestList.Add(model); } if (pageNumber > 0 && entitycollection != null) { Pagination.totalCount = entitycollection.TotalRecordCount; } return(patientSpecialTestList); }
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); }