Skip to content

Commit 476e367

Browse files
authored
UHM-5972: code refactoring for Fix start and end dates for syphilis (#156)
1 parent 8f5a255 commit 476e367

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

configuration/pih/htmlforms/hiv/section-hiv-state.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@
165165
);
166166

167167
setUpNextButtonForSections('hiv-state');
168-
setUpDatepickerStartAndEndDateValidation('mom-syph-treat-start','mom-syph-treat-end');
169-
setUpDatepickerStartAndEndDateValidation('partner-syph-treat-start','partner-syph-treat-end');
168+
setUpDatepickerStartAndEndDateValidation();
170169
setUpObsWithObsDateTime('syph-checkbox');
171170
});
172171
</script>
@@ -956,9 +955,9 @@
956955
<obs conceptId="CIEL:1628" style="checkbox" answerConceptId="CIEL:112493"
957956
answerCode="pihcore.syphilisTreatmentPregnantMother" toggle="mom-syph-treat"/>
958957
</p>
959-
<p id="mom-syph-treat">
960-
<obs id="mom-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate"/>
961-
<obs id="mom-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate"/>
958+
<p id="mom-syph-treat" class="startDateEndDate">
959+
<obs id="mom-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" class="startDate"/>
960+
<obs id="mom-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" class="endDate"/>
962961
</p>
963962
</obsgroup>
964963
</div>
@@ -969,9 +968,9 @@
969968
<obs conceptId="CIEL:1628" style="checkbox" answerConceptId="CIEL:112493"
970969
answerCode="pihcore.syphilisTreatmentPartner" toggle="partner-syph-treat"/>
971970
</p>
972-
<p id="partner-syph-treat">
973-
<obs id="partner-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" />
974-
<obs id="partner-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" />
971+
<p id="partner-syph-treat" class="startDateEndDate">
972+
<obs id="partner-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" class="startDate"/>
973+
<obs id="partner-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" class="endDate"/>
975974
</p>
976975
</obsgroup>
977976
</div>

configuration/pih/htmlforms/hiv/section-pmtct-history.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@
134134
setUpNextButtonForSections('pmtct-history');
135135
setUpExpandableContacts('<uimessage code="pihcore.invalid.phoneNumber"/>');
136136
setUpExpandableTransferAndReferralDetails();
137-
setUpDatepickerStartAndEndDateValidation('mom-syph-treat-start','mom-syph-treat-end');
138-
setUpDatepickerStartAndEndDateValidation('partner-syph-treat-start','partner-syph-treat-end');
137+
setUpDatepickerStartAndEndDateValidation();
139138
setUpObsWithObsDateTime('syph-checkbox');
140139
});
141140
</script>
@@ -482,9 +481,9 @@
482481
answerCode="pihcore.syphilisTreatmentPregnantMother"
483482
toggle="mom-syph-treat"/>
484483
</p>
485-
<p id="mom-syph-treat">
486-
<obs id="mom-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate"/>
487-
<obs id="mom-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate"/>
484+
<p id="mom-syph-treat" class="startDateEndDate">
485+
<obs id="mom-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" class="startDate"/>
486+
<obs id="mom-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" class="endDate"/>
488487
</p>
489488
</obsgroup>
490489
</div>
@@ -496,9 +495,9 @@
496495
answerConceptId="CIEL:112493"
497496
answerCode="pihcore.syphilisTreatmentPartner" toggle="partner-syph-treat"/>
498497
</p>
499-
<p id="partner-syph-treat">
500-
<obs id="partner-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" />
501-
<obs id="partner-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" />
498+
<p id="partner-syph-treat" class="startDateEndDate">
499+
<obs id="partner-syph-treat-start" conceptId="CIEL:163526" labelCode="pihcore.treatmentStartDate" class="startDate"/>
500+
<obs id="partner-syph-treat-end" conceptId="CIEL:164384" labelCode="pihcore.treatmentEndDate" class="endDate"/>
502501
</p>
503502
</obsgroup>
504503
</div>

configuration/pih/scripts/global/zl.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,31 @@ function setUpExpandableContacts(badPhoneNumberMsg) {
9393
* and that the "end date" cannot be before the "start date" by updating the min and max dates of the respective
9494
* datepickers
9595
*/
96-
function setUpDatepickerStartAndEndDateValidation(startDateWidgetId, endDateWidgetId){
96+
function setUpDatepickerStartAndEndDateValidation(){
9797

98-
const startDatepicker = getField(startDateWidgetId + '.value');
99-
const endDatepicker = getField(endDateWidgetId + '.value');
98+
jq(".startDateEndDate").each(function (j, domEl) {
10099

101-
if (startDatepicker) {
102-
startDatepicker.change(function () {
103-
let startDate = getField(startDateWidgetId + '.value').datepicker('getDate');
104-
if (startDate) {
105-
endDatepicker.datepicker('option', 'minDate', startDate);
100+
const startDatepicker = jq(jq(this).find('.startDate'));
101+
const endDatepicker = jq(jq(this).find('.endDate'));
102+
103+
if (startDatepicker) {
104+
startDatepicker.change(function () {
105+
let startDate = startDatepicker.find('input[type=text]').datepicker('getDate');
106+
if (startDate) {
107+
endDatepicker.find('input[type=text]').datepicker('option', 'minDate', startDate);
108+
}
109+
});
106110
}
107-
});
108-
}
109111

110-
if (endDatepicker) {
111-
endDatepicker.change(function() {
112-
let endDate = getField(endDateWidgetId + '.value').datepicker('getDate');
113-
if (endDate) {
114-
startDatepicker.datepicker('option', 'maxDate', endDate);
112+
if (endDatepicker) {
113+
endDatepicker.change(function () {
114+
let endDate = endDatepicker.find('input[type=text]').datepicker('getDate');
115+
if (endDate) {
116+
startDatepicker.find('input[type=text]').datepicker('option', 'maxDate', endDate);
117+
}
118+
});
115119
}
116-
});
117-
}
120+
});
118121
}
119122

120123
function setUpExpandableTransferAndReferralDetails(){

0 commit comments

Comments
 (0)