Skip to content

Commit 832292e

Browse files
committed
#13425 - Refactor contact creation form to avoid unnecessary warnings for similar health IDs
- `ContactController` Replaced person readonly setting from method to constructor. - `ContactCreateForm` Added person readonly flag to constructor and removed the method that set it.
1 parent b399414 commit 832292e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

sormas-ui/src/main/java/de/symeda/sormas/ui/contact/ContactController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,10 @@ public CommitDiscardWrapperComponent<ContactCreateForm> getContactCreateComponen
595595
} else {
596596
disease = FacadeProvider.getEventFacade().getEventByUuid(eventParticipant.getEvent().getUuid(), false).getDisease();
597597
}
598-
createForm = new ContactCreateForm(disease, false, false, true);
598+
createForm = new ContactCreateForm(disease, false, false, true, true);
599599

600600
createForm.setValue(createNewContact(eventParticipant, disease));
601601
createForm.setPerson(eventParticipant.getPerson());
602-
createForm.setPersonDetailsReadOnly();
603602
createForm.setDiseaseReadOnly();
604603

605604
final CommitDiscardWrapperComponent<ContactCreateForm> createComponent =
@@ -628,10 +627,9 @@ public CommitDiscardWrapperComponent<ContactCreateForm> getContactCreateComponen
628627
public CommitDiscardWrapperComponent<ContactCreateForm> getContactCreateComponent(PersonDto person) {
629628
final ContactCreateForm createForm;
630629

631-
createForm = new ContactCreateForm(null, false, false, true);
630+
createForm = new ContactCreateForm(null, false, false, true, true);
632631
createForm.setValue(createNewContact(person));
633632
createForm.setPerson(person);
634-
createForm.setPersonDetailsReadOnly();
635633

636634
final CommitDiscardWrapperComponent<ContactCreateForm> createComponent =
637635
new CommitDiscardWrapperComponent<>(createForm, UiUtil.permitted(UserRight.CONTACT_CREATE), createForm.getFieldGroup());

sormas-ui/src/main/java/de/symeda/sormas/ui/contact/ContactCreateForm.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class ContactCreateForm extends AbstractEditForm<ContactDto> {
104104
private Disease disease;
105105
private final Boolean hasCaseRelation;
106106
private final boolean asSourceContact;
107+
private final boolean isPersonReadOnly;
107108
private NullableOptionGroup contactCategory;
108109
private TextField contactProximityDetails;
109110

@@ -123,10 +124,19 @@ public class ContactCreateForm extends AbstractEditForm<ContactDto> {
123124
private final boolean showPersonSearchButton;
124125
private Window warningSimilarPersons;
125126

127+
public ContactCreateForm(Disease disease, boolean hasCaseRelation, boolean asSourceContact, boolean showPersonSearchButton) {
128+
this(disease, hasCaseRelation, asSourceContact, showPersonSearchButton, false);
129+
}
130+
126131
/**
127132
* TODO use disease and case relation information given in ContactDto
128133
*/
129-
public ContactCreateForm(Disease disease, boolean hasCaseRelation, boolean asSourceContact, boolean showPersonSearchButton) {
134+
public ContactCreateForm(
135+
Disease disease,
136+
boolean hasCaseRelation,
137+
boolean asSourceContact,
138+
boolean showPersonSearchButton,
139+
boolean isPersonReadOnly) {
130140
super(
131141
ContactDto.class,
132142
ContactDto.I18N_PREFIX,
@@ -137,6 +147,7 @@ public ContactCreateForm(Disease disease, boolean hasCaseRelation, boolean asSou
137147
this.disease = disease;
138148
this.hasCaseRelation = hasCaseRelation;
139149
this.asSourceContact = asSourceContact;
150+
this.isPersonReadOnly = isPersonReadOnly;
140151
this.showPersonSearchButton = showPersonSearchButton;
141152

142153
addFields();
@@ -158,11 +169,18 @@ protected void addFields() {
158169
addField(ContactDto.DISEASE_DETAILS, TextField.class);
159170

160171
personCreateForm = new PersonCreateForm(false, false, false, showPersonSearchButton);
172+
if (isPersonReadOnly) {
173+
personCreateForm.setPersonDetailsReadOnly();
174+
}
161175
personCreateForm.setWidth(100, Unit.PERCENTAGE);
162176
personCreateForm.setValue(new PersonDto());
163177
getContent().addComponent(personCreateForm, ContactDto.PERSON);
164178

165179
personCreateForm.getNationalHealthIdField().addTextFieldValueChangeListener(e -> {
180+
// Only check if the health ID can be edited
181+
if (!personCreateForm.getNationalHealthIdField().isEnabled()) {
182+
return;
183+
}
166184
warningSimilarPersons = PersonFormHelper
167185
.warningSimilarPersons(personCreateForm.getNationalHealthIdField().getValue(), null, () -> warningSimilarPersons = null);
168186
});
@@ -406,10 +424,6 @@ public void setPerson(PersonDto person, boolean isNewPerson) {
406424
personCreateForm.setPerson(person, isNewPerson);
407425
}
408426

409-
public void setPersonDetailsReadOnly() {
410-
personCreateForm.setPersonDetailsReadOnly();
411-
}
412-
413427
public void setDiseaseReadOnly() {
414428
getField(CaseDataDto.DISEASE).setEnabled(false);
415429
}

0 commit comments

Comments
 (0)