5151import de .symeda .sormas .api .infrastructure .district .DistrictReferenceDto ;
5252import de .symeda .sormas .api .infrastructure .region .RegionReferenceDto ;
5353import de .symeda .sormas .api .person .PersonDto ;
54+ import de .symeda .sormas .api .therapy .Drug ;
5455import de .symeda .sormas .api .utils .DataHelper ;
56+ import de .symeda .sormas .api .utils .Diseases ;
5557import de .symeda .sormas .api .utils .fieldvisibility .FieldVisibilityCheckers ;
5658import de .symeda .sormas .ui .ControllerProvider ;
5759import de .symeda .sormas .ui .UiUtil ;
@@ -74,6 +76,7 @@ public class ContactCreateForm extends AbstractEditForm<ContactDto> {
7476 private static final String CHOOSE_CASE_LOC = "chooseCaseLoc" ;
7577 private static final String REMOVE_CASE_LOC = "removeCaseLoc" ;
7678 private static final String ADOPT_ADDRESS_LOC = "adoptAddressLoc" ;
79+ private static final String PROPHYLAXIS_LOC = "prophylaxisLoc" ;
7780
7881 //@formatter:off
7982 private static final String HTML_LAYOUT =
@@ -97,7 +100,9 @@ public class ContactCreateForm extends AbstractEditForm<ContactDto> {
97100 LayoutUtil .fluidRowLocs (ContactDto .RELATION_TO_CASE ) +
98101 LayoutUtil .fluidRowLocs (ADOPT_ADDRESS_LOC ) +
99102 LayoutUtil .fluidRowLocs (ContactDto .RELATION_DESCRIPTION ) +
100- LayoutUtil .fluidRowLocs (ContactDto .DESCRIPTION );
103+ LayoutUtil .fluidRowLocs (ContactDto .DESCRIPTION ) +
104+ LayoutUtil .loc (PROPHYLAXIS_LOC ) +
105+ LayoutUtil .fluidRowLocs (4 , ContactDto .PROPHYLAXIS_PRESCRIBED , 4 , ContactDto .PRESCRIBED_DRUG , 4 , ContactDto .PRESCRIBED_DRUG_TEXT );
101106 //@formatter:on
102107
103108 private OptionGroup contactProximities ;
@@ -109,6 +114,7 @@ public class ContactCreateForm extends AbstractEditForm<ContactDto> {
109114 private TextField contactProximityDetails ;
110115
111116 private PersonCreateForm personCreateForm ;
117+ private Label prophylaxisLabel ;
112118
113119 DateField reportDate ;
114120 CheckBox multiDayContact ;
@@ -234,6 +240,17 @@ protected void addFields() {
234240 addField (ContactDto .CASE_ID_EXTERNAL_SYSTEM , TextField .class );
235241 addField (ContactDto .CASE_OR_EVENT_INFORMATION , TextArea .class ).setRows (4 );
236242
243+ // Prophylaxis details for IMI (Luxembourg only) - mirrors ContactDataForm
244+ prophylaxisLabel = new Label (I18nProperties .getString (Strings .headingProphylaxisLoc ));
245+ prophylaxisLabel .addStyleName (CssStyles .H3 );
246+ getContent ().addComponent (prophylaxisLabel , PROPHYLAXIS_LOC );
247+ prophylaxisLabel .setVisible (Disease .INVASIVE_MENINGOCOCCAL_INFECTION == disease );
248+
249+ CheckBox prophylaxisPrescribed = addField (ContactDto .PROPHYLAXIS_PRESCRIBED , CheckBox .class );
250+ prophylaxisPrescribed .setCaption (I18nProperties .getCaption (Captions .Contact_prophylaxisPrescribed ));
251+ addField (ContactDto .PRESCRIBED_DRUG , ComboBox .class );
252+ addField (ContactDto .PRESCRIBED_DRUG_TEXT , TextField .class );
253+
237254 initializeVisibilitiesAndAllowedVisibilities ();
238255
239256 region .addValueChangeListener (e -> {
@@ -259,14 +276,35 @@ protected void addFields() {
259276 FieldHelper .setVisibleWhen (getFieldGroup (), ContactDto .DISEASE_DETAILS , ContactDto .DISEASE , Arrays .asList (Disease .OTHER ), true );
260277 FieldHelper .setRequiredWhen (getFieldGroup (), ContactDto .DISEASE , Arrays .asList (ContactDto .DISEASE_DETAILS ), Arrays .asList (Disease .OTHER ));
261278
279+ FieldHelper .setVisibleWhen (
280+ getFieldGroup (),
281+ ContactDto .PRESCRIBED_DRUG ,
282+ ContactDto .PROPHYLAXIS_PRESCRIBED ,
283+ Collections .singletonList (Boolean .TRUE ),
284+ true );
285+ FieldHelper .setRequiredWhenNotNull (getFieldGroup (), ContactDto .PROPHYLAXIS_PRESCRIBED , ContactDto .PRESCRIBED_DRUG );
286+ FieldHelper .setVisibleWhen (
287+ getFieldGroup (),
288+ ContactDto .PRESCRIBED_DRUG_TEXT ,
289+ ContactDto .PRESCRIBED_DRUG ,
290+ Collections .singletonList (Drug .OTHER ),
291+ true );
292+ FieldHelper .setRequiredWhen (
293+ getFieldGroup (),
294+ ContactDto .PRESCRIBED_DRUG ,
295+ Arrays .asList (ContactDto .PRESCRIBED_DRUG_TEXT ),
296+ Arrays .asList (Drug .OTHER ));
297+
262298 cbDisease .addValueChangeListener (e -> {
263299 disease = (Disease ) e .getProperty ().getValue ();
264300 setVisible (disease != null , ContactDto .CONTACT_PROXIMITIES );
265301 if (isConfiguredServer (CountryHelper .COUNTRY_CODE_GERMANY )) {
266302 setVisible (disease == Disease .CORONAVIRUS , ContactDto .CONTACT_CATEGORY , ContactDto .CONTACT_PROXIMITY_DETAILS );
267303 }
268304 updateContactProximity ();
305+ updateProphylaxisSectionVisibility ();
269306 });
307+ updateProphylaxisSectionVisibility ();
270308
271309 if (!hasCaseRelation ) {
272310 Label caseInfoLabel = new Label (I18nProperties .getString (Strings .infoNoSourceCaseSelected ), ContentMode .HTML );
@@ -379,6 +417,44 @@ private void updateContactProximity() {
379417 contactProximities .setValue (value );
380418 }
381419
420+ private void updateProphylaxisSectionVisibility () {
421+
422+ boolean imiVisible = Disease .INVASIVE_MENINGOCOCCAL_INFECTION == disease ;
423+
424+ // Re-check @Diseases(IMI) against the current disease AND @HideForCountriesExcept("lu") against the deployment country.
425+ FieldVisibilityCheckers checkers =
426+ FieldVisibilityCheckers .withDisease (disease ).andWithCountry (FacadeProvider .getConfigFacade ().getCountryLocale ());
427+
428+ for (String propertyId : new String [] {
429+ ContactDto .PROPHYLAXIS_PRESCRIBED ,
430+ ContactDto .PRESCRIBED_DRUG ,
431+ ContactDto .PRESCRIBED_DRUG_TEXT }) {
432+ if (checkers .isVisible (ContactDto .class , propertyId )) {
433+ // Re-enable fields that were hidden and disallowed at init (e.g. directory flow, disease = null).
434+ addToVisibleAllowedFields (getField (propertyId ));
435+ }
436+ }
437+
438+ if (imiVisible ) {
439+ // Re-filter the drug options for the selected disease; the field factory populated them at construction time
440+ // (disease may have been null then, e.g. directory flow), so the list would otherwise show non-IMI drugs.
441+ FieldHelper .updateEnumData (
442+ (ComboBox ) getField (ContactDto .PRESCRIBED_DRUG ),
443+ Diseases .DiseasesConfiguration .getVisibleValues (Drug .class , disease ));
444+ }
445+
446+ // Only the checkbox is toggled directly; the two dependent fields are driven by the setVisibleWhen rules.
447+ setVisible (imiVisible , ContactDto .PROPHYLAXIS_PRESCRIBED );
448+ if (!imiVisible ) {
449+ getField (ContactDto .PROPHYLAXIS_PRESCRIBED ).clear ();
450+ getField (ContactDto .PRESCRIBED_DRUG ).clear ();
451+ getField (ContactDto .PRESCRIBED_DRUG_TEXT ).clear ();
452+ setVisible (false , ContactDto .PRESCRIBED_DRUG , ContactDto .PRESCRIBED_DRUG_TEXT );
453+ }
454+
455+ prophylaxisLabel .setVisible (imiVisible && checkers .isVisible (ContactDto .class , ContactDto .PROPHYLAXIS_PRESCRIBED ));
456+ }
457+
382458 private void hideAndFillJurisdictionFields () {
383459
384460 region .setVisible (false );
0 commit comments