diff --git a/.github/workflows/checking-repository-code.yml b/.github/workflows/checking-repository-code.yml new file mode 100644 index 0000000..173bd38 --- /dev/null +++ b/.github/workflows/checking-repository-code.yml @@ -0,0 +1,40 @@ +name: Checking Repository Code +on: [push] +jobs: + Checking-Repository-Code: + runs-on: ubuntu-latest + environment: Testing + env: + XXX: ${{ vars.XXX }} + steps: + - name: Environment Variables + run: | + echo "XXX: ${{ env.XXX }}" + - name: Checkout repository code + uses: actions/checkout@v4 + - name: Build Package + run: npm run install-build:production + - name: Testing code + run: npm run test-coverage:complete + - name: Prettier-linting code + run: npm run prettier-lint + - name: Set up Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + - name: Check for changes + id: changes + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "changes=true" >> $GITHUB_ENV + else + echo "changes=false" >> $GITHUB_ENV + fi + - name: Commit and push changes + if: env.changes == 'true' + run: | + git add . + git commit --amend --no-edit + git push --force + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/db-ddl/01-table-index.sql b/db-ddl/01-table-index.sql new file mode 100644 index 0000000..326dc24 --- /dev/null +++ b/db-ddl/01-table-index.sql @@ -0,0 +1,122 @@ +CREATE TABLE PUBLIC.PF_MED_FRECUENCY ( + MFRE_ID SERIAL PRIMARY KEY, + MFRE_EVERY_HOURS NUMERIC NOT NULL, + MFRE_QUANTITY NUMERIC NOT NULL +); + +CREATE INDEX IDX_MED_FRECUENCY_EVERYHOURS ON PUBLIC.PF_MED_FRECUENCY (MFRE_EVERY_HOURS); +CREATE INDEX IDX_MED_FRECUENCY_QUANTITY ON PUBLIC.PF_MED_FRECUENCY (MFRE_QUANTITY); +CREATE UNIQUE INDEX IDX_MED_FRECUENCY_ALL ON PUBLIC.PF_MED_FRECUENCY (MFRE_EVERY_HOURS, MFRE_QUANTITY); +CREATE UNIQUE INDEX IDX_MED_FRECUENCY_ID ON PUBLIC.PF_MED_FRECUENCY (MFRE_ID); + +CREATE TABLE PUBLIC.PF_MED_MANUFACTURER ( + MMAN_ID SERIAL PRIMARY KEY, + MMAN_NAME VARCHAR(255) NOT NULL +); + +CREATE UNIQUE INDEX IDX_MED_MANUFACTURER_ID ON PUBLIC.PF_MED_MANUFACTURER (MMAN_ID); +CREATE UNIQUE INDEX IDX_MED_MANUFACTURER_NAME ON PUBLIC.PF_MED_MANUFACTURER (MMAN_NAME); + +CREATE TABLE PUBLIC.PF_MED_SUBSTANCE ( + MSUB_ID SERIAL PRIMARY KEY, + MSUB_NAME VARCHAR(255) NOT NULL +); + +CREATE UNIQUE INDEX IDX_MED_SUBSTANCE_ID ON PUBLIC.PF_MED_SUBSTANCE (MSUB_ID); +CREATE UNIQUE INDEX IDX_MED_SUBSTANCE_NAME ON PUBLIC.PF_MED_SUBSTANCE (MSUB_NAME); + +CREATE TABLE PUBLIC.PF_USER ( + USER_ID SERIAL PRIMARY KEY, + USER_NAME VARCHAR(255) NOT NULL +); + +CREATE UNIQUE INDEX IDX_USER_ID ON PUBLIC.PF_USER (USER_ID); +CREATE UNIQUE INDEX IDX_USER_NAME ON PUBLIC.PF_USER (USER_NAME); + +CREATE TABLE PUBLIC.PF_MED_TYPE ( + MTYP_ID SERIAL PRIMARY KEY, + MTYP_NAME VARCHAR(255) NOT NULL +); + +CREATE UNIQUE INDEX IDX_MED_TYPE_ID ON PUBLIC.PF_MED_TYPE (MTYP_ID); +CREATE UNIQUE INDEX IDX_MED_TYPE_NAME ON PUBLIC.PF_MED_TYPE (MTYP_NAME); + +CREATE TABLE PUBLIC.PF_MED_BRANDED_MEDICINE ( + MBME_ID SERIAL PRIMARY KEY, + MBME_NAME VARCHAR(255) NOT NULL, + MTYP_ID INT NOT NULL REFERENCES PF_MED_TYPE(MTYP_ID), + MMAN_ID INT NOT NULL REFERENCES PF_MED_MANUFACTURER(MMAN_ID) +); + +CREATE INDEX IDX_MED_BRANDED_MEDICINE_MANUFACTURER ON PUBLIC.PF_MED_BRANDED_MEDICINE (MMAN_ID); +CREATE INDEX IDX_MED_BRANDED_MEDICINE_TYPE ON PUBLIC.PF_MED_BRANDED_MEDICINE (MTYP_ID); +CREATE UNIQUE INDEX IDX_MED_BRANDED_MEDICINE_ALL ON PUBLIC.PF_MED_BRANDED_MEDICINE (MBME_NAME, MTYP_ID, MMAN_ID); +CREATE UNIQUE INDEX IDX_MED_BRANDED_MEDICINE_ID ON PUBLIC.PF_MED_BRANDED_MEDICINE (MBME_ID); +CREATE UNIQUE INDEX IDX_MED_BRANDED_MEDICINE_NAME ON PUBLIC.PF_MED_BRANDED_MEDICINE (MBME_NAME); + +CREATE TABLE PUBLIC.PF_MED_BRANDED_PRESENTATION ( + MBPR_ID SERIAL PRIMARY KEY, + MBPR_QUANTITY NUMERIC NOT NULL, + MBME_ID INT NOT NULL REFERENCES PF_MED_BRANDED_MEDICINE(MBME_ID), + CONSTRAINT FK_BRANDED_PRESENTATION_BRANDED_MEDICINE FOREIGN KEY (MBME_ID) REFERENCES PF_MED_BRANDED_MEDICINE(MBME_ID) +); + +CREATE INDEX IDX_MED_BRANDED_PRESENTATION_BRANDED_MEDICINE ON PUBLIC.PF_MED_BRANDED_PRESENTATION (MBME_ID); +CREATE UNIQUE INDEX IDX_MED_BRANDED_PRESENTATION_ALL ON PUBLIC.PF_MED_BRANDED_PRESENTATION (MBPR_QUANTITY, MBME_ID); +CREATE UNIQUE INDEX IDX_MED_BRANDED_PRESENTATION_ID ON PUBLIC.PF_MED_BRANDED_PRESENTATION (MBPR_ID); + +CREATE TABLE PUBLIC.PF_MED_COMPONENT ( + MCOMP_ID SERIAL PRIMARY KEY, + MCOMP_GRAMS NUMERIC NOT NULL, + MSUB_ID INT NOT NULL REFERENCES PF_MED_SUBSTANCE(MSUB_ID), + MBPR_ID INT NOT NULL REFERENCES PF_MED_BRANDED_PRESENTATION(MBPR_ID) +); + +CREATE INDEX IDX_MED_COMPONENT_BRANDED_PRESENTATION ON PUBLIC.PF_MED_COMPONENT (MBPR_ID); +CREATE INDEX IDX_MED_COMPONENT_SUBSTANCE ON PUBLIC.PF_MED_COMPONENT (MSUB_ID); +CREATE UNIQUE INDEX IDX_MED_COMPONENT_ALL ON PUBLIC.PF_MED_COMPONENT (MCOMP_GRAMS, MSUB_ID, MBPR_ID); +CREATE UNIQUE INDEX IDX_MED_COMPONENT_ID ON PUBLIC.PF_MED_COMPONENT (MCOMP_ID); + +CREATE TABLE PUBLIC.PF_MED_PRESCRIPTION ( + MPRE_ID SERIAL PRIMARY KEY, + MPRE_ACTIVE BOOLEAN NOT NULL DEFAULT TRUE, + MPRE_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + MPRE_IS_SELF_MEDICATED BOOLEAN NOT NULL DEFAULT TRUE, + MTYP_ID INT NOT NULL REFERENCES PF_MED_TYPE(MTYP_ID), + MFRE_ID INT NOT NULL REFERENCES PF_MED_FRECUENCY(MFRE_ID), + USER_ID INT NOT NULL REFERENCES PF_USER(USER_ID) +); + +CREATE INDEX IDX_MED_PRESCRIPTION_FREQUENCY ON PUBLIC.PF_MED_PRESCRIPTION (MFRE_ID); +CREATE INDEX IDX_MED_PRESCRIPTION_TYPE ON PUBLIC.PF_MED_PRESCRIPTION (MTYP_ID); +CREATE INDEX IDX_MED_PRESCRIPTION_USER ON PUBLIC.PF_MED_PRESCRIPTION (USER_ID); +CREATE UNIQUE INDEX IDX_MED_PRESCRIPTION_ALL ON PUBLIC.PF_MED_PRESCRIPTION (MPRE_ACTIVE, MPRE_DATE, MPRE_IS_SELF_MEDICATED, MTYP_ID, MFRE_ID, USER_ID); +CREATE UNIQUE INDEX IDX_MED_PRESCRIPTION_ID ON PUBLIC.PF_MED_PRESCRIPTION (MPRE_ID); + +CREATE TABLE PUBLIC.PF_MED_PURCHASE ( + MPUR_ID SERIAL PRIMARY KEY, + MPUR_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + MPUR_DISCOUNT NUMERIC NOT NULL, + MPUR_PRICE NUMERIC NOT NULL, + MPUR_SHIPPING_COST NUMERIC NOT NULL, + MBME_ID INT NOT NULL REFERENCES PF_MED_BRANDED_MEDICINE(MBME_ID) +); + +CREATE INDEX IDX_MED_PURCHASE_BRANDED_MEDICINE ON PUBLIC.PF_MED_PURCHASE (MBME_ID); +CREATE INDEX IDX_MED_PURCHASE_DATE ON PUBLIC.PF_MED_PURCHASE (MPUR_DATE); +CREATE UNIQUE INDEX IDX_MED_PURCHASE_ALL ON PUBLIC.PF_MED_PURCHASE (MPUR_DATE, MPUR_DISCOUNT, MPUR_PRICE, MPUR_SHIPPING_COST, MBME_ID); +CREATE UNIQUE INDEX IDX_MED_PURCHASE_ID ON PUBLIC.PF_MED_PURCHASE (MPUR_ID); + +CREATE TABLE PUBLIC.PF_MED_STOCK ( + MSTO_ID SERIAL PRIMARY KEY, + MSTO_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + MSTO_QUANTITY NUMERIC NOT NULL, + MBPR_ID INT NOT NULL REFERENCES PF_MED_BRANDED_PRESENTATION(MBPR_ID), + USER_ID INT NOT NULL REFERENCES PF_USER(USER_ID) +); + +CREATE INDEX IDX_MED_STOCK_BRANDED_PRESENTATION ON PUBLIC.PF_MED_STOCK (MBPR_ID); +CREATE INDEX IDX_MED_STOCK_DATE ON PUBLIC.PF_MED_STOCK (MSTO_DATE); +CREATE INDEX IDX_MED_STOCK_USER ON PUBLIC.PF_MED_STOCK (USER_ID); +CREATE UNIQUE INDEX IDX_MED_STOCK_ALL ON PUBLIC.PF_MED_STOCK (MSTO_DATE, MSTO_QUANTITY, MBPR_ID, USER_ID); +CREATE UNIQUE INDEX IDX_MED_STOCK_ID ON PUBLIC.PF_MED_STOCK (MSTO_ID); diff --git a/db-ddl/02-data.sql b/db-ddl/02-data.sql new file mode 100644 index 0000000..fdf42d3 --- /dev/null +++ b/db-ddl/02-data.sql @@ -0,0 +1,1907 @@ +DO $$ +DECLARE + local_user_id INT; + local_mtyp_id INT; + local_mtyp_ids INT[] := '{}'; + local_mman_id INT; + local_mman_ids INT[] := '{}'; + local_msub_id INT; + local_msub_ids INT[] := '{}'; + local_mbme_id INT; + local_mbme_ids INT[] := '{}'; + local_mbpr_id INT; + local_mbpr_ids INT[] := '{}'; + local_mcomp_id INT; + local_mcomp_ids INT[] := '{}'; + local_mfre_id INT; + local_mfre_ids INT[] := '{}'; + local_mpre_id INT; + local_mpre_ids INT[] := '{}'; +BEGIN + + -- PF_USER + + INSERT INTO public.pf_user (user_id, user_name) + VALUES + ( + nextval( + 'pf_user_user_id_seq' :: regclass + ), + 'Arturo Andrés Mendoza Benavides' + ) RETURNING user_id INTO local_user_id; -- local_user_id + RAISE NOTICE 'Inserted into pf_user, user_id: %', + local_user_id; + + + -- PF_MED_MANUFACTURER + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'VITAMIN LIFE' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[1] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'ASCEND' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[2] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'SEVEN PHARMA' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[3] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'LABORATORIO CHILE' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[4] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'FARMACIA AHUMADA' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[5] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'LABORATORIO FNL' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[6] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'LABORATORIO ABEN LAB' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[7] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + INSERT INTO public.pf_med_manufacturer (mman_id, mman_name) + VALUES + ( + nextval( + 'pf_med_manufacturer_mman_id_seq' :: regclass + ), + 'GSK' + ) RETURNING mman_id INTO local_mman_id; + local_mman_ids := array_append(local_mman_ids, local_mman_id); -- local_mman_ids[8] + RAISE NOTICE 'Inserted into pf_med_manufacturer, mman_id: %', + local_mman_ids[array_length(local_mman_ids, 1) ]; + + + -- PF_MED_SUBSTANCE + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'LACTOBACILLUS ACIDOPHILUS' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[1] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'BIFIDOBACTERIUM BIFIDUM' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[2] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FOS-INULIN' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[3] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FENNEL SEED' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[4] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'COLLAGEN' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[5] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN C' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[6] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN D' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[7] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'BETA CAROTENE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[8] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'BIOTIN' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[9] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'CHROMIUM' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[10] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FOLIC ACID' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[11] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'IODINE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[12] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'KOREANINSENG' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[13] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'MAGNESIUM' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[14] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'MANGANESE SULFATE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[15] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'NIACINAMIDE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[16] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'PHOSPHORUS' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[17] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'SELENIUM' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[18] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN B1' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[19] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN B12' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[20] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN B2' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[21] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN B5' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[22] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN B6' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[23] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN D3' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[24] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN E' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[25] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN K1' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[26] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'ZINC' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[27] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'EZETIMIBA' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[28] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'ESCITALOPTRAM' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[29] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'ATORVASTATINA' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[30] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'MINOXIDIL' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[31] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FINASTERIDE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[32] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'CREATINE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[33] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FLUTICASONE FUROATE' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[34] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'VITAMIN A' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[35] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + INSERT INTO public.pf_med_substance (msub_id, msub_name) + VALUES + ( + nextval( + 'pf_med_substance_msub_id_seq' :: regclass + ), + 'FISH OIL' + ) RETURNING msub_id INTO local_msub_id; + local_msub_ids := array_append(local_msub_ids, local_msub_id); -- local_msub_ids[36] + RAISE NOTICE 'Inserted into pf_med_substance, msub_id: %', + local_msub_ids[array_length(local_msub_ids, 1) ]; + + -- PF_MED_TYPE + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'ATORVASTATINA' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[1] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'COLLAGEN' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[2] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'CORTICOSTEROID' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[3] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'CREATINE' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[4] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'ESCITALOPRAM' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[5] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'EZETIMIBA' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[6] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'HAIR GROWTH' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[7] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'MULTIVITAMIN' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[8] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'OMEGA-3' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[9] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'PROBIOTIC' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[10] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + INSERT INTO public.pf_med_type (mtyp_id, mtyp_name) + VALUES + ( + nextval( + 'pf_med_type_mtyp_id_seq' :: regclass + ), + 'VITAMIN A' + ) RETURNING mtyp_id INTO local_mtyp_id; + local_mtyp_ids := array_append(local_mtyp_ids, local_mtyp_id); -- local_mtyp_ids[11] + RAISE NOTICE 'Inserted into pf_med_type, mtyp_id: %', + local_mtyp_ids[array_length(local_mtyp_ids, 1) ]; + + + -- PF_MED_BRANDED_MEDICINE + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'DAILY BIOTIC FIBER', + local_mtyp_ids[10], + local_mman_ids[1] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[1] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'COLLAGEN EXTRA', + local_mtyp_ids[2], + local_mman_ids[1] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[2] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'MEN''S DAILY ONE', + local_mtyp_ids[8], + local_mman_ids[1] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[3] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'ZERITOL', + local_mtyp_ids[6], + local_mman_ids[2] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[4] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'ESCITALOPRAM', + local_mtyp_ids[5], + local_mman_ids[3] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[5] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'ATORVASTATINA', + local_mtyp_ids[1], + local_mman_ids[4] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[6] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'HAIR GROWTH', + local_mtyp_ids[7], + local_mman_ids[5] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[7] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'POWDER CREATINA MONOHYDRATE', + local_mtyp_ids[4], + local_mman_ids[6] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[8] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'AVAMYS', + local_mtyp_ids[3], + local_mman_ids[8] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[9] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'SIMI SARDIN', + local_mtyp_ids[9], + local_mman_ids[7] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[10] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + INSERT INTO public.pf_med_branded_medicine ( + mbme_id, mbme_name, mtyp_id, mman_id + ) + VALUES + ( + nextval( + 'pf_med_branded_medicine_mbme_id_seq' :: regclass + ), + 'A RETINOL', + local_mtyp_ids[11], + local_mman_ids[6] + ) RETURNING mbme_id INTO local_mbme_id; + local_mbme_ids := array_append(local_mbme_ids, local_mbme_id); -- local_mbme_ids[11] + RAISE NOTICE 'Inserted into pf_med_branded_medicine, mbme_id: %', + local_mbme_ids[array_length(local_mbme_ids, 1) ]; + + + -- PF_MED_BRANDED_PRESENTATION + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[1], + 60 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[1] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[2], + 120 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[2] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[3], + 100 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[3] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[4], + 28 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[4] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[5], + 30 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[5] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[6], + 30 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[6] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[7], + 30 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[7] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[8], + 60 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[8] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[9], + 120 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[9] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[10], + 90 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[10] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + INSERT INTO public.pf_med_branded_presentation (mbpr_id, mbme_id, mbpr_quantity) + VALUES + ( + nextval( + 'pf_med_branded_presentation_mbpr_id_seq' :: regclass + ), + local_mbme_ids[11], + 60 + ) RETURNING mbpr_id INTO local_mbpr_id; + local_mbpr_ids := array_append(local_mbpr_ids, local_mbpr_id); -- local_mbpr_ids[11] + RAISE NOTICE 'Inserted into pf_med_branded_presentation, mbpr_id: %', + local_mbpr_ids[array_length(local_mbpr_ids, 1) ]; + + + -- PF_MED_COMPONENT + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.15, + local_msub_ids[1], + local_mbpr_ids[1] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[1] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.15, + local_msub_ids[2], + local_mbpr_ids[1] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[2] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.1, + local_msub_ids[3], + local_mbpr_ids[1] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[3] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.05, + local_msub_ids[4], + local_mbpr_ids[1] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[4] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 4, + local_msub_ids[5], + local_mbpr_ids[2] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[5] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.2, + local_msub_ids[6], + local_mbpr_ids[2] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[6] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.00002, + local_msub_ids[7], + local_mbpr_ids[2] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[7] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.15, + local_msub_ids[6], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[8] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.0045, + local_msub_ids[8], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[9] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.000125, + local_msub_ids[9], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[10] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.000025, + local_msub_ids[10], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[11] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.0002, + local_msub_ids[11], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[12] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.000075, + local_msub_ids[12], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[13] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.04, + local_msub_ids[13], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[14] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.05, + local_msub_ids[14], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[15] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.0025, + local_msub_ids[15], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[16] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.015, + local_msub_ids[16], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[17] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.106, + local_msub_ids[17], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[18] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.00005, + local_msub_ids[18], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[19] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.006, + local_msub_ids[19], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[20] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.000012, + local_msub_ids[20], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[21] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.006, + local_msub_ids[21], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[22] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.015, + local_msub_ids[22], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[23] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.015, + local_msub_ids[23], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[24] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.0000025, + local_msub_ids[24], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[25] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.033, + local_msub_ids[25], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[26] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.000038, + local_msub_ids[26], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[27] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.02, + local_msub_ids[27], + local_mbpr_ids[3] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[28] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.01, + local_msub_ids[28], + local_mbpr_ids[4] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[29] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.01, + local_msub_ids[29], + local_mbpr_ids[5] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[30] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.01, + local_msub_ids[30], + local_mbpr_ids[6] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[31] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.003, + local_msub_ids[31], + local_mbpr_ids[7] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[32] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.001, + local_msub_ids[32], + local_mbpr_ids[7] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[33] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.001, + local_msub_ids[33], + local_mbpr_ids[8] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[34] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.0000275, + local_msub_ids[34], + local_mbpr_ids[9] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[35] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 2.92, + local_msub_ids[36], + local_mbpr_ids[10] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[36] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + INSERT INTO public.pf_med_component ( + mcomp_id, mcomp_grams, msub_id, mbpr_id + ) + VALUES + ( + nextval( + 'pf_med_component_mcomp_id_seq' :: regclass + ), + 0.001, + local_msub_ids[35], + local_mbpr_ids[11] + ) RETURNING mcomp_id INTO local_mcomp_id; + local_mcomp_ids := array_append(local_mcomp_ids, local_mcomp_id); -- local_mcomp_ids[37] + RAISE NOTICE 'Inserted into pf_med_component, mcomp_id: %', + local_mcomp_ids[array_length(local_mcomp_ids, 1) ]; + + + -- PF_MED_FRECUENCY + + INSERT INTO public.pf_med_frecuency ( + mfre_id, mfre_quantity, mfre_every_hours + ) + VALUES + ( + nextval( + 'pf_med_frecuency_mfre_id_seq' :: regclass + ), + 1, + 24 + ) RETURNING mfre_id INTO local_mfre_id; + local_mfre_ids := array_append(local_mfre_ids, local_mfre_id); -- local_mfre_ids[1] + RAISE NOTICE 'Inserted into pf_med_frecuency, mfre_id: %', + local_mfre_ids[array_length(local_mfre_ids, 1) ]; + + INSERT INTO public.pf_med_frecuency ( + mfre_id, mfre_quantity, mfre_every_hours + ) + VALUES + ( + nextval( + 'pf_med_frecuency_mfre_id_seq' :: regclass + ), + 2, + 24 + ) RETURNING mfre_id INTO local_mfre_id; + local_mfre_ids := array_append(local_mfre_ids, local_mfre_id); -- local_mfre_ids[2] + RAISE NOTICE 'Inserted into pf_med_frecuency, mfre_id: %', + local_mfre_ids[array_length(local_mfre_ids, 1) ]; + + INSERT INTO public.pf_med_frecuency ( + mfre_id, mfre_quantity, mfre_every_hours + ) + VALUES + ( + nextval( + 'pf_med_frecuency_mfre_id_seq' :: regclass + ), + 4, + 24 + ) RETURNING mfre_id INTO local_mfre_id; + local_mfre_ids := array_append(local_mfre_ids, local_mfre_id); -- local_mfre_ids[3] + RAISE NOTICE 'Inserted into pf_med_frecuency, mfre_id: %', + local_mfre_ids[array_length(local_mfre_ids, 1) ]; + + + -- PF_MED_PRESCRIPTION + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[10], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[1] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[2], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[2] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[8], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[3] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[1], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[4] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[5], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[5] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[6], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[6] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[7], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[7] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[4], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[8] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[3], + local_mfre_ids[3], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[9] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[9], + local_mfre_ids[2], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[10] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + INSERT INTO public.pf_med_prescription ( + mpre_id, mtyp_id, mfre_id, mpre_active, + mpre_is_self_medicated, mpre_date, + user_id + ) + VALUES + ( + nextval( + 'pf_med_prescription_mpre_id_seq' :: regclass + ), + local_mtyp_ids[11], + local_mfre_ids[1], + true, + true, + CURRENT_TIMESTAMP, + local_user_id + ) RETURNING mpre_id INTO local_mpre_id; + local_mpre_ids := array_append(local_mpre_ids, local_mpre_id); -- local_mpre_ids[11] + RAISE NOTICE 'Inserted into pf_med_prescription, mpre_id: %', + local_mpre_ids[array_length(local_mpre_ids, 1) ]; + + +END $$; +COMMIT; diff --git a/src/domain/model/activeComponentsByUnit.model.ts b/src/domain/model/activeComponentsByUnit.model.ts new file mode 100644 index 0000000..3ed82b0 --- /dev/null +++ b/src/domain/model/activeComponentsByUnit.model.ts @@ -0,0 +1,35 @@ +import { Domain as DomainError } from '../error/domain.error'; +import { Substance as SubstanceModel } from './substance.model'; +export class ActiveComponentByUnit { + private _grams!: number; + private _substance!: SubstanceModel; + constructor(grams: number, substance: SubstanceModel) { + this.grams = grams; + this.substance = substance; + } + public get grams(): number { + return this._grams; + } + public set grams(value: number) { + if (value <= 0) + throw new DomainError( + 'Active component by unit grams cannot be less or equal than zero' + ); + this._grams = value; + } + public get substance(): SubstanceModel { + return this._substance; + } + public set substance(value: SubstanceModel) { + this._substance = value; + } + public json(): { + grams: number; + substance: any; + } { + return { + grams: this.grams, + substance: this.substance.json() + }; + } +} diff --git a/src/domain/model/brandedMedicine.model.ts b/src/domain/model/brandedMedicine.model.ts new file mode 100644 index 0000000..240680d --- /dev/null +++ b/src/domain/model/brandedMedicine.model.ts @@ -0,0 +1,61 @@ +import { Domain as DomainError } from '../error/domain.error'; +import { Manufacturer as ManufacturerModel } from './manufacturer.model'; +import { Type as TypeModel } from './type.model'; +export class BrandedMedicine { + private _id!: string | undefined; + private _name!: string; + private _type!: TypeModel; + private _manufacturer!: ManufacturerModel; + constructor( + id: string | undefined | null, + name: string, + type: TypeModel, + manufacturer: ManufacturerModel + ) { + this.id = id; + this.name = name; + this.type = type; + this.manufacturer = manufacturer; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get name(): string { + return this._name; + } + public set name(value: string) { + value = value.trim().toUpperCase(); + if (value.length === 0) + throw new DomainError('Branded medicine name cannot be empty'); + this._name = value; + } + public get type(): TypeModel { + return this._type; + } + public set type(value: TypeModel) { + this._type = value; + } + public get manufacturer(): ManufacturerModel { + return this._manufacturer; + } + public set manufacturer(value: ManufacturerModel) { + this._manufacturer = value; + } + public json(): { + id: string | undefined; + name: string; + type: any; + manufacturer: any; + } { + return { + id: this.id, + name: this.name, + type: this.type.json(), + manufacturer: this.manufacturer.json() + }; + } +} diff --git a/src/domain/model/brandedPresentation.model.ts b/src/domain/model/brandedPresentation.model.ts new file mode 100644 index 0000000..3ac9d65 --- /dev/null +++ b/src/domain/model/brandedPresentation.model.ts @@ -0,0 +1,83 @@ +import { Domain as DomainError } from '../error/domain.error'; +import { BrandedMedicine as BrandedMedicineModel } from './brandedMedicine.model'; +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from './activeComponentsByUnit.model'; +export class BrandedPresentation { + private _id!: string | undefined; + private _brandedMedicine!: BrandedMedicineModel; + private _activeComponentsByUnit!: ActiveComponentByUnitModel[]; + private _quantity!: number; + constructor( + id: string | undefined | null, + brandedMedicine: BrandedMedicineModel, + activeComponentsByUnit: ActiveComponentByUnitModel[], + quantity: number + ) { + this.id = id; + this.brandedMedicine = brandedMedicine; + this.activeComponentsByUnit = activeComponentsByUnit; + this.quantity = quantity; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get brandedMedicine(): BrandedMedicineModel { + return this._brandedMedicine; + } + public set brandedMedicine(value: BrandedMedicineModel) { + this._brandedMedicine = value; + } + public get activeComponentsByUnit(): ActiveComponentByUnitModel[] { + return this._activeComponentsByUnit; + } + public set activeComponentsByUnit(value: ActiveComponentByUnitModel[]) { + if (value.length === 0) { + throw new DomainError('Active components list cannot be empty'); + } + const uniqueIds = new Set(); + const uniqueNames = new Set(); + for (const item of value) { + const substanceId = item.substance.id || ''; + const substanceName = item.substance.name; + if (substanceId.length > 0) { + if (uniqueIds.has(substanceId)) { + throw new DomainError( + `Substance with ID '${substanceId}' is duplicated` + ); + } + uniqueIds.add(substanceId); + } + if (uniqueNames.has(substanceName)) { + throw new DomainError( + `Substance with name '${substanceName}' is duplicated` + ); + } + uniqueNames.add(substanceName); + } + this._activeComponentsByUnit = value; + } + public get quantity(): number { + return this._quantity; + } + public set quantity(value: number) { + this._quantity = value; + } + public json(): { + id: string | undefined; + brandedMedicine: any; + quantity: number; + activeComponentsByUnit: any[]; + } { + return { + id: this.id, + brandedMedicine: this.brandedMedicine.json(), + quantity: this.quantity, + activeComponentsByUnit: this.activeComponentsByUnit.map((item) => + item.json() + ) + }; + } +} diff --git a/src/domain/model/frecuency.model.ts b/src/domain/model/frecuency.model.ts new file mode 100644 index 0000000..e6ac379 --- /dev/null +++ b/src/domain/model/frecuency.model.ts @@ -0,0 +1,36 @@ +import { Domain as DomainError } from '../error/domain.error'; +export class Frecuency { + private _quantity!: number; + private _everyHours!: number; + constructor(quantity: number, everyHours: number = 24) { + this.quantity = quantity; + this.everyHours = everyHours; + } + public get quantity(): number { + return this._quantity; + } + public set quantity(value: number) { + if (value <= 0) + throw new DomainError( + 'Frecuency quantity cannot be less or equal than zero' + ); + this._quantity = value; + } + public get everyHours(): number { + return this._everyHours; + } + public set everyHours(value: number) { + if (value <= 0) + throw new DomainError('Frecuency time cannot be less or equal than zero'); + this._everyHours = value; + } + public json(): { + quantity: number; + everyHours: number; + } { + return { + quantity: this.quantity, + everyHours: this.everyHours + }; + } +} diff --git a/src/domain/model/manufacturer.model.ts b/src/domain/model/manufacturer.model.ts new file mode 100644 index 0000000..beb40f3 --- /dev/null +++ b/src/domain/model/manufacturer.model.ts @@ -0,0 +1,34 @@ +import { Domain as DomainError } from '../error/domain.error'; +export class Manufacturer { + private _id!: string | undefined; + private _name!: string; + constructor(id: string | undefined | null, name: string) { + this.id = id; + this.name = name; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get name(): string { + return this._name; + } + public set name(value: string) { + value = value.trim().toUpperCase(); + if (value.length === 0) + throw new DomainError('Manufacturer name cannot be empty'); + this._name = value; + } + public json(): { + id: string | undefined; + name: string; + } { + return { + id: this.id, + name: this.name + }; + } +} diff --git a/src/domain/model/prescription.model.ts b/src/domain/model/prescription.model.ts new file mode 100644 index 0000000..77f80d6 --- /dev/null +++ b/src/domain/model/prescription.model.ts @@ -0,0 +1,77 @@ +import { Frecuency as FrecuencyModel } from './frecuency.model'; +import { Type as TypeModel } from './type.model'; +export class Prescription { + public static buildJSONArray(prescriptions: Prescription[]): { + id: string | undefined; + type: any; + frecuency: any; + isSelfMedicated: boolean; + date: Date; + }[] { + return prescriptions.map((prescription) => prescription.json()); + } + private _id!: string | undefined; + private _type!: TypeModel; + private _frecuency!: FrecuencyModel; + private _isSelfMedicated!: boolean; + private _date!: Date; + constructor( + id: string | undefined | null, + type: TypeModel, + frecuency: FrecuencyModel, + isSelfMedicated: boolean, + date: Date | undefined = undefined + ) { + this.id = id; + this.type = type; + this.frecuency = frecuency; + this.isSelfMedicated = isSelfMedicated; + this.date = date || new Date(); + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get type(): TypeModel { + return this._type; + } + public set type(value: TypeModel) { + this._type = value; + } + public get frecuency(): FrecuencyModel { + return this._frecuency; + } + public set frecuency(value: FrecuencyModel) { + this._frecuency = value; + } + public get date(): Date { + return this._date; + } + public set date(value: Date) { + this._date = value; + } + public get isSelfMedicated(): boolean { + return this._isSelfMedicated; + } + public set isSelfMedicated(value: boolean) { + this._isSelfMedicated = value; + } + public json(): { + id: string | undefined; + type: any; + frecuency: any; + isSelfMedicated: boolean; + date: Date; + } { + return { + id: this.id, + type: this.type.json(), + frecuency: this.frecuency.json(), + isSelfMedicated: this.isSelfMedicated, + date: this.date + }; + } +} diff --git a/src/domain/model/purchase.model.ts b/src/domain/model/purchase.model.ts new file mode 100644 index 0000000..aa3cb88 --- /dev/null +++ b/src/domain/model/purchase.model.ts @@ -0,0 +1,88 @@ +import { BrandedPresentation as BrandedPresentationModel } from './brandedPresentation.model'; +export class Purchase { + public static buildJSONArray(purchases: Purchase[]): { + id: string | undefined; + date: Date; + brandedPresentation: any; + price: number; + discount: number; + shippingCost: number; + }[] { + return purchases.map((purchase) => purchase.json()); + } + private _id!: string | undefined; + private _date!: Date; + private _brandedPresentation!: BrandedPresentationModel; + private _price!: number; + private _discount!: number; + private _shippingCost!: number; + constructor( + id: string | undefined | null, + brandedPresentation: BrandedPresentationModel, + price: number, + discount: number, + shippingCost: number, + date: Date | undefined = undefined + ) { + this.id = id; + this.date = date || new Date(); + this.brandedPresentation = brandedPresentation; + this.price = price; + this.discount = discount; + this.shippingCost = shippingCost; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get date(): Date { + return this._date; + } + public set date(value: Date) { + this._date = value; + } + public get brandedPresentation(): BrandedPresentationModel { + return this._brandedPresentation; + } + public set brandedPresentation(value: BrandedPresentationModel) { + this._brandedPresentation = value; + } + public get price(): number { + return this._price; + } + public set price(value: number) { + this._price = value; + } + public get discount(): number { + return this._discount; + } + public set discount(value: number) { + this._discount = value; + } + public get shippingCost(): number { + return this._shippingCost; + } + public set shippingCost(value: number) { + this._shippingCost = value; + } + public json(): { + id: string | undefined; + date: Date; + brandedPresentation: any; + price: number; + discount: number; + shippingCost: number; + } { + return { + id: this.id, + date: this.date, + brandedPresentation: this.brandedPresentation.json(), + price: this.price, + discount: this.discount, + shippingCost: this.shippingCost + }; + } +} diff --git a/src/domain/model/stock.model.ts b/src/domain/model/stock.model.ts new file mode 100644 index 0000000..5942e12 --- /dev/null +++ b/src/domain/model/stock.model.ts @@ -0,0 +1,64 @@ +import { BrandedPresentation as BrandedPresentationModel } from './brandedPresentation.model'; +export class Stock { + public static buildJSONArray(stocks: Stock[]): { + id: string | undefined; + brandedPresentation: any; + quantity: number; + date: Date; + }[] { + return stocks.map((stock) => stock.json()); + } + private _id!: string | undefined; + private _brandedPresentation!: BrandedPresentationModel; + private _quantity!: number; + private _date!: Date; + constructor( + id: string | undefined | null, + brandedPresentation: BrandedPresentationModel, + quantity: number, + date: Date | undefined = undefined + ) { + this.id = id; + this.brandedPresentation = brandedPresentation; + this.quantity = quantity; + this.date = date || new Date(); + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get brandedPresentation(): BrandedPresentationModel { + return this._brandedPresentation; + } + public set brandedPresentation(value: BrandedPresentationModel) { + this._brandedPresentation = value; + } + public get quantity(): number { + return this._quantity; + } + public set quantity(value: number) { + this._quantity = value; + } + public get date(): Date { + return this._date; + } + public set date(value: Date) { + this._date = value; + } + public json(): { + id: string | undefined; + brandedPresentation: any; + quantity: number; + date: Date; + } { + return { + id: this.id, + brandedPresentation: this.brandedPresentation.json(), + quantity: this.quantity, + date: this.date + }; + } +} diff --git a/src/domain/model/substance.model.ts b/src/domain/model/substance.model.ts new file mode 100644 index 0000000..6a6b10f --- /dev/null +++ b/src/domain/model/substance.model.ts @@ -0,0 +1,34 @@ +import { Domain as DomainError } from '../error/domain.error'; +export class Substance { + private _id!: string | undefined; + private _name!: string; + constructor(id: string | undefined | null, name: string) { + this.id = id; + this.name = name; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get name(): string { + return this._name; + } + public set name(value: string) { + value = value.trim().toUpperCase(); + if (value.length === 0) + throw new DomainError('Substance name cannot be empty'); + this._name = value; + } + public json(): { + id: string | undefined; + name: string; + } { + return { + id: this.id, + name: this.name + }; + } +} diff --git a/src/domain/model/type.model.ts b/src/domain/model/type.model.ts new file mode 100644 index 0000000..d0de775 --- /dev/null +++ b/src/domain/model/type.model.ts @@ -0,0 +1,33 @@ +import { Domain as DomainError } from '../error/domain.error'; +export class Type { + private _id!: string | undefined; + private _name!: string; + constructor(id: string | undefined | null, name: string) { + this.id = id; + this.name = name; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get name(): string { + return this._name; + } + public set name(value: string) { + value = value.trim().toUpperCase(); + if (value.length === 0) throw new DomainError('Type name cannot be empty'); + this._name = value; + } + public json(): { + id: string | undefined; + name: string; + } { + return { + id: this.id, + name: this.name + }; + } +} diff --git a/src/domain/model/user.model.ts b/src/domain/model/user.model.ts new file mode 100644 index 0000000..6779aaf --- /dev/null +++ b/src/domain/model/user.model.ts @@ -0,0 +1,72 @@ +import { Domain as DomainError } from '../error/domain.error'; +import { Prescription as PrescriptionModel } from './prescription.model'; +import { Purchase as PurchaseModel } from './purchase.model'; +import { Stock as StockModel } from './stock.model'; +export class User { + private _id!: string | undefined; + private _name!: string; + private _prescriptions!: PrescriptionModel[]; + private _purchases!: PurchaseModel[]; + private _stocks!: StockModel[]; + constructor( + id: string | undefined | null, + name: string, + prescriptions: PrescriptionModel[], + purchases: PurchaseModel[], + stocks: StockModel[] + ) { + this.id = id; + this.name = name; + this.prescriptions = prescriptions; + this.purchases = purchases; + this.stocks = stocks; + } + public get id(): string | undefined { + return this._id; + } + public set id(value: string | undefined | null) { + value = (value || '').trim().toLowerCase(); + this._id = value === '' ? undefined : value; + } + public get name(): string { + return this._name; + } + public set name(value: string) { + value = value.trim().toUpperCase(); + if (value.length === 0) throw new DomainError('User name cannot be empty'); + this._name = value; + } + public get prescriptions(): PrescriptionModel[] { + return this._prescriptions; + } + public set prescriptions(value: PrescriptionModel[]) { + this._prescriptions = value; + } + public get purchases(): PurchaseModel[] { + return this._purchases; + } + public set purchases(value: PurchaseModel[]) { + this._purchases = value; + } + public get stocks(): StockModel[] { + return this._stocks; + } + public set stocks(value: StockModel[]) { + this._stocks = value; + } + public json(): { + id: string | undefined; + name: string; + prescriptions: any[]; + purchases: any[]; + stocks: any[]; + } { + return { + id: this.id, + name: this.name, + prescriptions: PrescriptionModel.buildJSONArray(this.prescriptions), + purchases: PurchaseModel.buildJSONArray(this.purchases), + stocks: StockModel.buildJSONArray(this.stocks) + }; + } +} diff --git a/test/domain/model/activeComponentsByUnit.model.utest.ts b/test/domain/model/activeComponentsByUnit.model.utest.ts new file mode 100644 index 0000000..5411f07 --- /dev/null +++ b/test/domain/model/activeComponentsByUnit.model.utest.ts @@ -0,0 +1,28 @@ +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from '../../../src/domain/model/activeComponentsByUnit.model'; +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +const substance1: SubstanceModel = new SubstanceModel('id', 'NAME'); +describe('Class ActiveComponentByUnit Model', () => { + it('Happy Path 1', async () => { + const activeComponentsByUnit: ActiveComponentByUnitModel = + new ActiveComponentByUnitModel(1, substance1); + expect(activeComponentsByUnit.grams).toBe(1); + expect(activeComponentsByUnit.substance.json()).toEqual(substance1.json()); + expect(activeComponentsByUnit.json()).toEqual({ + grams: 1, + substance: substance1.json() + }); + }); + it('Error - Invalid grams', async () => { + let errorMsg: string = ''; + try { + new ActiveComponentByUnitModel(0, substance1); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe( + 'Active component by unit grams cannot be less or equal than zero' + ); + }); +}); diff --git a/test/domain/model/brandedMedicine.model.utest.ts b/test/domain/model/brandedMedicine.model.utest.ts new file mode 100644 index 0000000..10e7bbd --- /dev/null +++ b/test/domain/model/brandedMedicine.model.utest.ts @@ -0,0 +1,53 @@ +import { BrandedMedicine as BrandedMedicineModel } from '../../../src/domain/model/brandedMedicine.model'; +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +const manufacturer: ManufacturerModel = new ManufacturerModel('id', 'NAME'); +const type: TypeModel = new TypeModel('id', 'NAME'); +describe('Class BrandedMedicine Model', () => { + it('Happy Path 1', async () => { + const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + ' ID ', + ' name ', + type, + manufacturer + ); + expect(brandedMedicine.id).toBe('id'); + expect(brandedMedicine.name).toBe('NAME'); + expect(brandedMedicine.type.json()).toEqual(type.json()); + expect(brandedMedicine.manufacturer.json()).toEqual(manufacturer.json()); + expect(brandedMedicine.json()).toEqual({ + id: 'id', + name: 'NAME', + type: type.json(), + manufacturer: manufacturer.json() + }); + }); + it('Happy Path 2', async () => { + const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + undefined, + ' name ', + type, + manufacturer + ); + expect(brandedMedicine.id).toBeUndefined(); + expect(brandedMedicine.name).toBe('NAME'); + expect(brandedMedicine.type.json()).toEqual(type.json()); + expect(brandedMedicine.manufacturer.json()).toEqual(manufacturer.json()); + expect(brandedMedicine.json()).toEqual({ + name: 'NAME', + type: type.json(), + manufacturer: manufacturer.json() + }); + }); + it('Error - Empty Name', async () => { + let errorMsg: string = ''; + try { + new BrandedMedicineModel(' ID ', ' ', type, manufacturer); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Branded medicine name cannot be empty'); + }); +}); diff --git a/test/domain/model/brandedPresentation.model.utest.ts b/test/domain/model/brandedPresentation.model.utest.ts new file mode 100644 index 0000000..716c12d --- /dev/null +++ b/test/domain/model/brandedPresentation.model.utest.ts @@ -0,0 +1,138 @@ +import { BrandedMedicine as BrandedMedicineModel } from '../../../src/domain/model/brandedMedicine.model'; +import { BrandedPresentation as BrandedPresentationModel } from '../../../src/domain/model/brandedPresentation.model'; +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from '../../../src/domain/model/activeComponentsByUnit.model'; +const manufacturer: ManufacturerModel = new ManufacturerModel('id', 'NAME'); +const substance1: SubstanceModel = new SubstanceModel('id', 'NAME'); +const substance2: SubstanceModel = new SubstanceModel(undefined, 'NAME'); +const type: TypeModel = new TypeModel('id', 'NAME'); +const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + 'id', + 'NAME', + type, + manufacturer +); +describe('Class BrandedPresentation Model', () => { + it('Happy Path 1', async () => { + const brandedPresentation: BrandedPresentationModel = + new BrandedPresentationModel( + 'id', + brandedMedicine, + [new ActiveComponentByUnitModel(1, substance1)], + 1 + ); + expect(brandedPresentation.id).toBe('id'); + expect(brandedPresentation.brandedMedicine.json()).toEqual( + brandedMedicine.json() + ); + expect( + brandedPresentation.activeComponentsByUnit.map((item) => item.json()) + ).toEqual([new ActiveComponentByUnitModel(1, substance1).json()]); + expect(brandedPresentation.quantity).toBe(1); + expect(brandedPresentation.json()).toEqual({ + id: 'id', + brandedMedicine: brandedMedicine.json(), + quantity: 1, + activeComponentsByUnit: [ + new ActiveComponentByUnitModel(1, substance1).json() + ] + }); + }); + it('Happy Path 2', async () => { + const brandedPresentation: BrandedPresentationModel = + new BrandedPresentationModel( + undefined, + brandedMedicine, + [new ActiveComponentByUnitModel(1, substance2)], + 1 + ); + expect(brandedPresentation.id).toBeUndefined(); + expect(brandedPresentation.brandedMedicine.json()).toEqual( + brandedMedicine.json() + ); + expect(brandedPresentation.activeComponentsByUnit).toEqual([ + new ActiveComponentByUnitModel(1, substance2) + ]); + expect(brandedPresentation.quantity).toBe(1); + expect(brandedPresentation.json()).toEqual({ + brandedMedicine: brandedMedicine.json(), + quantity: 1, + activeComponentsByUnit: [ + new ActiveComponentByUnitModel(1, substance2).json() + ] + }); + }); + it('Error - Empty active components list', async () => { + let errorMsg: string = ''; + try { + new BrandedPresentationModel('id', brandedMedicine, [], 1); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Active components list cannot be empty'); + }); + it('Error - Duplicated substance IDs', async () => { + let errorMsg: string = ''; + try { + new BrandedPresentationModel( + 'id', + brandedMedicine, + [ + new ActiveComponentByUnitModel(1, new SubstanceModel('id1', 'NAME1')), + new ActiveComponentByUnitModel(1, new SubstanceModel('id1', 'NAME2')), + new ActiveComponentByUnitModel( + 1, + new SubstanceModel(undefined, 'NAME3') + ) + ], + 1 + ); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe("Substance with ID 'id1' is duplicated"); + }); + it('Error - Duplicated substance names', async () => { + let errorMsg: string = ''; + try { + new BrandedPresentationModel( + 'id', + brandedMedicine, + [ + new ActiveComponentByUnitModel(1, new SubstanceModel('id1', 'NAME1')), + new ActiveComponentByUnitModel(1, new SubstanceModel('id2', 'NAME1')) + ], + 1 + ); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe("Substance with name 'NAME1' is duplicated"); + }); + it('Error - Grams must be greater than zero', async () => { + let errorMsg: string = ''; + try { + new BrandedPresentationModel( + 'id', + brandedMedicine, + [new ActiveComponentByUnitModel(0, new SubstanceModel('id1', 'NAME1'))], + 1 + ); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe( + 'Active component by unit grams cannot be less or equal than zero' + ); + }); +}); diff --git a/test/domain/model/frecuency.model.utest.ts b/test/domain/model/frecuency.model.utest.ts new file mode 100644 index 0000000..ea787fb --- /dev/null +++ b/test/domain/model/frecuency.model.utest.ts @@ -0,0 +1,39 @@ +import { Frecuency as FrecuencyModel } from '../../../src/domain/model/frecuency.model'; +describe('Class Frecuency Model', () => { + it('Happy Path 1', async () => { + const frecuency: FrecuencyModel = new FrecuencyModel(1, 1); + expect(frecuency.quantity).toBe(1); + expect(frecuency.everyHours).toBe(1); + expect(frecuency.json()).toEqual({ quantity: 1, everyHours: 1 }); + }); + it('Happy Path 2', async () => { + const frecuency: FrecuencyModel = new FrecuencyModel(1); + expect(frecuency.quantity).toBe(1); + expect(frecuency.everyHours).toBe(24); + expect(frecuency.json()).toEqual({ quantity: 1, everyHours: 24 }); + }); + it('Error - Invalid quantity', async () => { + let errorMsg: string = ''; + try { + new FrecuencyModel(0, 1); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe( + 'Frecuency quantity cannot be less or equal than zero' + ); + }); + it('Error - Invalid everyHours', async () => { + let errorMsg: string = ''; + try { + new FrecuencyModel(1, 0); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Frecuency time cannot be less or equal than zero'); + }); +}); diff --git a/test/domain/model/manufacturer.model.utest.ts b/test/domain/model/manufacturer.model.utest.ts new file mode 100644 index 0000000..5948813 --- /dev/null +++ b/test/domain/model/manufacturer.model.utest.ts @@ -0,0 +1,32 @@ +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +describe('Class Manufacturer Model', () => { + it('Happy Path 1', async () => { + const manufacturer: ManufacturerModel = new ManufacturerModel( + ' ID ', + ' name ' + ); + expect(manufacturer.id).toBe('id'); + expect(manufacturer.name).toBe('NAME'); + expect(manufacturer.json()).toEqual({ id: 'id', name: 'NAME' }); + }); + it('Happy Path 2', async () => { + const manufacturer: ManufacturerModel = new ManufacturerModel( + undefined, + ' name ' + ); + expect(manufacturer.id).toBeUndefined(); + expect(manufacturer.name).toBe('NAME'); + expect(manufacturer.json()).toEqual({ name: 'NAME' }); + }); + it('Error - Empty Name', async () => { + let errorMsg: string = ''; + try { + new ManufacturerModel(' ID ', ' '); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Manufacturer name cannot be empty'); + }); +}); diff --git a/test/domain/model/prescription.model.utest.ts b/test/domain/model/prescription.model.utest.ts new file mode 100644 index 0000000..565e9d1 --- /dev/null +++ b/test/domain/model/prescription.model.utest.ts @@ -0,0 +1,59 @@ +import { Frecuency as FrecuencyModel } from '../../../src/domain/model/frecuency.model'; +import { Prescription as PrescriptionModel } from '../../../src/domain/model/prescription.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +const type: TypeModel = new TypeModel('id', 'NAME'); +const frecuency: FrecuencyModel = new FrecuencyModel(1, 1); +const date: Date = new Date(); +describe('Class Prescription Model', () => { + it('Happy Path 1', async () => { + const prescription: PrescriptionModel = new PrescriptionModel( + ' ID ', + type, + frecuency, + true, + date + ); + expect(prescription.id).toBe('id'); + expect(prescription.type).toBe(type); + expect(prescription.frecuency).toBe(frecuency); + expect(prescription.isSelfMedicated).toBeTruthy(); + expect(prescription.date).toBe(date); + expect(prescription.json()).toEqual({ + id: 'id', + type: type.json(), + frecuency: frecuency.json(), + isSelfMedicated: true, + date: date + }); + }); + it('Happy Path 2', async () => { + const prescription: PrescriptionModel = new PrescriptionModel( + undefined, + type, + frecuency, + true + ); + expect(prescription.id).toBeUndefined(); + expect(prescription.type).toBe(type); + expect(prescription.frecuency).toBe(frecuency); + expect(prescription.isSelfMedicated).toBeTruthy(); + expect(prescription.date).not.toBeUndefined(); + expect(typeof prescription.date).toBe('object'); + }); + it('Happy Path 3', async () => { + const prescriptions: PrescriptionModel[] = [ + new PrescriptionModel(' ID ', type, frecuency, true, date) + ]; + const jsonResult: any[] = PrescriptionModel.buildJSONArray(prescriptions); + expect(jsonResult.length).toBe(1); + expect(jsonResult).toEqual([ + { + id: 'id', + type: type.json(), + frecuency: frecuency.json(), + isSelfMedicated: true, + date: date + } + ]); + }); +}); diff --git a/test/domain/model/purchase.model.utest.ts b/test/domain/model/purchase.model.utest.ts new file mode 100644 index 0000000..88e6206 --- /dev/null +++ b/test/domain/model/purchase.model.utest.ts @@ -0,0 +1,86 @@ +import { BrandedMedicine as BrandedMedicineModel } from '../../../src/domain/model/brandedMedicine.model'; +import { BrandedPresentation as BrandedPresentationModel } from '../../../src/domain/model/brandedPresentation.model'; +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +import { Purchase as PurchaseModel } from '../../../src/domain/model/purchase.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from '../../../src/domain/model/activeComponentsByUnit.model'; +const manufacturer: ManufacturerModel = new ManufacturerModel('id', 'NAME'); +const substance1: SubstanceModel = new SubstanceModel('id', 'NAME'); +const type: TypeModel = new TypeModel('id', 'NAME'); +const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + 'id', + 'NAME', + type, + manufacturer +); +const brandedPresentation: BrandedPresentationModel = + new BrandedPresentationModel( + 'id', + brandedMedicine, + [new ActiveComponentByUnitModel(1, substance1)], + 1 + ); +describe('Class Purchase Model', () => { + it('Happy Path 1', async () => { + const date: Date = new Date(); + const purchase: PurchaseModel = new PurchaseModel( + ' ID ', + brandedPresentation, + 1, + 1, + 1, + date + ); + expect(purchase.id).toBe('id'); + expect(purchase.brandedPresentation.json()).toEqual( + brandedPresentation.json() + ); + expect(purchase.price).toBe(1); + expect(purchase.discount).toBe(1); + expect(purchase.shippingCost).toBe(1); + expect(purchase.date).toBe(date); + expect(purchase.json()).toEqual({ + id: 'id', + date: date, + brandedPresentation: brandedPresentation.json(), + price: 1, + discount: 1, + shippingCost: 1 + }); + }); + it('Happy Path 2', async () => { + const purchase: PurchaseModel = new PurchaseModel( + null, + brandedPresentation, + 1, + 1, + 1 + ); + expect(purchase.id).toBeUndefined(); + expect(purchase.brandedPresentation.json()).toEqual( + brandedPresentation.json() + ); + expect(purchase.price).toBe(1); + expect(purchase.discount).toBe(1); + expect(purchase.shippingCost).toBe(1); + expect(purchase.date).not.toBeUndefined(); + expect(typeof purchase.date).toBe('object'); + }); + it('Happy Path 3', async () => { + const date: Date = new Date(); + const purchases: PurchaseModel[] = [ + new PurchaseModel(' ID ', brandedPresentation, 1, 1, 1, date) + ]; + const jsonResult: any[] = PurchaseModel.buildJSONArray(purchases); + expect(jsonResult.length).toBe(1); + expect(jsonResult[0]).toEqual({ + id: 'id', + date: date, + brandedPresentation: brandedPresentation.json(), + price: 1, + discount: 1, + shippingCost: 1 + }); + }); +}); diff --git a/test/domain/model/stock.model.utest.ts b/test/domain/model/stock.model.utest.ts new file mode 100644 index 0000000..80d7185 --- /dev/null +++ b/test/domain/model/stock.model.utest.ts @@ -0,0 +1,71 @@ +import { BrandedMedicine as BrandedMedicineModel } from '../../../src/domain/model/brandedMedicine.model'; +import { BrandedPresentation as BrandedPresentationModel } from '../../../src/domain/model/brandedPresentation.model'; +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +import { Stock as StockModel } from '../../../src/domain/model/stock.model'; +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from '../../../src/domain/model/activeComponentsByUnit.model'; +const date: Date = new Date(); +const type: TypeModel = new TypeModel('id', 'NAME'); +const manufacturer: ManufacturerModel = new ManufacturerModel('id', 'NAME'); +const substance: SubstanceModel = new SubstanceModel('id', 'NAME'); +const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + 'id', + 'NAME', + type, + manufacturer +); +const brandedPresentation: BrandedPresentationModel = + new BrandedPresentationModel( + 'id', + brandedMedicine, + [new ActiveComponentByUnitModel(1, substance)], + 1 + ); +describe('Class Stock Model', () => { + it('Happy Path 1', async () => { + const stock: StockModel = new StockModel( + 'id', + brandedPresentation, + 1, + date + ); + expect(stock.id).toBe('id'); + expect(stock.brandedPresentation.json()).toEqual( + brandedPresentation.json() + ); + expect(stock.quantity).toBe(1); + expect(stock.date).toBe(date); + expect(stock.json()).toEqual({ + id: 'id', + brandedPresentation: brandedPresentation.json(), + quantity: 1, + date: date + }); + }); + it('Happy Path 2', async () => { + const stock: StockModel = new StockModel(undefined, brandedPresentation, 1); + expect(stock.id).toBeUndefined(); + expect(stock.brandedPresentation.json()).toEqual( + brandedPresentation.json() + ); + expect(stock.quantity).toBe(1); + expect(stock.date).not.toBeUndefined(); + expect(typeof stock.date).toBe('object'); + }); + it('Happy Path 3', async () => { + const stocks: StockModel[] = [ + new StockModel('id', brandedPresentation, 1, date) + ]; + const jsonResult: any[] = StockModel.buildJSONArray(stocks); + expect(jsonResult.length).toBe(1); + expect(jsonResult).toEqual([ + { + id: 'id', + brandedPresentation: brandedPresentation.json(), + quantity: 1, + date: date + } + ]); + }); +}); diff --git a/test/domain/model/substance.model.utest.ts b/test/domain/model/substance.model.utest.ts new file mode 100644 index 0000000..5d055a0 --- /dev/null +++ b/test/domain/model/substance.model.utest.ts @@ -0,0 +1,26 @@ +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +describe('Class Substance Model', () => { + it('Happy Path 1', async () => { + const substance: SubstanceModel = new SubstanceModel(' ID ', ' name '); + expect(substance.id).toBe('id'); + expect(substance.name).toBe('NAME'); + expect(substance.json()).toEqual({ id: 'id', name: 'NAME' }); + }); + it('Happy Path 2', async () => { + const substance: SubstanceModel = new SubstanceModel(undefined, ' name '); + expect(substance.id).toBeUndefined(); + expect(substance.name).toBe('NAME'); + expect(substance.json()).toEqual({ name: 'NAME' }); + }); + it('Error - Empty Name', async () => { + let errorMsg: string = ''; + try { + new SubstanceModel(' ID ', ' '); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Substance name cannot be empty'); + }); +}); diff --git a/test/domain/model/type.model.utest.ts b/test/domain/model/type.model.utest.ts new file mode 100644 index 0000000..78d3556 --- /dev/null +++ b/test/domain/model/type.model.utest.ts @@ -0,0 +1,26 @@ +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +describe('Class Type Model', () => { + it('Happy Path 1', async () => { + const type: TypeModel = new TypeModel(' ID ', ' name '); + expect(type.id).toBe('id'); + expect(type.name).toBe('NAME'); + expect(type.json()).toEqual({ id: 'id', name: 'NAME' }); + }); + it('Happy Path 2', async () => { + const type: TypeModel = new TypeModel(undefined, ' name '); + expect(type.id).toBeUndefined(); + expect(type.name).toBe('NAME'); + expect(type.json()).toEqual({ name: 'NAME' }); + }); + it('Error - Empty Name', async () => { + let errorMsg: string = ''; + try { + new TypeModel(' ID ', ' '); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('Type name cannot be empty'); + }); +}); diff --git a/test/domain/model/user.model.utest.ts b/test/domain/model/user.model.utest.ts new file mode 100644 index 0000000..56356a0 --- /dev/null +++ b/test/domain/model/user.model.utest.ts @@ -0,0 +1,104 @@ +import { ActiveComponentByUnit as ActiveComponentByUnitModel } from '../../../src/domain/model/activeComponentsByUnit.model'; +import { BrandedMedicine as BrandedMedicineModel } from '../../../src/domain/model/brandedMedicine.model'; +import { BrandedPresentation as BrandedPresentationModel } from '../../../src/domain/model/brandedPresentation.model'; +import { Frecuency as FrecuencyModel } from '../../../src/domain/model/frecuency.model'; +import { Manufacturer as ManufacturerModel } from '../../../src/domain/model/manufacturer.model'; +import { Prescription as PrescriptionModel } from '../../../src/domain/model/prescription.model'; +import { Purchase as PurchaseModel } from '../../../src/domain/model/purchase.model'; +import { Stock as StockModel } from '../../../src/domain/model/stock.model'; +import { Substance as SubstanceModel } from '../../../src/domain/model/substance.model'; +import { Type as TypeModel } from '../../../src/domain/model/type.model'; +import { User as UserModel } from '../../../src/domain/model/user.model'; +describe('Class User Model', () => { + it('Happy Path 1', async () => { + const User: UserModel = new UserModel(' ID ', ' name ', [], [], []); + expect(User.id).toBe('id'); + expect(User.name).toBe('NAME'); + expect(User.json()).toEqual({ + id: 'id', + name: 'NAME', + prescriptions: [], + purchases: [], + stocks: [] + }); + }); + it('Happy Path 2', async () => { + const User: UserModel = new UserModel(undefined, ' name ', [], [], []); + expect(User.id).toBeUndefined(); + expect(User.name).toBe('NAME'); + expect(User.json()).toEqual({ + name: 'NAME', + prescriptions: [], + purchases: [], + stocks: [] + }); + }); + it('Happy Path 3', async () => { + const date: Date = new Date(); + const frecuency: FrecuencyModel = new FrecuencyModel(1, 1); + const manufacturer: ManufacturerModel = new ManufacturerModel('id', 'NAME'); + const substance: SubstanceModel = new SubstanceModel('id', 'NAME'); + const type: TypeModel = new TypeModel('id', 'NAME'); + const brandedMedicine: BrandedMedicineModel = new BrandedMedicineModel( + 'id', + 'NAME', + type, + manufacturer + ); + const brandedPresentation: BrandedPresentationModel = + new BrandedPresentationModel( + 'id', + brandedMedicine, + [new ActiveComponentByUnitModel(1, substance)], + 1 + ); + const prescription: PrescriptionModel = new PrescriptionModel( + ' ID ', + type, + frecuency, + true, + date + ); + const purchase: PurchaseModel = new PurchaseModel( + ' ID ', + brandedPresentation, + 1, + 1, + 1, + date + ); + const stock: StockModel = new StockModel( + 'id', + brandedPresentation, + 1, + date + ); + const user: UserModel = new UserModel( + ' ID ', + ' name ', + [prescription], + [purchase], + [stock] + ); + expect(user.id).toBe('id'); + expect(user.name).toBe('NAME'); + expect(user.json()).toEqual({ + id: 'id', + name: 'NAME', + prescriptions: PrescriptionModel.buildJSONArray([prescription]), + purchases: PurchaseModel.buildJSONArray([purchase]), + stocks: StockModel.buildJSONArray([stock]) + }); + }); + it('Error - Empty Name', async () => { + let errorMsg: string = ''; + try { + new UserModel(' ID ', ' ', [], [], []); + } catch (error) { + if (error instanceof Error) { + errorMsg = error.message; + } + } + expect(errorMsg).toBe('User name cannot be empty'); + }); +});