public CaseParameter getParameters(mzk_casetype caseType) { CaseParameter model = new CaseParameter(); try { SoapEntityRepository repo = SoapEntityRepository.GetService(); QueryExpression query = new QueryExpression(mzk_caseparamter.EntityLogicalName); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); query.Criteria.AddCondition("mzk_casetype", ConditionOperator.Equal, (int)caseType); EntityCollection entitycollection = repo.GetEntityCollection(query); if (entitycollection != null && entitycollection.Entities != null && entitycollection.Entities.Count > 0) { mzk_caseparamter entity = (mzk_caseparamter)entitycollection.Entities[0]; model.diagnosisRequired = entity.mzk_DiagnosisRequired.HasValue ? entity.mzk_DiagnosisRequired.Value : false; model.urgencyId = entity.mzk_Urgency != null?entity.mzk_Urgency.Value.ToString() : ""; model.urgencyName = entity.FormattedValues["mzk_urgency"].ToString(); } } catch (Exception ex) { throw ex; } return(model); }
public static bool getDiagnosisRequired(mzk_casetype caseType) { try { CaseParameter model = new CaseParameter(); model = model.getParameters(caseType); return(model.diagnosisRequired); } catch (Exception ex) { throw ex; } }
public static CaseParameter getDefaultUrgency(mzk_casetype caseType) { try { CaseParameter model = new CaseParameter(); model = model.getParameters(caseType); return(model); } catch (Exception ex) { throw ex; } }
public static mzk_casetype getCaseType(string encounterId, string caseId = "") { try { mzk_casetype caseType = mzk_casetype.OutPatient; PatientCase model = new PatientCase(); QueryExpression query = new QueryExpression(xrm.Incident.EntityLogicalName); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_casetype"); if (string.IsNullOrEmpty(caseId)) { LinkEntity enc = new LinkEntity(xrm.Incident.EntityLogicalName, mzk_patientencounter.EntityLogicalName, "incidentid", "mzk_caseid", JoinOperator.Inner); enc.LinkCriteria.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, new Guid(encounterId)); query.LinkEntities.Add(enc); } else { query.Criteria.AddCondition("incidentid", ConditionOperator.Equal, new Guid(caseId)); } SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); EntityCollection entitycollection = entityRepository.GetEntityCollection(query); if (entitycollection != null && entitycollection.Entities != null && entitycollection.Entities.Count > 0) { xrm.Incident entity = (xrm.Incident)entitycollection.Entities[0]; caseType = entity.mzk_CaseType != null ? (mzk_casetype)entity.mzk_CaseType.Value : caseType; } return(caseType); } catch (Exception ex) { throw ex; } }
public async Task <string> addPatientOrder(PatientSpecialTest patientSpecialTest, bool isActivityOrder = false) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); xrm.mzk_patientorder patientOrderEntity = new xrm.mzk_patientorder(); HMUrgency urgency = HMUrgency.None; try { mzk_casetype caseType = mzk_casetype.OutPatient; patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientSpecialTest.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientSpecialTest.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientSpecialTest.appointmentId)); } if (patientSpecialTest.TestName != string.Empty && patientSpecialTest.TestName != null) { patientOrderEntity.Attributes["mzk_productid"] = new EntityReference("product", new Guid(patientSpecialTest.TestName)); } if (patientSpecialTest.Frequency != string.Empty && patientSpecialTest.Frequency != null) { patientOrderEntity.Attributes["mzk_frequencyid"] = new EntityReference("mzk_ordersetup", new Guid(patientSpecialTest.Frequency)); } if (patientSpecialTest.AssociatedDiagnosis != string.Empty && patientSpecialTest.AssociatedDiagnosis != null) { patientOrderEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(patientSpecialTest.AssociatedDiagnosis)); } if (patientSpecialTest.UrgencyId != string.Empty && patientSpecialTest.UrgencyId != null) { patientOrderEntity.Attributes["mzk_urgency"] = new OptionSetValue(Convert.ToInt32(patientSpecialTest.UrgencyId)); mzk_patientordermzk_Urgency orderUrgency = (mzk_patientordermzk_Urgency)Convert.ToInt32(patientSpecialTest.UrgencyId); if (orderUrgency == mzk_patientordermzk_Urgency.Routine) { urgency = HMUrgency.Routine; } else if (orderUrgency == mzk_patientordermzk_Urgency.Stat) { urgency = HMUrgency.Stat; } } if (!string.IsNullOrEmpty(patientSpecialTest.treatmentLocationId)) { patientOrderEntity.Attributes["mzk_treatmentlocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientSpecialTest.treatmentLocationId)); } if (patientSpecialTest.OrderingPhysician != string.Empty && patientSpecialTest.OrderingPhysician != null) { patientOrderEntity.Attributes["ownerid"] = new EntityReference("systemuser", new Guid(patientSpecialTest.OrderingPhysician)); } if (patientSpecialTest.EncounterId != string.Empty && patientSpecialTest.EncounterId != null) { patientOrderEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(patientSpecialTest.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientSpecialTest.EncounterId; encounter = encounter.encounterDetails(encounter).Result.ToList().First <PatientEncounter>(); PatientId = encounter.PatientId; caseType = encounter.caseTypeValue; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); } //if (!string.IsNullOrEmpty(patientSpecialTest.OrderDate)) // patientOrderEntity.Attributes["mzk_orderdate"] =Convert.ToDateTime( patientSpecialTest.OrderDate); if (patientSpecialTest.OrderDate != DateTime.MinValue) { patientOrderEntity.Attributes["mzk_orderdate"] = patientSpecialTest.OrderDate; } else { patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; } patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; if (patientSpecialTest.ClinicalNotes != string.Empty && patientSpecialTest.ClinicalNotes != null) { patientOrderEntity.Attributes["mzk_clinicalnotes"] = patientSpecialTest.ClinicalNotes; } patientOrderEntity.Attributes["mzk_type"] = new OptionSetValue(6); StatusManager statusManager = StatusManager.getRootStatus(mzk_entitytype.SpecialTestOrder, caseType, isActivityOrder); if (statusManager != null) { patientOrderEntity.mzk_OrderStatus = new OptionSetValue(statusManager.status); patientOrderEntity.mzk_StatusManagerDetail = new EntityReference(mzk_statusmanagerdetails.EntityLogicalName, new Guid(statusManager.StatusId)); } if (patientSpecialTest.clinicRecId > 0) { patientOrderEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(patientSpecialTest.clinicRecId); } if (!string.IsNullOrEmpty(patientSpecialTest.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientSpecialTest.orderingLocationId)); } bool isDuplicateAllowed = false; if (!string.IsNullOrEmpty(patientSpecialTest.EncounterId) && !string.IsNullOrEmpty(patientSpecialTest.TestName)) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientSpecialTest.EncounterId, patientSpecialTest.TestName); } if (isDuplicateAllowed == true) { Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); } else { throw new ValidationException("Same Special Test cannot be added multiple times."); } if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientSpecialTest.EncounterId)) { if (patientOrderEntity.Attributes.Contains("mzk_treatmentlocation")) { Clinic clinic = new Clinic().getClinicDetails(patientOrderEntity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Id.ToString()); await this.createCaseTrans(patientSpecialTest.EncounterId, OrderNumber, patientSpecialTest.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", urgency, "", "", "", 0, clinic.mzk_axclinicrefrecid); } else { await this.createCaseTrans(patientSpecialTest.EncounterId, OrderNumber, patientSpecialTest.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", urgency, "", "", "", 0, 0); } } } } catch (Exception ex) { if (!string.IsNullOrEmpty(Id)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id)); } throw ex; } return(Id); }
public async Task <string> addPatientOrder(PatientProcedure patientProcedure, bool isActivityOrder = false) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); mzk_patientorder patientOrderEntity = new mzk_patientorder(); try { if (!string.IsNullOrEmpty(patientProcedure.Notes)) { patientOrderEntity.mzk_Comments = patientProcedure.Notes; } if (!string.IsNullOrEmpty(patientProcedure.CareProvider)) { patientOrderEntity.mzk_UserId = new EntityReference(xrm.SystemUser.EntityLogicalName, new Guid(patientProcedure.CareProvider)); } mzk_casetype caseType = mzk_casetype.OutPatient; patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientProcedure.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientProcedure.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientProcedure.appointmentId)); if (!string.IsNullOrEmpty(patientProcedure.PatientId)) { patientOrderEntity.mzk_customer = new EntityReference("contact", new Guid(patientProcedure.PatientId)); } if (!string.IsNullOrEmpty(patientProcedure.CaseTransRecId)) { patientOrderEntity.mzk_AXCaseTransRefRecId = Convert.ToDecimal(patientProcedure.CaseTransRecId); } if (!string.IsNullOrEmpty(patientProcedure.ProcedureId)) { patientOrderEntity.mzk_ProductId = new EntityReference(xrm.Product.EntityLogicalName, Products.getProductId(patientProcedure.ProcedureId)); if (patientOrderEntity.mzk_ProductId == null && patientOrderEntity.mzk_ProductId.Id == Guid.Empty) { throw new ValidationException("Product not found for the corresponding item. Please contact system administrator"); } } patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; patientOrderEntity.mzk_FulfillmentDate = patientProcedure.FulfillmentDate; } else if (patientProcedure.EncounterId != null && patientProcedure.EncounterId != string.Empty) { if (!string.IsNullOrEmpty(patientProcedure.ProcedureId)) { patientOrderEntity.mzk_ProductId = new EntityReference(xrm.Product.EntityLogicalName, new Guid(patientProcedure.ProcedureId)); } patientOrderEntity.mzk_PatientEncounterId = new EntityReference(xrm.mzk_patientencounter.EntityLogicalName, new Guid(patientProcedure.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientProcedure.EncounterId; encounter = encounter.encounterDetails(encounter).Result.ToList().First <PatientEncounter>(); PatientId = encounter.PatientId; caseType = encounter.caseTypeValue; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); if (patientProcedure.OrderDate != DateTime.MinValue) { patientOrderEntity.mzk_OrderDate = patientProcedure.OrderDate; } else { patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; } patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; } if (!string.IsNullOrEmpty(patientProcedure.treatmentLocationId)) { patientOrderEntity.Attributes["mzk_treatmentlocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientProcedure.treatmentLocationId)); } patientOrderEntity.mzk_Type = new OptionSetValue((int)mzk_patientordermzk_Type.Procedure); StatusManager statusManager = StatusManager.getRootStatus(mzk_entitytype.ProcedureOrder, caseType, isActivityOrder); if (statusManager != null) { patientOrderEntity.mzk_OrderStatus = new OptionSetValue(statusManager.status); patientOrderEntity.mzk_StatusManagerDetail = new EntityReference(mzk_statusmanagerdetails.EntityLogicalName, new Guid(statusManager.StatusId)); } if (patientProcedure.clinicRecId > 0) { patientOrderEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(patientProcedure.clinicRecId); } if (!string.IsNullOrEmpty(patientProcedure.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientProcedure.orderingLocationId)); } bool isDuplicateAllowed = false; if (!string.IsNullOrEmpty(patientProcedure.EncounterId) && !string.IsNullOrEmpty(patientProcedure.ProcedureId)) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientProcedure.EncounterId, patientProcedure.ProcedureId); } else { isDuplicateAllowed = true; } if (isDuplicateAllowed == true) { Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientProcedure.EncounterId)) { if (patientOrderEntity.Attributes.Contains("mzk_treatmentlocation")) { Clinic clinic = new Clinic().getClinicDetails(patientOrderEntity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Id.ToString()); await this.createCaseTrans(patientProcedure.EncounterId, Id, patientProcedure.ProcedureId, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", AXRepository.AXServices.HMUrgency.None, "", "", "", 0, clinic.mzk_axclinicrefrecid); } else { await this.createCaseTrans(patientProcedure.EncounterId, Id, patientProcedure.ProcedureId, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", AXRepository.AXServices.HMUrgency.None, "", "", "", 0, 0); } } } } else { throw new ValidationException("Same procedure cannot be added multiple times."); } } catch (Exception ex) { if (!string.IsNullOrEmpty(Id)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id)); } throw ex; } return(Id.ToString()); }
public static StatusManager getRootStatus(mzk_entitytype entityType, mzk_casetype caseType, bool isActivityOrder = false) { try { StatusManager statusManagerObj = new StatusManager(); QueryExpression query = new QueryExpression(mzk_statusmanager.EntityLogicalName); query.Criteria.AddCondition("mzk_entitytype", ConditionOperator.Equal, (int)entityType); query.Criteria.AddCondition("mzk_casetype", ConditionOperator.Equal, (int)caseType); query.Criteria.AddCondition("mzk_effectivefrom", ConditionOperator.LessEqual, DateTime.Now.ToShortDateString()); query.Criteria.AddCondition("mzk_effectiveto", ConditionOperator.GreaterEqual, DateTime.Now.ToShortDateString()); LinkEntity entityTypeDetails = new LinkEntity(mzk_statusmanager.EntityLogicalName, mzk_statusmanagerdetails.EntityLogicalName, "mzk_statusmanagerid", "mzk_statusmanagerid", JoinOperator.Inner); entityTypeDetails.EntityAlias = "mzk_statusmanagerdetailsNextStatus"; if (isActivityOrder == true) { entityTypeDetails.LinkCriteria.AddCondition("mzk_startingstatusforactivityorder", ConditionOperator.Equal, true); } else { entityTypeDetails.LinkCriteria.AddCondition("mzk_startingstatusformanualorder", ConditionOperator.Equal, true); } entityTypeDetails.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); query.LinkEntities.Add(entityTypeDetails); SoapEntityRepository repo = SoapEntityRepository.GetService(); EntityCollection entitycol = repo.GetEntityCollection(query); StatusManager model = null; if (entitycol != null && entitycol.Entities != null && entitycol.Entities.Count > 0) { model = new StatusManager(); bool activityOrder = (bool)(((AliasedValue)entitycol.Entities[0]["mzk_statusmanagerdetailsNextStatus.mzk_startingstatusforactivityorder"]).Value); bool manualOrder = (bool)(((AliasedValue)entitycol.Entities[0]["mzk_statusmanagerdetailsNextStatus.mzk_startingstatusformanualorder"]).Value); if (entitycol.Entities[0].Attributes.Contains("mzk_statusmanagerdetailsNextStatus.mzk_orderstatus")) { model.status = (((AliasedValue)entitycol.Entities[0]["mzk_statusmanagerdetailsNextStatus.mzk_orderstatus"]).Value as OptionSetValue).Value; } if (entitycol.Entities[0].Attributes.Contains("mzk_statusmanagerdetailsNextStatus.mzk_statusmanagerdetailsid")) { model.StatusId = ((AliasedValue)entitycol.Entities[0]["mzk_statusmanagerdetailsNextStatus.mzk_statusmanagerdetailsid"]).Value.ToString(); } if (entitycol.Entities[0].Attributes.Contains("mzk_statusmanagerdetailsNextStatus.mzk_sendorm")) { model.sendOrm = (bool)(((AliasedValue)entitycol.Entities[0]["mzk_statusmanagerdetailsNextStatus.mzk_sendorm"]).Value); } } else { throw new ValidationException("Status manager not found. Please contact system administrator"); } return(model); } catch (Exception ex) { throw ex; } }
public List <StatusManager> getHierarchyByType(mzk_entitytype _entityType, mzk_casetype _caseType) { try { SoapEntityRepository repo = SoapEntityRepository.GetService(); QueryExpression query = new QueryExpression(mzk_statusmanager.EntityLogicalName); query.Criteria.AddCondition("mzk_entitytype", ConditionOperator.Equal, (int)_entityType); query.Criteria.AddCondition("mzk_casetype", ConditionOperator.Equal, (int)_caseType); query.Criteria.AddCondition("mzk_effectivefrom", ConditionOperator.LessEqual, DateTime.Now.ToShortDateString()); query.Criteria.AddCondition("mzk_effectiveto", ConditionOperator.GreaterEqual, DateTime.Now.ToShortDateString()); LinkEntity entityTypeDetails = new LinkEntity(mzk_statusmanager.EntityLogicalName, mzk_statusmanagerdetails.EntityLogicalName, "mzk_statusmanagerid", "mzk_statusmanagerid", JoinOperator.Inner); entityTypeDetails.EntityAlias = "mzk_statusmanagerdetails"; entityTypeDetails.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); query.LinkEntities.Add(entityTypeDetails); LinkEntity entityTypeAction = new LinkEntity(mzk_statusmanagerdetails.EntityLogicalName, mzk_actionmanager.EntityLogicalName, "mzk_actionmanagerid", "mzk_actionmanagerid", JoinOperator.Inner); entityTypeAction.EntityAlias = "mzk_actionmanager"; entityTypeAction.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); entityTypeDetails.LinkEntities.Add(entityTypeAction); LinkEntity entityTypeRevert = new LinkEntity(mzk_statusmanagerdetails.EntityLogicalName, mzk_statusmanagerdetails.EntityLogicalName, "mzk_revertstatus", "mzk_statusmanagerdetailsid", JoinOperator.LeftOuter); entityTypeRevert.EntityAlias = "mzk_statusmanagerdetailsRevertStatus"; entityTypeRevert.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_orderstatus"); entityTypeDetails.LinkEntities.Add(entityTypeRevert); EntityCollection entitycol = repo.GetEntityCollection(query); StatusManager model; List <StatusManager> listModelType = new List <StatusManager>(); foreach (Entity entity in entitycol.Entities) { model = new StatusManager(); if (entity.Attributes.Contains("mzk_actionmanager.mzk_actionname")) { model.name = ((AliasedValue)entity["mzk_actionmanager.mzk_actionname"]).Value.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_allowedit")) { model.allowEdit = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_allowedit"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_fulfillmentaction")) { model.fulfillmentAction = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_fulfillmentaction"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showendtime")) { model.showEndTime = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_showendtime"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showstarttime")) { model.showStartTime = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_showstarttime"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_undo")) { model.Undo = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_undo"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showtimer")) { model.showTimer = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_showtimer"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_orderstatus")) { model.status = (((AliasedValue)(entity["mzk_statusmanagerdetails.mzk_orderstatus"])).Value as OptionSetValue).Value; } // if (entity.Attributes.Contains("mzk_statusmanagerdetailsParentStatus.mzk_orderstatus")) // { //model.parentStatus = (((AliasedValue)entity["mzk_statusmanagerdetailsParentStatus.mzk_orderstatus"]).Value as OptionSetValue).Value; //} if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_statusmanagerdetailsid")) { model.StatusId = ((AliasedValue)entity["mzk_statusmanagerdetails.mzk_statusmanagerdetailsid"]).Value.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_parentstatusid")) { model.ParentStatusId = ((EntityReference)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_parentstatusid"]).Value).Id.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_revertstatus")) { model.RevertStatusId = ((EntityReference)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_revertstatus"]).Value).Id.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetailsRevertStatus.mzk_orderstatus")) { model.revertStatus = (((AliasedValue)entity["mzk_statusmanagerdetailsRevertStatus.mzk_orderstatus"]).Value as OptionSetValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showflip")) { model.isFlip = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_showflip"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_sendorm")) { model.sendOrm = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_sendorm"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_createcharge")) { model.createCharge = (bool)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_createcharge"]).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_fliptype")) { model.FlipType = (((AliasedValue)(entity["mzk_statusmanagerdetails.mzk_fliptype"])).Value as OptionSetValue).Value; } listModelType.Add(model); } return(listModelType); } 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 <string> addPatientOrder(PatientRadiologyOrder patientRadiologyOrder, bool isActivityOrder = false) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); mzk_patientorder patientOrderEntity = new mzk_patientorder(); try { mzk_casetype caseType = mzk_casetype.OutPatient; patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientRadiologyOrder.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientRadiologyOrder.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientRadiologyOrder.appointmentId)); if (!string.IsNullOrEmpty(patientRadiologyOrder.PatientId)) { patientOrderEntity.mzk_customer = new EntityReference("contact", new Guid(patientRadiologyOrder.PatientId)); } if (!string.IsNullOrEmpty(patientRadiologyOrder.CaseTransRecId)) { patientOrderEntity.mzk_AXCaseTransRefRecId = Convert.ToDecimal(patientRadiologyOrder.CaseTransRecId); } if (!string.IsNullOrEmpty(patientRadiologyOrder.CaseId)) { patientOrderEntity.mzk_caseid = new EntityReference("incident", new Guid(patientRadiologyOrder.CaseId)); } if (!string.IsNullOrEmpty(patientRadiologyOrder.TestName)) { patientOrderEntity.mzk_ProductId = new EntityReference(xrm.Product.EntityLogicalName, Products.getProductId(patientRadiologyOrder.TestName)); if (patientOrderEntity.mzk_ProductId == null && patientOrderEntity.mzk_ProductId.Id == Guid.Empty) { throw new ValidationException("Product not found for the corresponding item. Please contact system administrator"); } } patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; patientOrderEntity.mzk_FulfillmentDate = patientRadiologyOrder.FulfillmentDate; if (patientRadiologyOrder.clinicRecId > 0) { patientOrderEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(patientRadiologyOrder.clinicRecId); } if (!string.IsNullOrEmpty(patientRadiologyOrder.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientRadiologyOrder.orderingLocationId)); } if (!string.IsNullOrEmpty(patientRadiologyOrder.treatmentLocationId)) { patientOrderEntity.Attributes["mzk_treatmentlocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientRadiologyOrder.treatmentLocationId)); } } else if (patientRadiologyOrder.EncounterId != null && patientRadiologyOrder.EncounterId != string.Empty) { if (patientRadiologyOrder.TestName != null && patientRadiologyOrder.TestName != string.Empty) { patientOrderEntity.Attributes["mzk_productid"] = new EntityReference("product", new Guid(patientRadiologyOrder.TestName)); } if (patientRadiologyOrder.Frequency != null && patientRadiologyOrder.Frequency != string.Empty) { patientOrderEntity.Attributes["mzk_frequencyid"] = new EntityReference("mzk_ordersetup", new Guid(patientRadiologyOrder.Frequency)); } if (patientRadiologyOrder.AssociatedDiagnosis != null && patientRadiologyOrder.AssociatedDiagnosis != string.Empty) { patientOrderEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(patientRadiologyOrder.AssociatedDiagnosis)); } if (patientRadiologyOrder.ClinicalNotes != null && patientRadiologyOrder.ClinicalNotes != string.Empty) { patientOrderEntity.Attributes["mzk_clinicalnotes"] = patientRadiologyOrder.ClinicalNotes; } if (patientRadiologyOrder.StudyDate != null && patientRadiologyOrder.StudyDate != string.Empty) { patientOrderEntity.Attributes["mzk_studydate"] = new OptionSetValue(Convert.ToInt32(patientRadiologyOrder.StudyDate)); } if (patientRadiologyOrder.clinicRecId > 0) { patientOrderEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(patientRadiologyOrder.clinicRecId); } if (!string.IsNullOrEmpty(patientRadiologyOrder.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientRadiologyOrder.orderingLocationId)); } if (!string.IsNullOrEmpty(patientRadiologyOrder.treatmentLocationId)) { patientOrderEntity.Attributes["mzk_treatmentlocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientRadiologyOrder.treatmentLocationId)); } if (patientRadiologyOrder.OrderDate != DateTime.MinValue) { patientOrderEntity.Attributes["mzk_orderdate"] = patientRadiologyOrder.OrderDate; } else { patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; } patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; } //for Radiology patientOrderEntity.Attributes["mzk_type"] = new OptionSetValue(3); if (patientRadiologyOrder.EncounterId != null && patientRadiologyOrder.EncounterId != string.Empty) { patientOrderEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(patientRadiologyOrder.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientRadiologyOrder.EncounterId; List <PatientEncounter> listEncounter = encounter.encounterDetails(encounter).Result; if (!string.IsNullOrEmpty(CaseId)) { Speciality specialty = new Speciality(); patientOrderEntity.Attributes["mzk_specialtyname"] = specialty.getSpeciality(CaseId); } encounter = encounter.encounterDetails(encounter).Result.ToList().First <PatientEncounter>(); PatientId = encounter.PatientId; caseType = encounter.caseTypeValue; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); } StatusManager statusManager = StatusManager.getRootStatus(mzk_entitytype.RadiologyOrder, caseType, isActivityOrder); if (statusManager != null) { patientOrderEntity.mzk_OrderStatus = new OptionSetValue(statusManager.status); patientOrderEntity.mzk_StatusManagerDetail = new EntityReference(mzk_statusmanagerdetails.EntityLogicalName, new Guid(statusManager.StatusId)); } bool isDuplicateAllowed = false; if (!string.IsNullOrEmpty(patientRadiologyOrder.EncounterId) && !string.IsNullOrEmpty(patientRadiologyOrder.TestName)) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientRadiologyOrder.EncounterId, patientRadiologyOrder.TestName); } else { isDuplicateAllowed = true; } if (isDuplicateAllowed == true) { Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientRadiologyOrder.EncounterId)) { if (patientOrderEntity.Attributes.Contains("mzk_treatmentlocation")) { Clinic clinic = new Clinic().getClinicDetails(patientOrderEntity.GetAttributeValue <EntityReference>("mzk_treatmentlocation").Id.ToString()); await this.createCaseTrans(patientRadiologyOrder.EncounterId, Id, patientRadiologyOrder.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", AXRepository.AXServices.HMUrgency.None, "", "", "", 0, clinic.mzk_axclinicrefrecid); } else { await this.createCaseTrans(patientRadiologyOrder.EncounterId, Id, patientRadiologyOrder.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value, 1, "", AXRepository.AXServices.HMUrgency.None, "", "", "", 0, 0); } } } } else { throw new ValidationException("Same Radiology Test cannot be added multiple times."); } if (!string.IsNullOrEmpty(Id) && !string.IsNullOrEmpty(patientRadiologyOrder.appointmentId) && AppSettings.GetByKey("RISIntegration").ToLower() == true.ToString().ToLower()) { RIS ris = new RIS(); Patient patient = new Patient(); if (patientRadiologyOrder.registered) { await patient.updatePatientRIS(patientRadiologyOrder.PatientId); } else { await patient.createPatientRIS(patientRadiologyOrder.appointmentId, patientRadiologyOrder.PatientId); } } //await this.addContrastOrder(patientRadiologyOrder, Id); } catch (Exception ex) { if (!string.IsNullOrEmpty(Id)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id)); } throw ex; } return(Id.ToString()); }
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(PatientLabOrder patientLabOrder, bool isActivityOrder = false) { if (patientLabOrder.specimensourcelist != null && patientLabOrder.specimensourcelist.Count > 0) { for (int specimentCount = 0; specimentCount < patientLabOrder.specimensourcelist.Count; specimentCount++) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); xrm.mzk_patientorder patientOrderEntity = new xrm.mzk_patientorder(); try { mzk_casetype caseType = mzk_casetype.OutPatient; patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientLabOrder.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.appointmentId)); } if (!string.IsNullOrEmpty(patientLabOrder.TestName)) { patientOrderEntity.Attributes["mzk_productid"] = new EntityReference("product", new Guid(patientLabOrder.TestName)); } else { throw new ValidationException("Test Name must be selected"); } if (!string.IsNullOrEmpty(patientLabOrder.Frequency)) { patientOrderEntity.Attributes["mzk_frequencyid"] = new EntityReference("mzk_ordersetup", new Guid(patientLabOrder.Frequency)); } if (!string.IsNullOrEmpty(patientLabOrder.AssociatedDiagnosis)) { patientOrderEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(patientLabOrder.AssociatedDiagnosis)); } if (!string.IsNullOrEmpty(patientLabOrder.ClinicalNotes)) { patientOrderEntity.Attributes["mzk_clinicalnotes"] = patientLabOrder.ClinicalNotes; } if (!string.IsNullOrEmpty(patientLabOrder.AntibioticsComments)) { patientOrderEntity.Attributes["mzk_antibioticscomments"] = patientLabOrder.AntibioticsComments; } if (!string.IsNullOrEmpty(patientLabOrder.EncounterId)) { patientOrderEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(patientLabOrder.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientLabOrder.EncounterId; encounter = encounter.encounterDetails(encounter).Result.ToList().First <PatientEncounter>(); PatientId = encounter.PatientId; CaseId = encounter.CaseId.ToString(); caseType = encounter.caseTypeValue; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); } if (patientLabOrder.OrderDate != DateTime.MinValue) { patientOrderEntity.Attributes["mzk_orderdate"] = patientLabOrder.OrderDate; } else { patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; } patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; if (patientLabOrder.UrgencyId != string.Empty && patientLabOrder.UrgencyId != null) { patientOrderEntity.Attributes["mzk_urgency"] = new OptionSetValue(Convert.ToInt32(patientLabOrder.UrgencyId)); } if (!string.IsNullOrEmpty(patientLabOrder.Antibiotics) && patientLabOrder.Antibiotics == "1") { patientOrderEntity.Attributes["mzk_antibiotics"] = true; } else { patientOrderEntity.Attributes["mzk_antibiotics"] = false; } if (!string.IsNullOrEmpty(patientLabOrder.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientLabOrder.orderingLocationId)); patientOrderEntity.Attributes["mzk_specialityname"] = new Clinic().getClinicDetails(patientLabOrder.orderingLocationId).speciality; } if (!string.IsNullOrEmpty(patientLabOrder.ParentOrderId)) { patientOrderEntity.Attributes["mzk_parentorder"] = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.ParentOrderId)); } if (!string.IsNullOrEmpty(patientLabOrder.Instructionstopatients)) { patientOrderEntity.Attributes["mzk_instructionstopatients"] = patientLabOrder.Instructionstopatients; } patientOrderEntity.Attributes["mzk_type"] = new OptionSetValue(2); StatusManager statusManager = StatusManager.getRootStatus(mzk_entitytype.LabOrder, caseType, isActivityOrder); if (statusManager != null) { patientOrderEntity.mzk_OrderStatus = new OptionSetValue(statusManager.status); patientOrderEntity.mzk_StatusManagerDetail = new EntityReference(mzk_statusmanagerdetails.EntityLogicalName, new Guid(statusManager.StatusId)); } if (patientLabOrder.specimensourcelist[specimentCount] != null) { patientOrderEntity.Attributes["mzk_specimensource"] = new EntityReference("mzk_ordersetup", new Guid(patientLabOrder.specimensourcelist[specimentCount])); } bool isDuplicateAllowed = false; Products listProduct = new Products().getProductDetails(patientLabOrder.TestName); if (listProduct != null) { if (listProduct.IsSpecimenSource == false) { if (!string.IsNullOrEmpty(patientLabOrder.EncounterId) && !string.IsNullOrEmpty(patientLabOrder.TestName)) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientLabOrder.EncounterId, patientLabOrder.TestName); } } else { if (!string.IsNullOrEmpty(patientLabOrder.EncounterId) && !string.IsNullOrEmpty(patientLabOrder.TestName) && !string.IsNullOrEmpty(patientLabOrder.specimensourcelist[specimentCount])) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientLabOrder.EncounterId, patientLabOrder.TestName, patientLabOrder.specimensourcelist[specimentCount]); } } if (isDuplicateAllowed == true) { Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); } else { throw new ValidationException("Same Lab Test cannot be added multiple times."); } } if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientLabOrder.EncounterId)) { await this.createCaseTrans(patientLabOrder.EncounterId, Id, patientLabOrder.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value); } } if (AppSettings.GetByKey("LISIntegration").ToLower() == true.ToString().ToLower() && statusManager.sendOrm) { this.sendORMLISMessage(PatientId, 0, patientLabOrder.EncounterId, Id, CaseId, statusManager.status.ToString()); } } catch (Exception ex) { if (!string.IsNullOrEmpty(Id)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id)); } throw ex; } } } else { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); xrm.mzk_patientorder patientOrderEntity = new xrm.mzk_patientorder(); try { mzk_casetype caseType = mzk_casetype.OutPatient; patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientLabOrder.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.appointmentId)); } if (!string.IsNullOrEmpty(patientLabOrder.TestName)) { patientOrderEntity.Attributes["mzk_productid"] = new EntityReference("product", new Guid(patientLabOrder.TestName)); } else { throw new ValidationException("Test Name must be selected"); } if (!string.IsNullOrEmpty(patientLabOrder.Frequency)) { patientOrderEntity.Attributes["mzk_frequencyid"] = new EntityReference("mzk_ordersetup", new Guid(patientLabOrder.Frequency)); } if (!string.IsNullOrEmpty(patientLabOrder.AssociatedDiagnosis)) { patientOrderEntity.Attributes["mzk_associateddiagnosisid"] = new EntityReference("mzk_concept", new Guid(patientLabOrder.AssociatedDiagnosis)); } if (!string.IsNullOrEmpty(patientLabOrder.ClinicalNotes)) { patientOrderEntity.Attributes["mzk_clinicalnotes"] = patientLabOrder.ClinicalNotes; } if (!string.IsNullOrEmpty(patientLabOrder.AntibioticsComments)) { patientOrderEntity.Attributes["mzk_antibioticscomments"] = patientLabOrder.AntibioticsComments; } if (!string.IsNullOrEmpty(patientLabOrder.EncounterId)) { patientOrderEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(patientLabOrder.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientLabOrder.EncounterId; encounter = encounter.encounterDetails(encounter).Result.ToList().First <PatientEncounter>(); PatientId = encounter.PatientId; CaseId = encounter.CaseId.ToString(); caseType = encounter.caseTypeValue; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); } if (patientLabOrder.OrderDate != DateTime.MinValue) { patientOrderEntity.Attributes["mzk_orderdate"] = patientLabOrder.OrderDate; } else { patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; } patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; if (patientLabOrder.UrgencyId != string.Empty && patientLabOrder.UrgencyId != null) { patientOrderEntity.Attributes["mzk_urgency"] = new OptionSetValue(Convert.ToInt32(patientLabOrder.UrgencyId)); } if (!string.IsNullOrEmpty(patientLabOrder.Antibiotics) && patientLabOrder.Antibiotics == "1") { patientOrderEntity.Attributes["mzk_antibiotics"] = true; } else { patientOrderEntity.Attributes["mzk_antibiotics"] = false; } if (!string.IsNullOrEmpty(patientLabOrder.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientLabOrder.orderingLocationId)); patientOrderEntity.Attributes["mzk_specialityname"] = new Clinic().getClinicDetails(patientLabOrder.orderingLocationId).speciality; } if (!string.IsNullOrEmpty(patientLabOrder.ParentOrderId)) { patientOrderEntity.Attributes["mzk_parentorder"] = new EntityReference("mzk_patientorder", new Guid(patientLabOrder.ParentOrderId)); } if (!string.IsNullOrEmpty(patientLabOrder.Instructionstopatients)) { patientOrderEntity.Attributes["mzk_instructionstopatients"] = patientLabOrder.Instructionstopatients; } patientOrderEntity.Attributes["mzk_type"] = new OptionSetValue(2); StatusManager statusManager = StatusManager.getRootStatus(mzk_entitytype.LabOrder, caseType, isActivityOrder); if (statusManager != null) { patientOrderEntity.mzk_OrderStatus = new OptionSetValue(statusManager.status); patientOrderEntity.mzk_StatusManagerDetail = new EntityReference(mzk_statusmanagerdetails.EntityLogicalName, new Guid(statusManager.StatusId)); } bool isDuplicateAllowed = false; if (!string.IsNullOrEmpty(patientLabOrder.EncounterId) && !string.IsNullOrEmpty(patientLabOrder.TestName)) { isDuplicateAllowed = new PatientEncounter().DuplicateDetection(patientLabOrder.EncounterId, patientLabOrder.TestName); } if (isDuplicateAllowed == true) { Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); } else { throw new ValidationException("Same Lab Test cannot be added multiple times."); } if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientLabOrder.EncounterId)) { await this.createCaseTrans(patientLabOrder.EncounterId, Id, patientLabOrder.TestName, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value); } } if (AppSettings.GetByKey("LISIntegration").ToLower() == true.ToString().ToLower() && statusManager.sendOrm) { this.sendORMLISMessage(PatientId, 0, patientLabOrder.EncounterId, Id, CaseId, statusManager.status.ToString()); } } catch (Exception ex) { if (!string.IsNullOrEmpty(Id)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(Id)); } throw ex; } } return(Id.ToString()); }
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; } }