Skip to content

Commit

Permalink
VKT(Frontend & Backend): Enrollment history fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Nov 26, 2024
1 parent e2ed8a3 commit a95e64b
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 62 deletions.
20 changes: 20 additions & 0 deletions backend/vkt/db/4_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,26 @@ VALUES (2, null, 51400, '78b29334-a283-11ef-88a1-bf672bd574b1', '7676156682',
'https://pay.paytrail.com/pay/78b29334-a283-11ef-88a1-bf672bd574b1', 'OK',
null, 3);

INSERT INTO enrollment_appointment(person_id, examiner_id, examiner_exam_event_id,
skill_oral, skill_textual, skill_understanding,
partial_exam_speaking, partial_exam_speech_comprehension, partial_exam_writing, partial_exam_reading_comprehension,
status, digital_certificate_consent, email, phone_number, street, postal_code, town, country, first_name, last_name,
auth_hash, auth_hash_expires, auth_hash_sent, created_at)
VALUES (2, 1, 1,
false, true, false,
false, false, false, true,
'COMPLETED', false,
'[email protected]', '0401234504', null, null, null, null,
'Anneli', 'Annikkinen',
'22223089-83a8-4163-8180-d8b675ff5337', NOW() - INTERVAL '13 days', NOW() - INTERVAL '16 days',
NOW() - INTERVAL '17 days');

INSERT INTO payment(version, enrollment_id, amount, transaction_id, reference, payment_url,
payment_status, refunded_at, enrollment_appointment_id)
VALUES (3, null, 51400, '12345634-a283-11ef-88a1-bf672bd574b1', '9676156682',
'https://pay.paytrail.com/pay/12345634-a283-11ef-88a1-bf672bd574b1', 'OK',
null, 3);

-- Insert enrollment appointment
INSERT INTO enrollment_appointment(person_id, examiner_id, examiner_exam_event_id,
skill_oral, skill_textual, skill_understanding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import fi.oph.vkt.repository.EnrollmentGradesRepository;
import fi.oph.vkt.repository.ExaminerExamEventRepository;
import fi.oph.vkt.util.ClerkEnrollmentUtil;
import fi.oph.vkt.util.ExaminerUtil;
import fi.oph.vkt.util.UUIDSource;
import fi.oph.vkt.util.exception.APIException;
import fi.oph.vkt.util.exception.APIExceptionType;
Expand Down Expand Up @@ -119,7 +120,7 @@ public ExaminerEnrollmentGradesDTO getAppointmentGrades(final String oid, final
enrollmentAppointment
);

return enrollmentGradeOptional.map(this::createGradesDTO).orElse(null);
return enrollmentGradeOptional.map(ExaminerUtil::createGradesDTO).orElse(null);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -193,36 +194,7 @@ public ExaminerEnrollmentGradesDTO upsertAppointmentGrades(
enrollmentAppointment.setGrade(enrollmentGrade);
enrollmentAppointmentRepository.saveAndFlush(enrollmentAppointment);

return createGradesDTO(enrollmentGrade);
}

private ExaminerEnrollmentGradesDTO createGradesDTO(final EnrollmentGrade enrollmentGrade) {
return ExaminerEnrollmentGradesDTO
.builder()
.version(enrollmentGrade.getVersion())
.writingPartialExam(
createGradeDTO(enrollmentGrade.getWritingPartialExamGrade(), enrollmentGrade.getWritingPartialExamComment())
)
.readingComprehensionPartialExam(
createGradeDTO(
enrollmentGrade.getReadingComprehensionPartialExamGrade(),
enrollmentGrade.getReadingComprehensionPartialExamComment()
)
)
.speakingPartialExam(
createGradeDTO(enrollmentGrade.getSpeakingPartialExamGrade(), enrollmentGrade.getSpeakingPartialExamComment())
)
.speechComprehensionPartialExam(
createGradeDTO(
enrollmentGrade.getSpeechComprehensionPartialExamGrade(),
enrollmentGrade.getSpeechComprehensionPartialExamComment()
)
)
.build();
}

private EnrollmentGradeDTO createGradeDTO(final EnrollmentGradeType grade, final String comment) {
return grade == null ? null : EnrollmentGradeDTO.builder().grade(grade).comment(comment).build();
return ExaminerUtil.createGradesDTO(enrollmentGrade);
}

@Transactional
Expand Down Expand Up @@ -295,7 +267,8 @@ public List<ExaminerEnrollmentAppointmentHistoryDTO> getEnrollmentAppointmentHis

return enrollmentAppointments
.stream()
.map(e -> ClerkEnrollmentUtil.createClerkEnrollmentAppointmentHistoryDTO(enrollmentAppointment))
.filter(e -> e.getId() != enrollmentAppointmentId)
.map(ClerkEnrollmentUtil::createClerkEnrollmentAppointmentHistoryDTO)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import fi.oph.vkt.audit.dto.ClerkEnrollmentAuditDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.EnrollmentGrade;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.FreeEnrollment;
import fi.oph.vkt.model.KoskiEducations;
import fi.oph.vkt.model.Person;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class ClerkEnrollmentUtil {
Expand Down Expand Up @@ -243,6 +245,7 @@ public static ExaminerEnrollmentAppointmentHistoryDTO createClerkEnrollmentAppoi
final ExaminerExamEventDTO examinerExamEventDTO = enrollmentAppointment.getExaminerExamEvent() != null
? ExaminerUtil.toExaminerExamEventWithoutEnrollmentsDTO(enrollmentAppointment.getExaminerExamEvent())
: null;
final EnrollmentGrade grade = enrollmentAppointment.getGrade();

return ExaminerEnrollmentAppointmentHistoryDTO
.builder()
Expand All @@ -256,6 +259,7 @@ public static ExaminerEnrollmentAppointmentHistoryDTO createClerkEnrollmentAppoi
.readingComprehensionPartialExam(enrollmentAppointment.isReadingComprehensionPartialExam())
.examEvent(examinerExamEventDTO)
.examinerName(examiner.getNickname() + " " + examiner.getLastName())
.grades(grade != null ? ExaminerUtil.createGradesDTO(grade) : null)
.build();
}
}
35 changes: 35 additions & 0 deletions backend/vkt/src/main/java/fi/oph/vkt/util/ExaminerUtil.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package fi.oph.vkt.util;

import fi.oph.vkt.api.dto.EnrollmentGradeDTO;
import fi.oph.vkt.api.dto.MunicipalityDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerContactRequestDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentGradesDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerExamEventDTO;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.EnrollmentGrade;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.ExaminerExamEvent;
import fi.oph.vkt.model.Municipality;
import fi.oph.vkt.model.type.EnrollmentGradeType;

import java.util.List;

public class ExaminerUtil {
Expand Down Expand Up @@ -92,4 +97,34 @@ public static ExaminerDetailsDTO toExaminerDetailsDTO(
.contactRequests(enrollmentAppointments.stream().map(ExaminerUtil::toContactRequestDTO).toList())
.build();
}

private static EnrollmentGradeDTO createGradeDTO(final EnrollmentGradeType grade, final String comment) {
return grade == null ? null : EnrollmentGradeDTO.builder().grade(grade).comment(comment).build();
}

public static ExaminerEnrollmentGradesDTO createGradesDTO(final EnrollmentGrade enrollmentGrade) {
return ExaminerEnrollmentGradesDTO
.builder()
.version(enrollmentGrade.getVersion())
.writingPartialExam(
createGradeDTO(enrollmentGrade.getWritingPartialExamGrade(), enrollmentGrade.getWritingPartialExamComment())
)
.readingComprehensionPartialExam(
createGradeDTO(
enrollmentGrade.getReadingComprehensionPartialExamGrade(),
enrollmentGrade.getReadingComprehensionPartialExamComment()
)
)
.speakingPartialExam(
createGradeDTO(enrollmentGrade.getSpeakingPartialExamGrade(), enrollmentGrade.getSpeakingPartialExamComment())
)
.speechComprehensionPartialExam(
createGradeDTO(
enrollmentGrade.getSpeechComprehensionPartialExamGrade(),
enrollmentGrade.getSpeechComprehensionPartialExamComment()
)
)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
useCommonTranslation,
useKoodistoMunicipalitiesTranslation,
} from 'configs/i18n';
import { useAppDispatch } from 'configs/redux';
import { useAppDispatch, useAppSelector } from 'configs/redux';
import { EnrollmentAppointmentStatus } from 'enums/app';
import { ClerkEnrollmentTextFieldEnum } from 'enums/clerkEnrollment';
import {
Expand All @@ -46,6 +46,7 @@ import { ClerkEnrollmentTextFieldProps } from 'interfaces/clerkEnrollmentTextFie
import { PartialExamsAndSkills } from 'interfaces/common/enrollment';
import { ExaminerExamEvent } from 'interfaces/examinerExamEvent';
import { sendClerkEnrollmentAppointmentAuthLink } from 'redux/reducers/clerkEnrollmentAppointment';
import { clerkEnrollmentAppointmentSelector } from 'redux/selectors/clerkEnrollmentAppointment';
import { DateTimeUtils } from 'utils/dateTime';

const CheckboxField = ({
Expand Down Expand Up @@ -365,6 +366,7 @@ export const ClerkEnrollmentAppointmentDetailsFields = ({
const [enrollmentHistoryModalOpen, setEnrollmentHistoryModalOpen] =
useState(false);
const [gradeModalOpen, setGradeModalOpen] = useState(false);
const { grades } = useAppSelector(clerkEnrollmentAppointmentSelector);

const initialFieldErrors = Object.values(
ClerkEnrollmentAppointmentDetailsFields,
Expand Down Expand Up @@ -544,7 +546,7 @@ export const ClerkEnrollmentAppointmentDetailsFields = ({
</div>
)}
{isViewMode ? (
<EnrollmentSkillsListTable enrollment={enrollment} />
<EnrollmentSkillsListTable grades={grades} enrollment={enrollment} />
) : (
<ClerkEnrollmentSkillsListFields
enrollment={enrollment}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Fragment, useEffect } from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import Accordion from '@mui/material/Accordion';
import AccordionDetails from '@mui/material/AccordionDetails';
import AccordionSummary from '@mui/material/AccordionSummary';
import { useEffect } from 'react';
import {
CustomButton,
CustomModal,
Expand Down Expand Up @@ -52,20 +56,33 @@ export const EnrollmentHistoryModal = ({
<LoadingProgressIndicator displayBlock={true} isLoading={isLoading}>
{enrollmentHistory &&
enrollmentHistory.map(
(enrollment: ClerkEnrollmentAppointmentHistory) => (
<Fragment key={enrollment.enrollmentTime.toString()}>
<Text className="bold">
{ExamEventUtils.languageAndLevelText(
enrollment.examEvent.language,
ExamLevel.GOOD_AND_SATISFACTORY,
translateCommon,
)}
{', '}
{DateTimeUtils.renderDate(enrollment.examEvent.date)}
</Text>
(
enrollment: ClerkEnrollmentAppointmentHistory,
idx: number,
) => (
<Accordion
defaultExpanded={idx === 0}
key={enrollment.enrollmentTime.toString()}
>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Text className="bold">
{ExamEventUtils.languageAndLevelText(
enrollment.examEvent.language,
ExamLevel.GOOD_AND_SATISFACTORY,
translateCommon,
)}
{', '}
{DateTimeUtils.renderDate(enrollment.examEvent.date)}
</Text>
</AccordionSummary>
<br />
<EnrollmentSkillsListTable enrollment={enrollment} />
</Fragment>
<AccordionDetails>
<EnrollmentSkillsListTable
grades={enrollment.grades}
enrollment={enrollment}
/>
</AccordionDetails>
</Accordion>
),
)}
</LoadingProgressIndicator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { Fragment } from 'react';
import { H3, Text } from 'shared/components';

import { useClerkTranslation, useCommonTranslation } from 'configs/i18n';
import { useAppSelector } from 'configs/redux';
import { PartialExamsAndSkills } from 'interfaces/common/enrollment';
import { clerkEnrollmentAppointmentSelector } from 'redux/selectors/clerkEnrollmentAppointment';
import { ClerkEnrollmentAppointmentGrades } from 'interfaces/clerkEnrollment';
import {
PartialExams,
PartialExamsAndSkills,
} from 'interfaces/common/enrollment';

interface GradedPartialExams extends Omit<PartialExams, 'understandingSkill'> {}

export const EnrollmentSkillsListTable = ({
enrollment,
grades,
}: {
enrollment: PartialExamsAndSkills;
grades: ClerkEnrollmentAppointmentGrades;
}) => {
const translateCommon = useCommonTranslation();
const { t } = useClerkTranslation({
Expand All @@ -19,25 +25,23 @@ export const EnrollmentSkillsListTable = ({
const partialTextualExams = [
'writingPartialExam',
'readingComprehensionPartialExam',
].filter(
(exam) => !!enrollment[exam as keyof PartialExamsAndSkills],
) as Array<keyof PartialExamsAndSkills>;
].filter((exam) => !!enrollment[exam as keyof GradedPartialExams]) as Array<
keyof GradedPartialExams
>;

const partialOralExams = [
'speakingPartialExam',
'speechComprehensionPartialExam',
].filter(
(exam) => !!enrollment[exam as keyof PartialExamsAndSkills],
) as Array<keyof PartialExamsAndSkills>;

const { grades } = useAppSelector(clerkEnrollmentAppointmentSelector);
].filter((exam) => !!enrollment[exam as keyof GradedPartialExams]) as Array<
keyof GradedPartialExams
>;

const renderGrade = (grade: string) =>
grade && grade !== '' ? translateCommon(`enrollment.grades.${grade}`) : '-';
const renderComment = (comment: string) =>
comment && comment !== '' ? comment : '-';

const partialExamsRow = (exams: Array<keyof PartialExamsAndSkills>) => {
const partialExamsRow = (exams: Array<keyof GradedPartialExams>) => {
return exams.map((exam, idx) => (
<Fragment key={exam}>
{idx > 0 && <div />}
Expand All @@ -46,8 +50,8 @@ export const EnrollmentSkillsListTable = ({
{translateCommon(`enrollment.partialExamsAndSkills.${exam}`)}
</Text>
</div>
<Text>{renderGrade(grades[exam]?.grade)}</Text>
<Text>{renderComment(grades[exam]?.comment)}</Text>
<Text>{renderGrade(grades && grades[exam]?.grade)}</Text>
<Text>{renderComment(grades && grades[exam]?.comment)}</Text>
</Fragment>
));
};
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/vkt/src/interfaces/clerkEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface ClerkEnrollmentAppointmentHistory
enrollmentTime: Dayjs;
examEvent: ExaminerExamEvent;
examinerName: string;
grades: ClerkEnrollmentAppointmentGrades;
}

export interface ClerkEnrollmentAppointmentHistoryResponse
Expand Down

0 comments on commit a95e64b

Please sign in to comment.