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 bool getHierarchy() { try { SoapEntityRepository repo = SoapEntityRepository.GetService(); EntityCollection entitycol = repo.GetEntityCollection(this.getActionsQuery()); StatusManager model; 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_allowedit")) { model.allowEdit = (bool)(entity["mzk_allowedit"]); } if (entity.Attributes.Contains("mzk_fulfillmentaction")) { model.fulfillmentAction = (bool)(entity["mzk_fulfillmentaction"]); } if (entity.Attributes.Contains("mzk_showendtime")) { model.showEndTime = (bool)(entity["mzk_showendtime"]); } if (entity.Attributes.Contains("mzk_showstarttime")) { model.showStartTime = (bool)(entity["mzk_showstarttime"]); } if (entity.Attributes.Contains("mzk_undo")) { model.Undo = (bool)(entity["mzk_undo"]); } if (entity.Attributes.Contains("mzk_showtimer")) { model.showTimer = (bool)(entity["mzk_showtimer"]); } if (entity.Attributes.Contains("mzk_orderstatus")) { model.status = ((entity["mzk_orderstatus"]) 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_statusmanagerdetailsid")) { model.StatusId = (entity["mzk_statusmanagerdetailsid"]).ToString(); } if (entity.Attributes.Contains("mzk_parentstatusid")) { model.ParentStatusId = ((EntityReference)entity["mzk_parentstatusid"]).Id.ToString(); } if (entity.Attributes.Contains("mzk_revertstatus")) { model.RevertStatusId = ((EntityReference)entity["mzk_revertstatus"]).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_showflip")) { model.isFlip = (bool)(entity["mzk_showflip"]); } if (entity.Attributes.Contains("mzk_sendorm")) { model.sendOrm = (bool)(entity["mzk_sendorm"]); } if (entity.Attributes.Contains("mzk_createcharge")) { model.createCharge = (bool)(entity["mzk_createcharge"]); } if (entity.Attributes.Contains("mzk_fliptype")) { model.FlipType = ((entity["mzk_fliptype"]) as OptionSetValue).Value; } listModel.Add(model); } return(true); } 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 <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 <StatusManagerHeader> getStatusManagerDetails(string statusManagerId) { try { QueryExpression query = new QueryExpression(mzk_statusmanager.EntityLogicalName); query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition("mzk_statusmanagerid", ConditionOperator.Equal, new Guid(statusManagerId)); 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); 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); query.LinkEntities.Add(entityTypeDetails); SoapEntityRepository repo = SoapEntityRepository.GetService(); EntityCollection entitycol = repo.GetEntityCollection(query); StatusManagerHeader model = new StatusManagerHeader(); StatusManager modelDetails = null; List <StatusManager> list = new List <StatusManager>(); bool isFirst = true; foreach (Entity entity in entitycol.Entities) { if (isFirst) { isFirst = false; mzk_statusmanager statusManager = (mzk_statusmanager)entity; model = this.fillStatusManagerHeader(statusManager); } modelDetails = new StatusManager(); if (entity.Attributes.Contains("mzk_actionmanager.mzk_actionname")) { modelDetails.name = ((AliasedValue)entity["mzk_actionmanager.mzk_actionname"]).Value.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_actionmanagerid")) { modelDetails.ActionManagerId = ((EntityReference)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_actionmanagerid"]).Value).Id.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_allowedit")) { modelDetails.allowEdit = (bool)(entity["mzk_statusmanagerdetails.mzk_allowedit"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_fulfillmentaction")) { modelDetails.fulfillmentAction = (bool)(entity["mzk_statusmanagerdetails.mzk_fulfillmentaction"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showendtime")) { modelDetails.showEndTime = (bool)(entity["mzk_statusmanagerdetails.mzk_showendtime"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showstarttime")) { modelDetails.showStartTime = (bool)(entity["mzk_statusmanagerdetails.mzk_showstarttime"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_undo")) { modelDetails.Undo = (bool)(entity["mzk_statusmanagerdetails.mzk_undo"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showtimer")) { modelDetails.showTimer = (bool)(entity["mzk_statusmanagerdetails.mzk_showtimer"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_orderstatus")) { modelDetails.status = (((entity["mzk_statusmanagerdetails.mzk_orderstatus"] as AliasedValue).Value) as OptionSetValue).Value; modelDetails.statusText = entity.FormattedValues["mzk_statusmanagerdetails.mzk_orderstatus"].ToString(); } // 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")) { modelDetails.StatusId = (entity["mzk_statusmanagerdetails.mzk_statusmanagerdetailsid"] as AliasedValue).Value.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_parentstatusid")) { modelDetails.ParentStatusId = ((EntityReference)((AliasedValue)entity["mzk_statusmanagerdetails.mzk_parentstatusid"]).Value).Id.ToString(); } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_showflip")) { modelDetails.isFlip = (bool)(entity["mzk_statusmanagerdetails.mzk_showflip"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_sendorm")) { modelDetails.sendOrm = (bool)(entity["mzk_statusmanagerdetails.mzk_sendorm"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_createcharge")) { modelDetails.createCharge = (bool)(entity["mzk_statusmanagerdetails.mzk_createcharge"] as AliasedValue).Value; } if (entity.Attributes.Contains("mzk_statusmanagerdetails.mzk_fliptype")) { modelDetails.FlipType = (((entity["mzk_statusmanagerdetails.mzk_fliptype"] as AliasedValue).Value) as OptionSetValue).Value; modelDetails.flipTypeText = entity.FormattedValues["mzk_statusmanagerdetails.mzk_fliptype"].ToString(); } list.Add(modelDetails); } model.details = list; return(model); } catch (Exception ex) { throw ex; } }
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()); }