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(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 <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 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()); }