public string GetPatientMasterVisitId(int PatientId, DateTime visitDate, string EncounterType, int ServiceAreaId, int UserId) { PatientMasterVisitManager pmvManager = new PatientMasterVisitManager(); List <PatientMasterVisit> pmv = new List <PatientMasterVisit>(); PatientEncounterLogic patientEncounter = new PatientEncounterLogic(); OutCome ResultOutcome = new OutCome(); pmv = pmvManager.GetPatientMasterVisitBasedonVisitDate(PatientId, visitDate); if (pmv != null) { if (pmv.Count > 0) { MasterVisitId = pmv[0].Id; } } if (MasterVisitId > 0) { Result = patientEncounter.SavePatientPreviousEncounter(PatientId, MasterVisitId, EncounterType, ServiceAreaId, Convert.ToInt32(Session["AppUserId"]), visitDate); if (Result > 0) { ResultOutcome.Result = MasterVisitId; ResultOutcome.Msg = EncounterType + " Encounter Saved"; } } else { var lookupLogic = new LookupLogic(); var facility = lookupLogic.GetFacility(Session["AppPosID"].ToString()); if (facility == null) { facility = lookupLogic.GetFacility(); } PatientMasterVisit pm = new PatientMasterVisit(); pm.ServiceId = 1; pm.VisitDate = visitDate; pm.VisitBy = UserId; pm.Start = visitDate; pm.End = visitDate; pm.PatientId = PatientId; pm.CreatedBy = UserId; pm.Active = true; pm.Status = 2; pm.FacilityId = facility.FacilityID; int PatientMasterVisitId = pmvManager.AddPatientMasterVisit(pm); int res = patientEncounter.SavePatientPreviousEncounter(PatientId, PatientMasterVisitId, EncounterType, ServiceAreaId, Convert.ToInt32(Session["AppUserId"]), visitDate); if (res > 0) { Result = PatientMasterVisitId; ResultOutcome.Result = Result; ResultOutcome.Msg = EncounterType + "Encounter Saved"; } } string jsonScreeningObject = "[]"; jsonScreeningObject = new JavaScriptSerializer().Serialize(ResultOutcome); return(jsonScreeningObject); }