220 likes | 365 Vues
Domain Driven Design and Event Sourcing with RIM. Introduction. RIM Resistance is Futile, you Will be Assimilated!. DDD and Event Sourcing. Introduction George de la Torre Developer of custom clinical apps For a long time Discovered RIM a long time ago… Oleg Sitalo (silent partner)
E N D
Introduction RIMResistance is Futile, you Will be Assimilated!
DDD and Event Sourcing • Introduction • George de la Torre • Developer of custom clinical apps • For a long time • Discovered RIM a long time ago… • Oleg Sitalo (silent partner) • Developer of custom clinical apps • For a long time together • Believes in RIM, at occasions…
DDD and Event Sourcing • Agenda • Google will find heaps of stuff on this • Will focus on the RIM stuff • Great resources for DDD/ES • http://msdn.microsoft.com/en-us/library/jj554200.aspx • Implementing Doman-Driven Design • Vaughn Vernon • Domain Driven Design (the Blue Book) • Eric Evans
DDD and Event Sourcing • Domain Driven Design • Object Oriented Model • Business needs & language captured • HL7 v3 RIM benefits • Design done! – the hardest part • Standard – open & shared to all • Deep insights into domain knowledge • Integration of domains built in (No barriers!) • Reuse logic across clinical domains
Domain ModelBlueprint for all Aggregates HL7 V3 RIM
Supporting DomainsExternal Services Vocabulary Bounded Contexts
Supporting DomainsExternal Services Anti Corruption Layer Other systems or Big Ball of Mud… Business Process and Rules Engines Point: This layer keeps RIM pure!
DDD and Event Sourcing • Event Sourcing • Only the Aggregate (D-MIM) is persisted • The command is saved (Behavior) • Aggregates publishes the events • Command Query Responsibility Segregation (CQRS) • Command (Transaction) Model • Query Model
Patient Dashboard ExampleUse Case • Schedule a patient visit • Find Patient (Query Model) • View Calendar (Query Model) • Patient assigned time slot (Command) • CreateAppointmentCommand(data) executes • Scheduling aggregate is created from data • The created aggregate is appended • Publishes event to update Query Model
Scheduling Aggregate • Considerations • Entity is usually the Root • No cloning, only class codes • Aggregates varies with the RIM set • Act may be the Root (Strategy) • Reference others Aggregates (Observations) • Act Mood partitioning • PHI segregation requirement (Query model too) • Performance
Scheduling Aggregate • Considerations continued… • Serialized, XML, JSON, etc… • Relational Database (SQL) • Cache based systems • File systems • NoSQL • Natural for event stores • Easier to query Aggregates if needed • Aggregates loaded for logic on command
Scheduling AggregateAppended CreateAppointmentCommand(data) Event Store
Scheduling AggregatePublishes Events AppointmentCreatedEvent(data) { UpdateDatabaseView() } Query model
Scheduling AggregatePublishes Events AppointmentCreatedEvent() { CreateAdmissionMessage() } HL7 2.x MSH|^~\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT^A01|MSG00001-|P|2.3 EVN|A01|198808181123 PID|||PATID1234^5^M11||JONES^WILLIAM^A^III||19610615|M-||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(91-9)379-1212|(919)271- 3434||S||PATID12345001^2^M10|123456789|9-87654^NC
Scheduling AggregatePublishes Events AppointmentCreatedEvent() { UpdateDataMart() }
Patient Dashboard ExampleTwo Separate Models (CQRS) • Domain (Transaction) Model • Complex structure (RIM) • Aggregates are only created from RIM • Aggregates are appended (Write Only) • Query Model • Simplified model structure (SQL) • Multiple models created as needed • Model optimized for querying (Read Only)
Simple Component DesignCQRS Query Web Dashboard Commands App Services Aggregate Services View Model Publishes to Events SQL