11package ch .elexis .core .ui .commands ;
22
33import java .util .List ;
4+ import java .util .Optional ;
45
56import org .eclipse .core .commands .AbstractHandler ;
67import org .eclipse .core .commands .ExecutionEvent ;
1314import org .eclipse .ui .IViewPart ;
1415import org .eclipse .ui .PlatformUI ;
1516
16- import ch .elexis .core .data .events . ElexisEventDispatcher ;
17+ import ch .elexis .core .data .util . NoPoUtil ;
1718import ch .elexis .core .l10n .Messages ;
19+ import ch .elexis .core .model .ICoverage ;
20+ import ch .elexis .core .model .IEncounter ;
21+ import ch .elexis .core .model .IMandator ;
22+ import ch .elexis .core .model .IPatient ;
23+ import ch .elexis .core .model .builder .IEncounterBuilder ;
1824import ch .elexis .core .services .holder .ContextServiceHolder ;
25+ import ch .elexis .core .services .holder .CoreModelServiceHolder ;
26+ import ch .elexis .core .services .holder .EncounterServiceHolder ;
1927import ch .elexis .core .ui .UiDesk ;
2028import ch .elexis .core .ui .dialogs .DocumentSelectDialog ;
2129import ch .elexis .core .ui .dialogs .SelectFallDialog ;
2432import ch .elexis .core .ui .views .TextView ;
2533import ch .elexis .core .ui .views .controls .GenericSearchSelectionDialog ;
2634import ch .elexis .data .Brief ;
27- import ch .elexis .data .Fall ;
28- import ch .elexis .data .Konsultation ;
2935import ch .elexis .data .Kontakt ;
30- import ch .elexis .data .Patient ;
3136import ch .elexis .data .Query ;
3237import ch .rgw .tools .ExHandler ;
3338import ch .rgw .tools .StringTool ;
@@ -37,34 +42,39 @@ public class BriefNewHandler extends AbstractHandler implements IHandler {
3742
3843 @ Override
3944 public Object execute (ExecutionEvent event ) throws ExecutionException {
40- Patient pat = ElexisEventDispatcher . getSelectedPatient ( );
45+ IPatient pat = ContextServiceHolder . get (). getActivePatient (). orElse ( null );
4146 if (pat == null ) {
4247 MessageDialog .openInformation (UiDesk .getTopShell (), Messages .Core_No_patient_selected ,
4348 Messages .Core_No_patient_selected );
4449 return null ;
4550 }
4651
47- Fall selectedFall = ( Fall ) ElexisEventDispatcher . getSelected ( Fall . class );
52+ ICoverage selectedFall = ContextServiceHolder . get (). getActiveCoverage (). orElse ( null );
4853 if (selectedFall == null ) {
4954 SelectFallDialog sfd = new SelectFallDialog (UiDesk .getTopShell ());
5055 sfd .open ();
5156 if (sfd .result != null ) {
52- ElexisEventDispatcher .fireSelectionEvent (sfd .result );
57+ selectedFall = NoPoUtil .loadAsIdentifiable (sfd .result , ICoverage .class ).orElse (null );
58+ ContextServiceHolder .get ().setActiveCoverage (selectedFall );
5359 } else {
5460 MessageDialog .openInformation (UiDesk .getTopShell (), Messages .TextView_NoCaseSelected , // $NON-NLS-1$
5561 Messages .TextView_SaveNotPossibleNoCaseAndKonsSelected ); // $NON-NLS-1$
5662 return null ;
5763 }
5864 }
5965
60- Konsultation selectedKonsultation = ( Konsultation ) ElexisEventDispatcher . getSelected ( Konsultation .class );
66+ IEncounter selectedKonsultation = ContextServiceHolder . get (). getTyped ( IEncounter .class ). orElse ( null );
6167 if (selectedKonsultation == null ) {
62- Konsultation k = pat .getLetzteKons (false );
63- if (k == null ) {
64- k = ((Fall ) ElexisEventDispatcher .getSelected (Fall .class )).neueKonsultation ();
65- k .setMandant (ContextServiceHolder .getActiveMandatorOrNull ());
68+ selectedKonsultation = EncounterServiceHolder .get ().getLatestEncounter (pat ).orElse (null );
69+ if (selectedKonsultation == null ) {
70+ Optional <IMandator > activeMandator = ContextServiceHolder .get ().getActiveMandator ();
71+ if (activeMandator .isPresent ()) {
72+ selectedKonsultation = new IEncounterBuilder (CoreModelServiceHolder .get (), selectedFall ,
73+ activeMandator .get ()).buildAndSave ();
74+ EncounterServiceHolder .get ().addDefaultDiagnosis (selectedKonsultation );
75+ }
6676 }
67- ElexisEventDispatcher . fireSelectionEvent ( k );
77+ ContextServiceHolder . get (). setTyped ( selectedKonsultation );
6878 }
6979
7080 TextView tv = null ;
@@ -73,7 +83,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
7383 qbe .add (Brief .FLD_TYPE , Query .EQUALS , Brief .TEMPLATE );
7484 qbe .add (Brief .FLD_KONSULTATION_ID , Query .NOT_EQUAL , "SYS" ); //$NON-NLS-1$
7585 qbe .startGroup ();
76- qbe .add (Brief .FLD_DESTINATION_ID , Query .EQUALS , ElexisEventDispatcher .getSelectedMandator ().getId ());
86+ qbe .add (Brief .FLD_DESTINATION_ID , Query .EQUALS ,
87+ ContextServiceHolder .get ().getActiveMandator ().get ().getId ());
7788 qbe .or ();
7889 qbe .add (Brief .FLD_DESTINATION_ID , Query .EQUALS , StringTool .leer );
7990 qbe .endGroup ();
0 commit comments