public async Task <List <ConsultationSummary> > getCarePLan(string caseId) { try { List <ConsultationSummary> ConsultationSummary = new List <ConsultationSummary>(); ConsultationSummary model = new ConsultationSummary(); PatientMedication medication = new PatientMedication(); PatientRadiologyOrder radiology = new PatientRadiologyOrder(); PatientLabOrder lab = new PatientLabOrder(); PatientSpecialTest st = new PatientSpecialTest(); PatientTherapy pt = new PatientTherapy(); PatientReferralOrder pr = new PatientReferralOrder(); PatientProcedure pp = new PatientProcedure(); PatientEncounter encounter = new PatientEncounter(); encounter.CaseId = caseId; model.listPatientMedication = medication.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); model.listPatientRadiologyOrder = radiology.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); model.listPatientLabOrder = lab.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); model.listPatientSpecialTest = st.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, "", caseId).Result.ToList(); model.listPatientTherapy = pt.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); model.listPatientReferral = pr.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); model.listPatientProcedure = pp.getPatientOrder(null, null, null, null, DateTime.MinValue, DateTime.MinValue, false, null, caseId).Result.ToList(); ConsultationSummary.Add(model); return(ConsultationSummary); } catch (Exception ex) { throw ex; } }
public async Task <List <ConsultationSummary> > assessmentConsultationSummary(string caseId) { try { List <ConsultationSummary> ConsultationSummary = new List <ConsultationSummary>(); PatientEncounter enc = new PatientEncounter(); if (!string.IsNullOrEmpty(caseId)) { enc.CaseId = caseId; enc.EncounterType = Convert.ToString((int)mzk_encountertype.PrimaryAssessment); List <PatientEncounter> listPatEnc = enc.getEncounterDetails(enc).Result; if (listPatEnc.Count > 0) { patientEncounterId = listPatEnc.First <PatientEncounter>().EncounterId; } else { throw new ValidationException("Assessment summary is not available"); } } return(this.getConsultationSummary(patientEncounterId).Result); } catch (Exception ex) { throw ex; } }
public bool UpdatePatientEncounterData(int id, PatientEncounter patientInfo) { if (id > 0) { var patientDiagnosis = _context.PatientEncounter.Find(id); if (patientDiagnosis != null) { patientDiagnosis.VisitStartDate = patientInfo.VisitStartDate; patientDiagnosis.VisitEndDate = patientInfo.VisitEndDate; patientDiagnosis.ClinicianID = patientInfo.ClinicianID; patientDiagnosis.PatientID = patientInfo.PatientID; patientDiagnosis.CPTID = patientInfo.CPTID; patientDiagnosis.LocationID = patientInfo.LocationID; patientDiagnosis.Subjective = patientInfo.Subjective; patientDiagnosis.Objective = patientInfo.Objective; patientDiagnosis.Assessment = patientInfo.Assessment; patientDiagnosis.Plans = patientInfo.Plans; patientDiagnosis.IsActive = patientInfo.IsActive; patientDiagnosis.UpdatedDate = DateTime.Now; patientDiagnosis.UpdatedBy = patientInfo.UpdatedBy; _context.SaveChanges(); return(true); } } return(false); }
public async Task <PatientEncounter> AddPatientEncounter(int patientId, int encounterType, int patientMasterVisitId, DateTime encounterDate, int serviceAreaId, int userId) { try { PatientEncounter patientEncounter = new PatientEncounter() { PatientId = patientId, EncounterTypeId = encounterType, Status = 0, PatientMasterVisitId = patientMasterVisitId, EncounterStartTime = encounterDate, EncounterEndTime = encounterDate, ServiceAreaId = serviceAreaId, CreatedBy = userId, CreateDate = DateTime.Now }; await _unitOfWork.Repository <PatientEncounter>().AddAsync(patientEncounter); await _unitOfWork.SaveAsync(); return(patientEncounter); } catch (Exception e) { throw e; } }
public async Task <Result <AddEncounterVisitResponse> > Handle(AddEncounterVisitCommand request, CancellationToken cancellationToken) { using (var trans = _unitOfWork.Context.Database.BeginTransaction()) { try { PatientMasterVisit patientMasterVisit = new PatientMasterVisit() { PatientId = request.PatientId, ServiceId = request.ServiceAreaId, Start = request.EncounterDate, Active = true, CreateDate = DateTime.Now, DeleteFlag = false, VisitDate = request.EncounterDate, CreatedBy = request.UserId, VisitType = 0 }; await _unitOfWork.Repository <PatientMasterVisit>().AddAsync(patientMasterVisit); await _unitOfWork.SaveAsync(); PatientEncounter patientEncounter = new PatientEncounter() { PatientId = request.PatientId, EncounterTypeId = request.EncounterType, Status = 0, PatientMasterVisitId = patientMasterVisit.Id, EncounterStartTime = request.EncounterDate, EncounterEndTime = request.EncounterDate, ServiceAreaId = request.ServiceAreaId, CreatedBy = request.UserId, CreateDate = DateTime.Now }; await _unitOfWork.Repository <PatientEncounter>().AddAsync(patientEncounter); await _unitOfWork.SaveAsync(); trans.Commit(); //_unitOfWork.Dispose(); return(Result <AddEncounterVisitResponse> .Valid(new AddEncounterVisitResponse { PatientMasterVisitId = patientMasterVisit.Id, PatientEncounterId = patientEncounter.Id })); } catch (Exception ex) { trans.Rollback(); return(Result <AddEncounterVisitResponse> .Invalid(ex.Message)); } } }
public int AddpatientEncounter(PatientEncounter patientEncounter) { using (UnitOfWork unitOfWork = new UnitOfWork(new GreencardContext())) { unitOfWork.PatientEncounterRepository.Add(patientEncounter); Result = unitOfWork.Complete(); unitOfWork.Dispose(); return(Result); } }
public int AddPatientEncounter(PatientEncounter pmt) { try { return(_patientEncounterManager.AddpatientEncounter(pmt)); } catch (Exception e) { throw new Exception(e.Message); } }
public int UpdatePatientEncounter(PatientEncounter patientEncounter) { try { return(_patientEncounterManager.UpdatePatientEncounter(patientEncounter)); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <List <PatientVitals> > getLastRecordedVitals(string caseId, string appointmentId) { PatientEncounter patEnc = new PatientEncounter(); List <PatientVitals> patientVitals = new List <PatientVitals>(); if (!string.IsNullOrEmpty(appointmentId)) { patEnc = patEnc.encounterDetails((int)mzk_encountertype.Consultation, "", "", appointmentId).Result; if (patEnc != null && !string.IsNullOrEmpty(patEnc.EncounterId)) { patientVitals = new PatientVitals().getPatientEncounterVitals(null, patEnc.EncounterId, false, false).Result.ToList(); if (patientVitals.Count == 0) { patEnc = new PatientEncounter(); patEnc = patEnc.encounterDetails((int)mzk_encountertype.Triage, "", "", appointmentId).Result; if (patEnc != null && !string.IsNullOrEmpty(patEnc.EncounterId)) { patientVitals = new PatientVitals().getPatientEncounterVitals(null, patEnc.EncounterId, false, false).Result.ToList(); } } } } else if (!string.IsNullOrEmpty(caseId)) { patEnc.CaseId = caseId; patEnc.EncounterType = ((int)mzk_encountertype.PrimaryAssessment).ToString(); List <PatientEncounter> listEnc = null; listEnc = patEnc.getEncounterDetails(patEnc).Result; if (listEnc != null && listEnc.FirstOrDefault() != null && !string.IsNullOrEmpty(listEnc.First().EncounterId)) { patientVitals = new PatientVitals().getPatientEncounterVitals(null, listEnc.First().EncounterId, false, false).Result.ToList(); if (patientVitals.Count == 0) { patEnc = new PatientEncounter(); patEnc.CaseId = caseId; patEnc.EncounterType = ((int)mzk_encountertype.Triage).ToString(); listEnc = patEnc.getEncounterDetails(patEnc).Result; if (listEnc != null && listEnc.First() != null && !string.IsNullOrEmpty(listEnc.First().EncounterId)) { patientVitals = new PatientVitals().getPatientEncounterVitals(null, listEnc.First().EncounterId, false, false).Result.ToList(); } } } } return(patientVitals); }
public async Task <List <CheifComplaint> > getCheifComplaintFromClinicalTemplate(string caseId, string searchText, string appointmentId) { List <CheifComplaint> CheifComplaint = new List <CheifComplaint>(); ClinicalTemplate clinicalTemplate = new ClinicalTemplate(); string encounterId = ""; PatientEncounter patEnc = new PatientEncounter(); if (!string.IsNullOrEmpty(appointmentId)) { patEnc = patEnc.encounterDetails((int)mzk_encountertype.Consultation, "", "", appointmentId).Result; if (patEnc != null) { encounterId = patEnc.EncounterId; } } else if (!string.IsNullOrEmpty(caseId)) { patEnc.CaseId = caseId; patEnc.EncounterType = ((int)mzk_encountertype.PrimaryAssessment).ToString(); List <PatientEncounter> listEnc = null; listEnc = patEnc.getEncounterDetails(patEnc).Result; if (listEnc != null && listEnc.FirstOrDefault() != null) { encounterId = listEnc.First().EncounterId; } } List <ClinicalTemplateNarration> listNarration = clinicalTemplate.getPatientsClinicalTempalteNarration("", encounterId, "", false, 0, false, searchText); foreach (ClinicalTemplateNarration narration in listNarration) { CheifComplaint model = new CheifComplaint(); if (!string.IsNullOrEmpty(narration.comments)) { model.Complaint = narration.comments; } CheifComplaint.Add(model); } return(CheifComplaint); }
public override async Task <IActionResult> PatchAsync(int id, [FromBody] PatientEncounter patientEncounter) { //var attrToUpdate = _jsonApiContext.AttributesToUpdate; //var patientEncounterOld = _dbContextResolver.GetDbSet<PatientEncounter>().Where(m => m.Id == id).FirstOrDefault(); //CommonMethods commonMethods = new CommonMethods(); ////var patientEncounterInfo = await base.PatchAsync(id, patientEncounter); //int eventID = _dbContextResolver.GetDbSet<Event>().LastOrDefault().Id + 1; //List<AuditLogs> auditLogs = commonMethods.GetAuditLogValues(patientEncounterOld, patientEncounter, "PatientEncounter", attrToUpdate) // //.Where(i => attrToUpdate.Keys.Any(a1 => a1.InternalAttributeName == i.PropertyName)) // .Select(q => new AuditLogs() { NewValue = q.NewValue, OldValue = q.OldValue, PrimaryKeyID = q.PrimaryKeyID, TableName = q.TableName, PropertyName = q.PropertyName, EventID = eventID }).ToList(); //await _dbContextResolver.GetDbSet<AuditLogs>().AddRangeAsync(auditLogs); return(await base.PatchAsync(id, patientEncounter)); }
public async Task <List <ConsultationSummary> > triageConsultationSummary(string caseId, string cpsaWorkflowId) { try { List <ConsultationSummary> ConsultationSummary = new List <ConsultationSummary>(); PatientEncounter enc = new PatientEncounter(); if (!string.IsNullOrEmpty(cpsaWorkflowId)) { patientEncounterId = enc.getEncounterIdByWorkflowId(cpsaWorkflowId); if (string.IsNullOrEmpty(patientEncounterId)) { throw new ValidationException("Nursing triage summary is not available"); } } else if (!string.IsNullOrEmpty(caseId)) { enc.CaseId = caseId; enc.EncounterType = Convert.ToString((int)mzk_encountertype.Triage); List <PatientEncounter> listPatEnc = enc.getEncounterDetails(enc).Result; if (listPatEnc.Count > 0) { patientEncounterId = listPatEnc.First <PatientEncounter>().EncounterId; } else { throw new ValidationException("Nursing triage summary is not available"); } } if (!string.IsNullOrEmpty(patientEncounterId)) { return(this.getConsultationSummary(patientEncounterId).Result); } return(ConsultationSummary); } catch (Exception ex) { throw ex; } }
public int UpdatePatientEncounter(PatientEncounter patientEncounter) { using (UnitOfWork unitOfWork = new UnitOfWork(new GreencardContext())) { var encounter = unitOfWork.PatientEncounterRepository.GetById(patientEncounter.Id); if (null != encounter) { encounter.PatientId = patientEncounter.PatientId; encounter.PatientMasterVisitId = patientEncounter.PatientMasterVisitId; encounter.EncounterStartTime = patientEncounter.EncounterStartTime; encounter.EncounterEndTime = patientEncounter.EncounterEndTime; encounter.ServiceAreaId = patientEncounter.ServiceAreaId; } unitOfWork.PatientEncounterRepository.Update(patientEncounter); Result = unitOfWork.Complete(); unitOfWork.Dispose(); return(Result); } }
public int AddpatientEncounter(int patientId, int patientMasterVisitId, int encounterTypeId, int serviceId, int userId) { try { PatientEncounter patientVisitEncounter = new PatientEncounter() { PatientId = patientId, EncounterStartTime = DateTime.Now, EncounterEndTime = DateTime.Now, ServiceAreaId = serviceId, EncounterTypeId = encounterTypeId, PatientMasterVisitId = patientMasterVisitId, CreatedBy = userId }; return(_patientEncounterManager.AddpatientEncounter(patientVisitEncounter)); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Create an encounter /// </summary> private PatientEncounter CreateEncounter(Act act, Patient recordTarget) { var retVal = new PatientEncounter() { Participations = new List <ActParticipation>() { new ActParticipation(ActParticipationKey.RecordTarget, recordTarget.Key) }, ActTime = act.ActTime, StartTime = act.StartTime, StopTime = act.StopTime, MoodConceptKey = ActMoodKeys.Propose, Key = Guid.NewGuid() }; recordTarget.Participations.Add(new ActParticipation() { ParticipationRoleKey = ActParticipationKey.RecordTarget, Act = retVal }); return(retVal); }
public async Task <Result <GetPersonLastHtsEncounterResponse> > Handle(GetPersonLastHtsEncounterCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { var result = await _unitOfWork.Repository <HtsEncounter>().Get(x => x.PersonId == request.PersonId) .OrderByDescending(x => x.Id).FirstOrDefaultAsync(); var patientEncounter = new PatientEncounter(); int encounterId = 0; if (result != null) { patientEncounter = await _commonUnitOfWork.Repository <PatientEncounter>() .Get(x => x.Id == result.PatientEncounterID).FirstOrDefaultAsync(); encounterId = result.Id; } _unitOfWork.Dispose(); _commonUnitOfWork.Dispose(); var personLastHtsEncounter = new GetPersonLastHtsEncounterResponse() { EncounterId = encounterId, PatientMasterVisitId = patientEncounter.PatientMasterVisitId, PatientEncounterID = patientEncounter.Id }; return(Result <GetPersonLastHtsEncounterResponse> .Valid(personLastHtsEncounter)); } } catch (Exception e) { return(Result <GetPersonLastHtsEncounterResponse> .Invalid(e.Message)); } }
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> AddPatientDisposition(PatientDisposition patientDisposition) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); xrm.mzk_disposition patientDispositionEntity = new xrm.mzk_disposition(); if (patientDisposition.Asneeded == "1") { patientDispositionEntity.mzk_Asneeded = true; } if (patientDisposition.FollowUp != 0) { patientDispositionEntity.mzk_FollowUp = new OptionSetValue(patientDisposition.FollowUp); } if (!string.IsNullOrEmpty(patientDisposition.Comments)) { patientDispositionEntity.mzk_Comments = patientDisposition.Comments; } if (!string.IsNullOrEmpty(patientDisposition.DescriptionofSickNotes)) { patientDispositionEntity.mzk_DescriptionofSickNotes = patientDisposition.DescriptionofSickNotes; } if (!string.IsNullOrEmpty(patientDisposition.EncounterId)) { patientDispositionEntity.mzk_EncounterId = new EntityReference(xrm.mzk_patientencounter.EntityLogicalName, new Guid(patientDisposition.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientDisposition.EncounterId; patientDispositionEntity.mzk_customer = new EntityReference("contact", new Guid(encounter.getEncounterDetails(encounter).Result.ToList().First <PatientEncounter>().PatientId)); } if (patientDisposition.SickStartDate != DateTime.MinValue) { patientDispositionEntity.mzk_SickStartDate = patientDisposition.SickStartDate; } if (patientDisposition.SickEndDate != DateTime.MinValue) { patientDispositionEntity.mzk_SickEndDate = patientDisposition.SickEndDate; } if (!string.IsNullOrEmpty(patientDisposition.Notes)) { patientDispositionEntity.mzk_Notes = patientDisposition.Notes; } if (patientDisposition.OutComeValue != 0) { patientDispositionEntity.mzk_Outcome = new OptionSetValue(patientDisposition.OutComeValue); } if (patientDisposition.PartnerHospitalId != null && patientDisposition.PartnerHospitalId != string.Empty && patientDisposition.PartnerHospitalId != "0") { patientDispositionEntity.Attributes["mzk_partnerhospitalid"] = new EntityReference("mzk_hospital", new Guid(patientDisposition.PartnerHospitalId)); } Id = Convert.ToString(entityRepository.CreateEntity(patientDispositionEntity)); return(Id.ToString()); }
public async Task <bool> updatePatientDisposition(PatientDisposition patientDisposition) { try { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); QueryExpression query = new QueryExpression(mzk_disposition.EntityLogicalName); query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true); query.Criteria.AddCondition("mzk_encounterid", ConditionOperator.Equal, patientDisposition.EncounterId); EntityCollection entitycollection = entityRepository.GetEntityCollection(query); if (entitycollection.Entities.Count > 0) { Entity encounterEntity = entitycollection.Entities[0]; if (patientDisposition.Asneeded == "1") { encounterEntity.Attributes["mzk_asneeded"] = true; } else { encounterEntity.Attributes["mzk_asneeded"] = false; } mzk_dispositionmzk_FollowUp followUp = 0; if (patientDisposition.FollowUp != 0) { encounterEntity.Attributes["mzk_followup"] = new OptionSetValue(patientDisposition.FollowUp); followUp = (mzk_dispositionmzk_FollowUp)Convert.ToInt32(patientDisposition.FollowUp); } if (!string.IsNullOrEmpty(patientDisposition.Notes)) { encounterEntity.Attributes["mzk_notes"] = patientDisposition.Notes; } if (patientDisposition.FollowUpNumber != 0) { encounterEntity.Attributes["mzk_followupnumber"] = new OptionSetValue(patientDisposition.FollowUpNumber); } if (!string.IsNullOrEmpty(patientDisposition.Comments)) { encounterEntity.Attributes["mzk_comments"] = patientDisposition.Comments; } if (!string.IsNullOrEmpty(patientDisposition.DescriptionofSickNotes)) { encounterEntity.Attributes["mzk_descriptionofsicknotes"] = patientDisposition.DescriptionofSickNotes; } if (patientDisposition.SickStartDate != DateTime.MinValue) { encounterEntity.Attributes["mzk_sickstartdate"] = patientDisposition.SickStartDate; } else { encounterEntity.Attributes["mzk_sickstartdate"] = null; } if (patientDisposition.SickEndDate != DateTime.MinValue) { encounterEntity.Attributes["mzk_sickenddate"] = patientDisposition.SickEndDate; } else { encounterEntity.Attributes["mzk_sickenddate"] = null; } if (patientDisposition.OutComeValue != 0) { encounterEntity.Attributes["mzk_outcome"] = new OptionSetValue(patientDisposition.OutComeValue); } if (patientDisposition.PartnerHospitalId != null && patientDisposition.PartnerHospitalId != string.Empty && patientDisposition.PartnerHospitalId != "0") { encounterEntity.Attributes["mzk_partnerhospitalid"] = new EntityReference("mzk_hospital", new Guid(patientDisposition.PartnerHospitalId)); } entityRepository.UpdateEntity(encounterEntity); AppointmentRepository appRepo = new AppointmentRepository(); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientDisposition.EncounterId; long appointmentrecid = new PatientEncounter().getEncounterDetails(encounter).Result.ToList().First <PatientEncounter>().AppointmentRefRecId; if (appointmentrecid > 0) { appRepo.updateDispositionDetails(appointmentrecid, string.IsNullOrEmpty(patientDisposition.Comments) ? string.Empty : patientDisposition.Comments, patientDisposition.FollowUpNumber.ToString() + " " + followUp.ToString()); } } return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// Insert SBADM /// </summary> public PatientEncounter Insert(PatientEncounter data) { return(this.Insert <PatientEncounter>(data)); }
/// <summary> /// Save sbadm /// </summary> public PatientEncounter Save(PatientEncounter data) { return(this.Save <PatientEncounter>(data)); }
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 <bool> updateVisitReason(string encounterId, string visitReason) { try { PatientEncounter patEnc = new PatientEncounter(); patEnc.EncounterId = encounterId; patEnc = patEnc.getEncounterDetails(patEnc).Result.First(); string caseId = string.Empty; string appointmentId = string.Empty; if (patEnc != null) { if (!string.IsNullOrEmpty(patEnc.AppointmentId)) { appointmentId = patEnc.AppointmentId; } else if (!string.IsNullOrEmpty(patEnc.CaseId)) { caseId = patEnc.CaseId; } } SoapEntityRepository repo = SoapEntityRepository.GetService(); QueryExpression query = new QueryExpression(mzk_patientencounter.EntityLogicalName); query.ColumnSet = new ColumnSet(false); if (!string.IsNullOrEmpty(encounterId)) { query.Criteria.AddCondition("mzk_patientencounterid", ConditionOperator.Equal, new Guid(encounterId)); } LinkEntity workOrder = new LinkEntity(mzk_patientencounter.EntityLogicalName, msdyn_workorder.EntityLogicalName, "mzk_workorder", "msdyn_workorderid", JoinOperator.Inner); if (!string.IsNullOrEmpty(caseId)) { workOrder.LinkCriteria.AddCondition("msdyn_servicerequest", ConditionOperator.Equal, new Guid(caseId)); } if (!string.IsNullOrEmpty(appointmentId)) { workOrder.LinkCriteria.AddCondition("msdyn_workorderid", ConditionOperator.Equal, new Guid(appointmentId)); } workOrder.Columns = new ColumnSet("msdyn_workordersummary"); EntityCollection entityCollection = repo.GetEntityCollection(query); foreach (Entity entity in entityCollection.Entities) { if (!string.IsNullOrEmpty(visitReason)) { entity.Attributes["msdyn_workordersummary"] = visitReason; } repo.UpdateEntity(entity); } return(true); } catch (Exception ex) { throw ex; } }
public async Task <string> addPatientOrder(PatientTherapy patientTherapy) { SoapEntityRepository entityRepository = SoapEntityRepository.GetService(); mzk_patientorder patientOrderEntity = new mzk_patientorder(); try { patientOrderEntity.mzk_appointable = true; if (!string.IsNullOrEmpty(patientTherapy.appointmentId)) { patientOrderEntity.mzk_orderingappointment = new EntityReference("mzk_patientorder", new Guid(patientTherapy.appointmentId)); patientOrderEntity.mzk_fulfillmentappointment = new EntityReference("mzk_patientorder", new Guid(patientTherapy.appointmentId)); } if (!string.IsNullOrEmpty(patientTherapy.Therapy)) { patientOrderEntity.Attributes["mzk_productid"] = new EntityReference("product", new Guid(patientTherapy.Therapy)); } if (!string.IsNullOrEmpty(patientTherapy.Frequency)) { patientOrderEntity.Attributes["mzk_frequencyid"] = new EntityReference("mzk_ordersetup", new Guid(patientTherapy.Frequency)); } if (!string.IsNullOrEmpty(patientTherapy.Description)) { patientOrderEntity.Attributes["mzk_comments"] = patientTherapy.Description; } if (!string.IsNullOrEmpty(patientTherapy.EncounterId)) { patientOrderEntity.Attributes["mzk_patientencounterid"] = new EntityReference("mzk_patientencounter", new Guid(patientTherapy.EncounterId)); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientTherapy.EncounterId; PatientId = encounter.getEncounterDetails(encounter).Result.ToList().First <PatientEncounter>().PatientId; patientOrderEntity.Attributes["mzk_customer"] = new EntityReference("contact", new Guid(PatientId)); } patientOrderEntity.Attributes["mzk_orderdate"] = DateTime.Now.Date; patientOrderEntity.Attributes["mzk_fulfillmentdate"] = patientOrderEntity.Attributes["mzk_orderdate"]; if (patientTherapy.clinicRecId > 0) { patientOrderEntity.Attributes["mzk_axclinicrefrecid"] = Convert.ToDecimal(patientTherapy.clinicRecId); } if (!string.IsNullOrEmpty(patientTherapy.orderingLocationId)) { patientOrderEntity.Attributes["mzk_orderinglocation"] = new EntityReference("mzk_organizationalunit", new Guid(patientTherapy.orderingLocationId)); } patientOrderEntity.Attributes["mzk_type"] = new OptionSetValue(Convert.ToInt32(mzk_patientordermzk_Type.Thrapy)); patientOrderEntity.Attributes["mzk_orderstatus"] = new OptionSetValue((int)mzk_orderstatus.Ordered); Id = Convert.ToString(entityRepository.CreateEntity(patientOrderEntity)); if (AppSettings.GetByKey("OperationsIntegration").ToLower() == true.ToString().ToLower()) { if (!string.IsNullOrEmpty(patientTherapy.EncounterId)) { await this.createCaseTrans(patientTherapy.EncounterId, Id, patientTherapy.Therapy, (mzk_orderstatus)patientOrderEntity.mzk_OrderStatus.Value); } } return(Id.ToString()); } catch (Exception ex) { if (!string.IsNullOrEmpty(OrderNumber)) { entityRepository.DeleteEntity(mzk_patientorder.EntityLogicalName, new Guid(OrderNumber)); } throw ex; } }
public async Task <List <ConsultationSummary> > getConsultationSummary(string patientEncounterId, bool summaryUpdated = false, bool isStartEncounter = false) { try { var json = string.Empty; List <ConsultationSummary> ConsultationSummary = new List <ConsultationSummary>(); ConsultationSummary model = null; PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientEncounterId; List <PatientEncounter> listPatientEncounter = encounter.getEncounterDetails(encounter).Result; if (listPatientEncounter != null) { if (summaryUpdated == true) { model = await this.getConsultationSummaryModel(listPatientEncounter, isStartEncounter); if (model != null) { ConsultationSummary.Add(model); } } else { if (listPatientEncounter.Count > 0) { json = listPatientEncounter[0].SummaryJson; if (json != null) { string decompressjson = string.Empty; decompressjson = StringHelper.Decompress(json); model = JsonConvert.DeserializeObject <ConsultationSummary>(decompressjson); ConsultationSummary.Add(model); } else { model = await this.getConsultationSummaryModel(listPatientEncounter, isStartEncounter); if (model != null) { ConsultationSummary.Add(model); } } } else { model = await this.getConsultationSummaryModel(listPatientEncounter, isStartEncounter); if (model != null) { ConsultationSummary.Add(model); } } } } else { throw new ValidationException("Unable to find Patient Encounter"); } return(ConsultationSummary); } catch (Exception ex) { throw ex; } }
//public async Task<List<PatientVisit>> getVisitReason(long patientRecId, string encounterId) //{ // PatientVisitRepository repo = new PatientVisitRepository(); // List<PatientVisit> patientVisit = new List<PatientVisit>(); // PatientEncounter patEnc = new PatientEncounter(); // patEnc.EncounterId = encounterId; // patEnc = patEnc.encounterDetails(patEnc).Result.First(); // Guid caseGuid = Guid.Empty; // long appointmentrecId = 0; // if(patEnc != null) // { // if(patEnc.AppointmentRefRecId > 0) // { // appointmentrecId = patEnc.AppointmentRefRecId; // } // else if (!string.IsNullOrEmpty(patEnc.CaseId)) // { // caseGuid = new Guid(patEnc.CaseId); // } // } // HMPatientVisitContract[] contractList = null; // //TODO: CRM implementation: Visit Reason // if(contractList != null) // { // foreach (HMPatientVisitContract contract in contractList) // { // PatientVisit model = new PatientVisit(); // if (!string.IsNullOrEmpty(contract.parmVisitReason)) // { // model.VisitReason = contract.parmVisitReason; // } // patientVisit.Add(model); // } // } // return patientVisit; //} //public async Task<bool> updateVisitReason(string encounterId, string visitReason) //{ // try // { // PatientVisitRepository repo = new PatientVisitRepository(); // PatientEncounter patEnc = new PatientEncounter(); // patEnc.EncounterId = encounterId; // patEnc = patEnc.encounterDetails(patEnc).Result.First(); // Guid caseGuid = Guid.Empty; // long appointmentrecId = 0; // if (patEnc != null) // { // if (patEnc.AppointmentRefRecId > 0) // { // appointmentrecId = patEnc.AppointmentRefRecId; // } // else if (!string.IsNullOrEmpty(patEnc.CaseId)) // { // caseGuid = new Guid(patEnc.CaseId); // } // } // return repo.updateVisitReason(caseGuid, appointmentrecId, visitReason); // } // catch (Exception ex) // { // throw ex; // } //} public async Task <List <PatientVisit> > getVisitReason(string customerId, string encounterId, string caseId = "", string appointmentId = "") { try { PatientVisit patientVisit; Guid caseGuid = Guid.Empty; List <PatientVisit> visitReasonList = new List <PatientVisit>(); if (!string.IsNullOrEmpty(encounterId)) { PatientEncounter patEnc = new PatientEncounter(); patEnc.EncounterId = encounterId; patEnc = patEnc.getEncounterDetails(patEnc).Result.First(); if (patEnc != null) { if (!string.IsNullOrEmpty(patEnc.AppointmentId)) { appointmentId = patEnc.AppointmentId; } else if (!string.IsNullOrEmpty(patEnc.CaseId)) { caseId = patEnc.CaseId; } } } else { if (string.IsNullOrEmpty(appointmentId) && !string.IsNullOrEmpty(caseId)) { caseGuid = new Guid(caseId); } } SoapEntityRepository repo = SoapEntityRepository.GetService(); QueryExpression query = new QueryExpression(msdyn_workorder.EntityLogicalName); query.ColumnSet = new ColumnSet("msdyn_workordersummary"); if (!string.IsNullOrEmpty(customerId)) { query.Criteria.AddCondition("mzk_customer", ConditionOperator.Equal, new Guid(customerId)); } if (caseGuid != Guid.Empty) { query.Criteria.AddCondition("msdyn_servicerequest", ConditionOperator.Equal, caseGuid); } if (!string.IsNullOrEmpty(appointmentId)) { LinkEntity apptEntity = new LinkEntity(msdyn_workorder.EntityLogicalName, mzk_patientappointment.EntityLogicalName, "msdyn_workorderid", "mzk_workorderid", JoinOperator.Inner); apptEntity.LinkCriteria.AddCondition("mzk_patientappointmentid", ConditionOperator.Equal, new Guid(appointmentId)); query.LinkEntities.Add(apptEntity); } EntityCollection entityCollection = repo.GetEntityCollection(query); foreach (Entity entity in entityCollection.Entities) { patientVisit = new PatientVisit(); if (entity.Attributes.Contains("msdyn_workordersummary")) { patientVisit.VisitReason = entity.Attributes["msdyn_workordersummary"].ToString(); } visitReasonList.Add(patientVisit); } return(visitReasonList); } catch (Exception ex) { throw ex; } }
public async Task <List <ConsultationSummary> > getConsultationSummary_OLD(string patientEncounterId, bool summaryUpdated = false) { try { var json = string.Empty; string triagePatientEncounterId = string.Empty; List <ConsultationSummary> ConsultationSummary = new List <ConsultationSummary>(); ConsultationSummary model = new ConsultationSummary(); PatientEncounter encounter = new PatientEncounter(); encounter.EncounterId = patientEncounterId; if (summaryUpdated == true) { model.listPatientEncounter = encounter.encounterDetails(encounter).Result.ToList(); patientCaseId = model.listPatientEncounter[0].CaseId; patientId = model.listPatientEncounter[0].PatientId; model.patientEncounterId = patientEncounterId; model.patientId = patientId; model.patientCaseId = patientCaseId; model.patient = new Patient().getPatientBasicInfo(patientId).Result.patient; model.listVisitReason = new PatientVisit().getVisitReason(null, patientEncounterId).Result.ToList(); model.listCheifComplaint = new CheifComplaint().getCheifComplaint(null, patientEncounterId, 0, "").Result.ToList(); model.listPatientAllergy = new PatientAllergy().getPatientAllergies(patientId, null, null, DateTime.MinValue, DateTime.MinValue, true).Result.ToList(); model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, patientEncounterId, false, false).Result.ToList(); if (model.listPatientVitals.Count == 0) { PatientEncounter triageEncounter = new PatientEncounter(); triageEncounter.CaseId = patientCaseId; triageEncounter.EncounterType = "1"; if (triageEncounter.encounterDetails(triageEncounter).Result.Count > 0) { triagePatientEncounterId = triageEncounter.encounterDetails(triageEncounter).Result.ToList().First <PatientEncounter>().EncounterId; model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, triagePatientEncounterId, false, false).Result.ToList(); } } model.listPatientMedication = new PatientMedication().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientRadiologyOrder = new PatientRadiologyOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientLabOrder = new PatientLabOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientSpecialTest = new PatientSpecialTest().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, "").Result.ToList(); model.listPatientTherapy = new PatientTherapy().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientReferral = new PatientReferralOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientProcedure = new PatientProcedure().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null, null, false).Result.ToList(); model.listPatientDiagnosis = new PatientDiagnosis().getPatientDiagnosis(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, 0, "").Result.ToList(); model.listPatientProblem = new PatientProblem().getPatientProblems(patientId, true, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listPatientDisposition = new PatientDisposition().getPatientDisposition(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listClinicalTemplate = new ClinicalTemplate().getPatientClinicalTemplates(patientId, patientEncounterId).Result; model.SummaryUpdatedDate = DateTime.Now; Notes notes = new Notes(); notes.EntityType = "incident"; notes.ObjectId = patientCaseId; model.listProgressNotes = new Notes().getNotes(notes).Result; ConsultationSummary.Add(model); json = JsonConvert.SerializeObject(model); encounter.updateSummaryJson(patientEncounterId, json); } else { PatientEncounter pe = new PatientEncounter(); if (pe.encounterDetails(encounter).Result.Count > 0) { json = pe.encounterDetails(encounter).Result[0].SummaryJson; if (json != null) { model = JsonConvert.DeserializeObject <ConsultationSummary>(json); ConsultationSummary.Add(model); } else { model.listPatientEncounter = pe.encounterDetails(encounter).Result.ToList(); patientCaseId = model.listPatientEncounter[0].CaseId; patientId = model.listPatientEncounter[0].PatientId; model.patientEncounterId = patientEncounterId; model.patientId = patientId; model.patientCaseId = patientCaseId; model.patient = new Patient().getPatientBasicInfo(patientId).Result.patient; model.listVisitReason = new PatientVisit().getVisitReason(null, patientEncounterId).Result.ToList(); model.listCheifComplaint = new CheifComplaint().getCheifComplaint(null, patientEncounterId, 0, "").Result.ToList(); model.listPatientAllergy = new PatientAllergy().getPatientAllergies(patientId, null, null, DateTime.MinValue, DateTime.MinValue, true).Result.ToList(); model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, patientEncounterId, false, false).Result.ToList(); if (model.listPatientVitals.Count == 0) { PatientEncounter triageEncounter = new PatientEncounter(); triageEncounter.CaseId = patientCaseId; triageEncounter.EncounterType = "1"; if (triageEncounter.encounterDetails(triageEncounter).Result.Count > 0) { triagePatientEncounterId = triageEncounter.encounterDetails(triageEncounter).Result.ToList().First <PatientEncounter>().EncounterId; model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, triagePatientEncounterId, false, false).Result.ToList(); } } model.listPatientMedication = new PatientMedication().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientRadiologyOrder = new PatientRadiologyOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientLabOrder = new PatientLabOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientSpecialTest = new PatientSpecialTest().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, "").Result.ToList(); model.listPatientTherapy = new PatientTherapy().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientReferral = new PatientReferralOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientProcedure = new PatientProcedure().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientDiagnosis = new PatientDiagnosis().getPatientDiagnosis(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, 0, "").Result.ToList(); model.listPatientProblem = new PatientProblem().getPatientProblems(patientId, true, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listPatientDisposition = new PatientDisposition().getPatientDisposition(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listClinicalTemplate = new ClinicalTemplate().getPatientClinicalTemplates(patientId, patientEncounterId).Result; model.SummaryUpdatedDate = DateTime.Now; Notes notes = new Notes(); notes.EntityType = "incident"; notes.ObjectId = patientCaseId; model.listProgressNotes = new Notes().getNotes(notes).Result; ConsultationSummary.Add(model); json = JsonConvert.SerializeObject(model); encounter.updateSummaryJson(patientEncounterId, json); } } else { model.listPatientEncounter = new PatientEncounter().encounterDetails(encounter).Result.ToList(); patientCaseId = model.listPatientEncounter[0].CaseId; patientId = model.listPatientEncounter[0].PatientId; model.patientEncounterId = patientEncounterId; model.patientId = patientId; model.patientCaseId = patientCaseId; model.patient = new Patient().getPatientBasicInfo(patientId).Result.patient; model.listVisitReason = new PatientVisit().getVisitReason(null, patientEncounterId).Result.ToList(); model.listCheifComplaint = new CheifComplaint().getCheifComplaint(null, patientEncounterId, 0, "").Result.ToList(); model.listPatientAllergy = new PatientAllergy().getPatientAllergies(patientId, null, null, DateTime.MinValue, DateTime.MinValue, true).Result.ToList(); model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, patientEncounterId, false, false).Result.ToList(); if (model.listPatientVitals.Count == 0) { PatientEncounter triageEncounter = new PatientEncounter(); triageEncounter.CaseId = patientCaseId; triageEncounter.EncounterType = "1"; if (triageEncounter.encounterDetails(triageEncounter).Result.Count > 0) { triagePatientEncounterId = triageEncounter.encounterDetails(triageEncounter).Result.ToList().First <PatientEncounter>().EncounterId; model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, triagePatientEncounterId, false, false).Result.ToList(); } } model.listPatientMedication = new PatientMedication().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientRadiologyOrder = new PatientRadiologyOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientLabOrder = new PatientLabOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientSpecialTest = new PatientSpecialTest().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, "").Result.ToList(); model.listPatientTherapy = new PatientTherapy().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientReferral = new PatientReferralOrder().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientProcedure = new PatientProcedure().getPatientOrder(null, patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, false, null).Result.ToList(); model.listPatientDiagnosis = new PatientDiagnosis().getPatientDiagnosis(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, 0, "").Result.ToList(); model.listPatientProblem = new PatientProblem().getPatientProblems(patientId, true, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listPatientDisposition = new PatientDisposition().getPatientDisposition(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listClinicalTemplate = new ClinicalTemplate().getPatientClinicalTemplates(patientId, patientEncounterId).Result.ToList(); model.SummaryUpdatedDate = DateTime.Now; Notes notes = new Notes(); notes.EntityType = "incident"; notes.ObjectId = patientCaseId; model.listProgressNotes = new Notes().getNotes(notes).Result; ConsultationSummary.Add(model); json = JsonConvert.SerializeObject(model); encounter.updateSummaryJson(patientEncounterId, json); } } return(ConsultationSummary); } catch (Exception ex) { throw ex; } }
private async Task <ConsultationSummary> getConsultationSummaryModel(List <PatientEncounter> listPatientEncounter, bool isStartEncounter = false) { var json = string.Empty; string triagePatientEncounterId = string.Empty; ConsultationSummary model = new ConsultationSummary(); string patientEncounterId = listPatientEncounter[0].EncounterId; string EncounterTemplateId = listPatientEncounter[0].EncounterTemplateId; model.listPatientEncounter = listPatientEncounter; patientCaseId = model.listPatientEncounter[0].CaseId; patientId = new PatientCase().getCaseDetails(patientCaseId).Result.PatientId; model.patientEncounterId = patientEncounterId; model.patientId = patientId; model.patientCaseId = patientCaseId; model.patient = new Patient().getPatientDetails(patientId).Result; model.listVisitReason = new PatientVisit().getVisitReason("", "", patientCaseId, model.listPatientEncounter[0].AppointmentId).Result.ToList(); model.listCheifComplaint = new List <CheifComplaint>();//new CheifComplaint().getCheifComplaint(null, patientEncounterId, 0, "").Result.ToList(); model.listPatientAllergy = new PatientAllergy().getPatientAllergies(patientId, null, null, DateTime.MinValue, DateTime.MinValue, true).Result.ToList(); model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, patientEncounterId, false, false, "", false).Result.ToList(); if (model.listPatientVitals.Count == 0 && model.listPatientEncounter[0].EncounterType != "1") { PatientEncounter triageEncounter = new PatientEncounter(); triageEncounter.CaseId = patientCaseId; triageEncounter.EncounterType = "1"; List <PatientEncounter> triageEncounterList = triageEncounter.getEncounterDetails(triageEncounter).Result.ToList(); if (triageEncounterList.Count > 0) { triagePatientEncounterId = triageEncounterList.First <PatientEncounter>().EncounterId; model.listPatientVitals = new PatientVitals().getPatientEncounterVitals(null, triagePatientEncounterId, false, false, "", false).Result.ToList(); } } if (!isStartEncounter && listPatientEncounter[0].EncounterType != ((int)mzk_encountertype.Triage).ToString()) { EntityCollection patientOrderDetailsCollection = new PatientOrder().getPatientOrderDetails(patientEncounterId); if (patientOrderDetailsCollection != null) { model.listPatientRadiologyOrder = new PatientRadiologyOrder().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.Radiology).ToString()).ToList()).Result.ToList(); model.listPatientLabOrder = new PatientLabOrder().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.Lab).ToString()).ToList()).Result.ToList(); model.listPatientSpecialTest = new PatientSpecialTest().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.SpecialTest).ToString()).ToList()).Result.ToList(); model.listPatientTherapy = new List <PatientTherapy>(); model.listPatientReferral = new PatientReferralOrder().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.Referral).ToString()).ToList()).Result.ToList(); model.listPatientProcedure = new PatientProcedure().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.Procedure).ToString()).ToList()).Result.ToList(); model.listPatientMedication = new PatientMedication().getPatientOrder(patientOrderDetailsCollection.Entities.Where(item => (item["mzk_type"] as OptionSetValue).Value.ToString() == ((int)mzk_patientordermzk_Type.Medication).ToString()).ToList()).Result.ToList(); } } else { model.listPatientRadiologyOrder = new List <PatientRadiologyOrder>(); model.listPatientLabOrder = new List <PatientLabOrder>(); model.listPatientSpecialTest = new List <PatientSpecialTest>(); model.listPatientTherapy = new List <PatientTherapy>(); model.listPatientReferral = new List <PatientReferralOrder>(); model.listPatientProcedure = new List <PatientProcedure>(); model.listPatientMedication = new List <PatientMedication>(); } if (!isStartEncounter && listPatientEncounter[0].EncounterType != ((int)mzk_encountertype.Triage).ToString()) { model.listPatientDiagnosis = new PatientDiagnosis().getPatientDiagnosis(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue, 0, "").Result.ToList(); } else { model.listPatientDiagnosis = new List <PatientDiagnosis>(); } // model.listPatientProblem = new PatientProblem().getPatientProblems(patientId, true, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); model.listPatientProblem = new List <PatientProblem>(); if (!isStartEncounter && listPatientEncounter[0].EncounterType != ((int)mzk_encountertype.Triage).ToString()) { model.listPatientDisposition = new PatientDisposition().getPatientDisposition(patientEncounterId, null, null, DateTime.MinValue, DateTime.MinValue).Result.ToList(); } else { model.listPatientDisposition = new List <PatientDisposition>(); } if (!isStartEncounter) { model.listClinicalTemplate = new ClinicalTemplate().getPatientClinicalTemplates(patientId, patientEncounterId).Result; } else { model.listClinicalTemplate = new List <ClinicalTemplate>(); } if (listPatientEncounter[0].EncounterType != ((int)mzk_encountertype.Triage).ToString()) { model.listProgressNotes = new Notes().getCaseNotes(patientCaseId).Result; } else { model.listProgressNotes = new List <Notes>(); } model.SummaryUpdatedDate = DateTime.Now; json = JsonConvert.SerializeObject(model); string compressJson = string.Empty; compressJson = StringHelper.Compress(json); new PatientEncounter().updateSummaryJson(patientEncounterId, compressJson); return(model); }
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 override async Task <IActionResult> PostAsync([FromBody] PatientEncounter patientEncounter) { return(await base.PostAsync(patientEncounter)); }