using SheetMe.Core.Catalog; using SheetMe.Data.Stores; namespace SheetMe.Designer.Services; /// /// 지금 고른 환자 — 앱 전체가 하나를 공유한다. /// /// 왜 전역인가. 환자는 미리보기 창에서 고르는데, 그 값이 필요한 곳은 거기만이 아니다 — /// 쿼리 편집기의 '검증 실행'도 같은 환자로 돌려야 의미가 있다. /// 창마다 따로 들고 있으면 같은 서식을 두 화면에서 서로 다른 환자로 보게 되고, /// 그건 화면으로 구분할 수 없다. /// /// 하나만 둔다. 여러 개를 허용하면 어느 것이 지금 것인지 알 수 없고, /// 환자 정보가 걸린 문제에서 그건 개인정보 사고가 된다. /// /// 앱이 닫힐 때까지 메모리에 남는다. 디스크에 쓰지 않는다 — /// 환자 문맥은 로그에도 안 남기기로 한 값이다(). /// public static class PatientSession { #region Member Fields /// 환자가 바뀌었다 — 열려 있는 화면들이 다시 그려야 한다 public static event EventHandler? Changed; #endregion #region Properties /// 지금 고른 환자의 문맥 — 안 골랐으면 null public static PatientContext? Current { get; private set; } /// 사람에게 보여 줄 한 줄 — 창 머리에 그대로 쓴다 public static string Label { get; private set; } = string.Empty; /// 고른 환자가 있는가 public static bool HasPatient => Current is not null; #endregion #region Methods /// 환자를 붙이거나(문맥 전달) 뗀다(null 전달) public static void Set(PatientContext? context, string label) { Current = context; Label = context is null ? string.Empty : label; Changed?.Invoke(null, EventArgs.Empty); } /// /// 치환 변수원 — 환자가 없으면 null 이고, 호출부는 그때 자리표시로 구문만 검사해야 한다. /// public static IQueryVariableSource? Variables() => Current is { } context ? new PatientQueryVariableSource(context, UserSession.Current.UidCod) : null; /// /// 이 문서용 태그·배선 해석기 한 벌 — 지금 세션 환자 기준. /// /// 미리보기를 거치지 않는 인쇄(Ctrl+P)가 쓴다. 미리보기 창은 자기 해석기를 창 수명만큼 /// 들고 있지만, 여기는 한 번 뽑는 종이라 그때그때 만든다. /// 주민번호·주소·담당의를 이 자리에서 한 번씩 읽는다 — 태그마다 읽으면 왕복이 늘어난다. /// public static (SheetMe.Core.Catalog.ITagValueResolver Tags, MDataTableRunner Fields) ResolversFor(SheetMe.Core.Models.FormDocument document) { var session = new SessionTagResolver(); SheetMe.Core.Catalog.ITagValueResolver tags = Current is { } picked ? new PatientTagResolver(picked, session, PatientIdentity.ResidentNumberOf(picked), PatientIdentity.AddressOf(picked), PatientIdentity.DoctorOf(picked), PatientIdentity.StaffDoctorOf(picked), PatientIdentity.DepartmentOf(picked), PatientIdentity.HospitalRowOf(picked), PatientIdentity.DiagnosisSourceFor(picked), PatientIdentity.SurgerySourceFor(picked), PatientIdentity.ReviewDiagnosisSourceFor(picked), PatientIdentity.VitalSourceFor(picked), PatientIdentity.ScheduledSurgerySourceFor(picked), PatientIdentity.PathologyDoctorSource(), PatientIdentity.LabDoctorSource(), PatientIdentity.ExtraStoreSource(), PatientIdentity.ContextStoreSource()) : session; return (tags, new MDataTableRunner(document, Variables())); } #endregion }