Skip to content

Commit

Permalink
OK-786 (new): Save-logic for koski-tutkinnot, validation logic, lisen…
Browse files Browse the repository at this point in the history
…siaatti -option removed, minor fixes to component definition
  • Loading branch information
pitkamak committed Jan 29, 2025
1 parent f918ccc commit e8f6b3b
Show file tree
Hide file tree
Showing 34 changed files with 70,389 additions and 70,015 deletions.
139,684 changes: 69,842 additions & 69,842 deletions dev-resources/koski/korkeakoulutukset.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS application_koski_tutkinnot (
application_key varchar(40),
tutkinnot jsonb,
PRIMARY KEY (application_key)
);

COMMENT ON TABLE application_koski_tutkinnot IS 'Koskesta haetut tutkinnot hakemuksittain, tallennetaan tarvittaessa';
14 changes: 13 additions & 1 deletion resources/less/editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,22 @@
margin-bottom: 5px;
}

.editor-form__property-component-info-wrapper {
display: flex;
flex: auto;
flex-flow: row nowrap;
align-content: center;
column-gap: 20px;
margin-bottom: 10px;
}

.editor-form__component-item-description {
color: @blue-text-color;
font-size: 14px;
margin-bottom: 10px;
.embedded {
width: 40%;
padding-top: 8px;
}
}

.editor-form__koodisto-options {
Expand Down
7 changes: 7 additions & 0 deletions resources/sql/application-queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1387,3 +1387,10 @@ LEFT JOIN applications AS la
WHERE la.id IS NULL AND
a.haku in (:haku_oids) AND
a.person_oid in (:person_oids);

-- name: yesql-add-koski-tutkinnot<!
INSERT INTO application_koski_tutkinnot (application_key, tutkinnot)
VALUES (:application_key, :tutkinnot::jsonb);

-- name: yesql-get-koski-tutkinnot-for-application
SELECT tutkinnot FROM application_koski_tutkinnot WHERE application_key = :key;
18 changes: 17 additions & 1 deletion spec/ataru/applications/application_store_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,23 @@
[{:oid "hakukohde1"}]
false
fields-by-id
#{}))))
#{}))
(should== [{:application_key "application-oid"
:attachment_key "itse-syotetty-tutkintotodistus"
:state "attachment-missing"
:updated? false
:hakukohde "hakukohde1"}]
(store/create-application-attachment-reviews
"application-oid"
(store/filter-visible-attachments {:itse-syotetty-tutkinto-nimi {:value [["tutkinto1"]]}}
flat-form-content
fields-by-id)
{:itse-syotetty-tutkinto-nimi {:value [["tutkinto1"]]}}
nil
[{:oid "hakukohde1"}]
false
fields-by-id
#{}))))

(it "should update attachment reviews for application without hakukohteet"
(let [application (first (filter #(= "attachments" (:key %)) fixtures/applications))
Expand Down
20 changes: 20 additions & 0 deletions spec/ataru/fixtures/form.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[ataru.component-data.base-education-module-higher :refer [base-education-module-higher]]
[ataru.component-data.person-info-module :as person-info-module]
[ataru.component-data.kk-application-payment-module :as payment-module]
[ataru.component-data.koski-tutkinnot-module :as ktm]
[clojure.string :as string]))

(def metadata {:created-by {:oid "1.2.246.562.24.1000000"
Expand Down Expand Up @@ -245,6 +246,9 @@
:locked nil
:locked-by nil
:content [(component/hakukohteet)
(assoc-in (ktm/koski-tutkinnot-module metadata)
[:children 1 :options 9 :followups 0 :children 4 :id]
"itse-syotetty-tutkintotodistus")
(assoc (component/single-choice-button metadata)
:id "choice_1"
:options [{:value "0"
Expand Down Expand Up @@ -352,3 +356,19 @@
(merge minimal-form
{:id 909909
:key "payment-exemption-test-form"}))

(def tutkinto-test-form
(merge minimal-form
(-> {:content [(ktm/koski-tutkinnot-module metadata)]}
(assoc-in [:content 0 :children 1 :options 1 :followups 0 :children 1]
{:params {:question-group-id :lukiokoulutus-question-group},
:validators ["required"],
:fieldClass "formField", :fieldType "textField", :cannot-edit false, :cannot-view false,
:label {:fi "Miten menee??", :sv ""},
:id "additional-field-for-lukiokoulutus"})
(assoc-in [:content 0 :children 1 :options 6 :followups 0 :children 1]
{:params {:question-group-id :lukiokoulutus-question-group},
:validators ["required"],
:fieldClass "formField", :fieldType "textField", :cannot-edit false, :cannot-view false,
:label {:fi "Miten menee??", :sv ""},
:id "additional-field-for-kk-alemmat"}))))
12 changes: 5 additions & 7 deletions spec/ataru/koski/koski_json_parser_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,24 @@

(it "should parse korkeakoulu-tutkinnot from Koski-JSON"
(let [parsed (parser/parse-koski-tutkinnot
["kk-alemmat" "kk-ylemmat" "lisensiaatti" "tohtori"]
["kk-alemmat" "kk-ylemmat" "tohtori"]
(read-opiskeluoikeudet-from-json "korkeakoulutukset.json"))
kk-alemmat (filter #(= "kk-alemmat" (:level %)) parsed)
kk-ylemmat (filter #(= "kk-ylemmat" (:level %)) parsed)
lisensiaatti (filter #(= "lisensiaatti" (:level %)) parsed)
tohtori (filter #(= "tohtori" (:level %)) parsed)]
(should= 4 (count (levels parsed)))
(should= 3 (count (levels parsed)))
(should= 4 (count kk-alemmat))
(should= 8 (count kk-ylemmat))
(should= 1 (count lisensiaatti))
(should= 9 (count kk-ylemmat))
(should= 1 (count tohtori))
(should= ["1.2.246.562.10.38515028629_672501_2011-12-07" "1.2.246.562.10.78305677532_623404_2010-09-20"
"1.2.246.562.10.38515028629_642102_2010-12-10" "1.2.246.562.10.38515028629_633501_2013-04-15"]
(mapv :id kk-alemmat))
(should= ["1.2.246.562.10.38515028629_772501_2014-08-06" "1.2.246.562.10.78305677532_726404_2012-06-20"
"1.2.246.562.10.38515028629_772501_2016-12-19" "1.2.246.562.10.38515028629_772401_2009-11-16"
"1.2.246.562.10.38515028629_672401_2006-05-17" "1.2.246.562.10.38515028629_733501_2014-10-07"
"1.2.246.562.10.57572539237_771218_2014-12-11" "1.2.246.562.10.38515028629_733203_2004-10-22"]
"1.2.246.562.10.57572539237_771218_2014-12-11" "1.2.246.562.10.38515028629_772201_2017-01-25"
"1.2.246.562.10.38515028629_733203_2004-10-22"]
(mapv :id kk-ylemmat))
(should= "1.2.246.562.10.38515028629_772201_2017-01-25" (:id (first lisensiaatti)))
(should= "1.2.246.562.10.38515028629_875401_2017-10-17" (:id (first tohtori)))))

(it "should return empty when returned tutkinnot not in requested level list"
Expand Down
109 changes: 106 additions & 3 deletions spec/ataru/tutkinto/tutkinto_util_spec.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,116 @@
(ns ataru.tutkinto.tutkinto-util-spec
(:require [speclj.core :refer :all]
(:require [ataru.util :as util]
[speclj.core :refer :all]
[cheshire.core :as json]
[ataru.tutkinto.tutkinto-util :as tutkinto-util]))
[ataru.tutkinto.tutkinto-util :as tutkinto-util]
[ataru.fixtures.form :as form-fixtures]))

(defn- read-application-json [file-name]
(:application (json/parse-string (slurp (str "dev-resources/koski/" file-name)) true)))

(def answers {:amm-perus-tutkinto-id {:valid true,
:label {:fi "Ammatilliset perustutkinnot",
:sv "SV: Ammatilliset perustutkinnot",
:en ""},
:value [[""]],
:values [[{:value "", :valid true}]],
:original-value [[""]]},
:lukiokoulutus-tutkinto-id {:valid true,
:label {:fi "Lukiokoulutus", :sv "SV: Lukiokoulutus", :en ""},
:value [[""]],
:values [[{:value "", :valid true}]],
:original-value [[""]]}
:kk-alemmat-tutkinto-id {:valid true, :label {:fi "Alemmat korkeakoulututkinnot",
:sv "SV: Alemmat korkeakoulututkinnot",
:en ""},
:value [["1.2.246.562.10.78305677532_623404_2010-09-20"]],
:values [[{:value "1.2.246.562.10.78305677532_623404_2010-09-20", :valid true}]],
:original-value [[""]], :errors []}})

(def itse-syotetty-tutkinto-nimi-answer {:valid true, :label {:fi "Tutkinto",
:sv "SV: Tutkinto",
:en ""},
:value [["Supertutkinto"]],
:values [[{:value "Supertutkinto", :valid true}]],
:original-value [[""]], :errors []})

(def itse-syotetty-nongrouped-answer {:valid true, :label {:fi "Miten menee??", :sv "", :en ""},
:value "ihan ok",
:values {:value "ihan ok", :valid true},
:original-value "", :errors []})

(def flat-form-content (util/flatten-form-fields (:content form-fixtures/tutkinto-test-form)))
(def flat-form-content-with-nongrouped-itsesyotetty
(util/flatten-form-fields (:content (assoc-in form-fixtures/tutkinto-test-form [:content 0 :children 1 :options 9 :followups]
[{:params {},
:validators [],
:fieldClass "formField", :fieldType "textField", :cannot-edit false, :cannot-view false,
:label {:fi "Miten menee??", :sv ""},
:id "itse-syotetty-question-1"}
{:params {},
:validators [],
:fieldClass "formField", :fieldType "textField", :cannot-edit false, :cannot-view false,
:label {:fi "Miten menee huomenna??", :sv ""},
:id "itse-syotetty-question-2"}]))))
(defn find-from-flat-content [id flat-form-content]
(some #(when (= id (:id %)) %) flat-form-content))

(describe "Finding tutkinto-data from application"
(tags :unit)
(it "should detect tutkinto id fields in application"
(should= true (tutkinto-util/koski-tutkinnot-in-application? (read-application-json "application-with-koski-tutkinnot.json")))
))
))

(describe "Finding tutkinto-levels without any selections"
(tags :unit)
(it "should detect field related to level having some selections"
(should= false (tutkinto-util/koski-tutkinto-field-without-selections?
{:id "additional-field-for-kk-alemmat"}
flat-form-content
answers
["amm-perus" "lukiokoulutus" "kk-alemmat"])))
(it "should detect field related to level having no selections"
(should= true (tutkinto-util/koski-tutkinto-field-without-selections?
{:id "additional-field-for-lukiokoulutus"}
flat-form-content
answers
["amm-perus" "lukiokoulutus" "kk-alemmat"]))))

(describe "Resolving tutkinto-level selections"
(tags :unit)
(it "should detect selected koski-tutkinto level"
(should= true
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "kk-alemmat-question-group" flat-form-content)
flat-form-content
answers)))
(it "should ignore non-selected koski-tutkinto level"
(should= false
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "perusopetus-question-group" flat-form-content)
flat-form-content
answers)))
(it "should detect itse syötetty as selected when values in question group"
(should= true
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "itse-syotetty-question-group" flat-form-content)
flat-form-content
(assoc answers :itse-syotetty-tutkinto-nimi itse-syotetty-tutkinto-nimi-answer))))
(it "should detect itse syötetty as non-selected when no values in question group"
(should= false
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "itse-syotetty-question-group" flat-form-content)
flat-form-content
answers)))
(it "should detect itse syötetty as selected when non grouped values"
(should= true
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "itse-syotetty-question-2" flat-form-content-with-nongrouped-itsesyotetty)
flat-form-content-with-nongrouped-itsesyotetty
(assoc answers :itse-syotetty-question-1 itse-syotetty-tutkinto-nimi-answer))))
(it "should detect itse syötetty as non-selected when no values (neither non-grouped nor in question group)"
(should= false
(tutkinto-util/tutkinto-option-selected nil
(find-from-flat-content "itse-syotetty-question-1" flat-form-content-with-nongrouped-itsesyotetty)
flat-form-content-with-nongrouped-itsesyotetty
answers))))
49 changes: 26 additions & 23 deletions src/clj/ataru/applications/application_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,13 @@
:person-oid
(person-service/get-person person-service)
:oppijanumero))
koski-tutkinnot (future (some->> (when (tutkinto-util/koski-tutkinnot-in-application? application) (:person-oid application))
(koski/get-tutkinnot-for-oppija koski-service false)
:opiskeluoikeudet
(parse-koski-tutkinnot requested-tutkinto-levels)))]
koski-tutkinnot (future (when (tutkinto-util/koski-tutkinnot-in-application? application)
(if (tutkinto-util/save-koski-tutkinnot? form)
(application-store/koski-tutkinnot-for-application (:key application))
(some->> (:person-oid application)
(koski/get-tutkinnot-for-oppija koski-service false)
:opiskeluoikeudet
(parse-koski-tutkinnot requested-tutkinto-levels)))))]
(util/remove-nil-values {:application (-> application
(dissoc :person-oid)
(assoc :person (get-person this application))
Expand All @@ -545,25 +548,25 @@
(get-excel-report-of-applications-by-key
[_ application-keys selected-hakukohde selected-hakukohderyhma included-ids ids-only? sort-by-field sort-order session]
(when (aac/applications-access-authorized-including-opinto-ohjaaja? organization-service tarjonta-service suoritus-service person-service session application-keys [:view-applications :edit-applications])
(let [applications (application-store/get-applications-by-keys application-keys)
application-reviews (->> applications
(map :key)
application-store/get-application-reviews-by-keys
(reduce #(assoc %1 (:application-key %2) %2) {}))
application-review-notes (->> applications
(map :key)
application-store/get-application-review-notes-by-keys
(group-by :application-key))
onr-persons (->> (map :person-oid applications)
distinct
(filter some?)
(person-service/get-persons person-service))
applications-with-persons (map (fn [application]
(assoc application
:person (->> (:person-oid application)
(get onr-persons)
(person-service/parse-person-with-master-oid application))))
applications)
(let [applications (application-store/get-applications-by-keys application-keys)
application-reviews (->> applications
(map :key)
application-store/get-application-reviews-by-keys
(reduce #(assoc %1 (:application-key %2) %2) {}))
application-review-notes (->> applications
(map :key)
application-store/get-application-review-notes-by-keys
(group-by :application-key))
onr-persons (->> (map :person-oid applications)
distinct
(filter some?)
(person-service/get-persons person-service))
applications-with-persons (map (fn [application]
(assoc application
:person (->> (:person-oid application)
(get onr-persons)
(person-service/parse-person-with-master-oid application))))
applications)
hakukohteiden-ehdolliset (delay (hakukohteiden-ehdolliset valinta-tulos-service applications))
skip-answers-to-preserve-memory? (if (not-empty included-ids)
(<= 200000 (count applications))
Expand Down
Loading

0 comments on commit e8f6b3b

Please sign in to comment.