PageSourceSearch

https://thaineqas.com/js/common/user.js

js thaineqas.com collected 2026-10-09 00:35:46 UTC 28,290 bytes, 997 lines download raw bytes

1import * as gql from './graphql.js';
2import * as common from './common.js';
3import * as auth from './auth.js';
4import { getConfig } from './config.js';
5
6import { getTracking, addTracking } from './tracking.js';
7import { getReceipt, addReceipt, addPayment } from './payment.js';
8import { getCertificate, createCertificate } from './certificate.js';
9
10// getLabstatus
11// =================
12// get the list of the Laboratory status
13export async function getLabStatus()
14{
15    let query = `
16    query ListLabStatus {
17        getLabStatus {
18            type_id
19            type_code
20            type_name
21        }
22    }`;
23
24    try {
25		let ret = await gql.sendGQL('query', query);
26        let result = {};
27		if(ret['status'] == 'success') {
28			let labstatus_data = ret['response']['data']['getLabStatus'];
29            if(labstatus_data && labstatus_data.length > 0) {
30                for(let data_each of labstatus_data) {
31                    let { type_id, type_name } = data_each;
32                    result[type_id] = data_each;
33                }
34                
35			    return result;
36            }
37		}
38	} catch(error) {
39		console.error(error);
40	}
41   
42	return null;
43}
44
45// acceptPdpa
46// =================
47// allow the user to accept the PDPA.
48export async function acceptPdpa(participant_code, accept = "")
49{
50    let query = `mutation {
51        acceptPDPA(participant_code: "${ participant_code }", accept_pdpa: "${ encodeURI(accept) }")
52    }`;
53
54    try {
55		let ret = await gql.sendMutation({ query });
56
57		if(ret['status'] == 'success') {
58			let result = ret['response']['data']['acceptPDPA'];
59			return result;
60		}
61	} catch(error) {
62		console.error(error);
63	}
64
65    return null;
66}
67
68// archiveMember
69// ================
70// archive old data into the database.
71export async function archiveMember(participant_code)
72{
73    let query = `mutation {
74        archiveMember(participant_code: "${ participant_code }") {
75            participant_code
76            participant_id
77            archived_data {
78                participant_id
79                username
80                name
81                rank
82                lab_name
83                hos_name
84                address
85                district
86                tambon
87                province
88                postcode
89                registered_year
90                registered_date
91                tel
92                email
93                num_pt
94                num_aptt
95                num_inr
96                num_factorviii
97            }
98        }
99    }`;
100
101    try {
102		let ret = await gql.sendMutation({ query });
103
104		if(ret['status'] == 'success') {
105			let member_data = ret['response']['data']['archiveMember'];
106			return member_data;
107		}
108	} catch(error) {
109		console.error(error);
110	}
111
112    return null;
113}
114
115/*  
116    getUser
117    =============
118    get the user data by using participant_code
119*/
120export async function getUser(participant_code)
121{
122    let find_data = '';
123
124    let query = `query {
125                getUser(participant_code: "${ participant_code }") {
126                    participant_code
127                    participant_id
128                    email
129                    name
130                    user_type {
131                        type_id
132                        type_code
133                        type_name
134                    }
135                    user_status {
136                        type_id
137                        type_code
138                        type_name
139                    }
140                    lab_status {
141                        type_id
142                        type_code
143                        type_name
144                    }
145                    testing {
146                        testing_id
147                        year
148                        testing_type
149                    }
150                    tracking {
151                        tracking_id
152                        sent_year
153                        receipt_tracking
154                        first_tracking
155                        second_tracking
156                        third_tracking
157                    }
158                    archived_data {
159                        participant_id
160                        username
161                        name
162                        rank
163                        lab_name
164                        hos_name
165                        address
166                        district
167                        tambon
168                        province
169                        postcode
170                        registered_year
171                        registered_date
172                        tel
173                        email
174                        num_pt
175                        num_aptt
176                        num_inr
177                        num_factorviii
178                    }
179                    accept_pdpa
180                }
181            }`;
182	
183	try {
184		let ret = await gql.sendGQL('query', query);
185
186		if(ret['status'] == 'success') {
187			let loggedin_data = ret['response']['data']['isloggedin'];
188			return (loggedin_data) ? loggedin_data : { 'status': 'notloggedin' };
189		}
190	} catch(error) {
191		console.error(error);
192	}
193   
194	return null;
195}
196
197
198/*  
199    getTesting
200    =============
201    get the user data to show what user want to subscribe by using participant_code
202*/
203export async function getTesting(participant_code)
204{
205    let query = `query {
206                getPayment(participant_code: "${ participant_code }") {
207                    year
208                    testing_type
209                }
210            }`;
211	
212	try {
213		let ret = await gql.sendGQL('query', query);
214
215		if(ret['status'] == 'success') {
216			let payment = ret['response']['data']['getPayment'];
217            if(payment && payment.legth > 0)
218                payment = payment.sort((a,b) => parseInt(a['year']) - parseInt(b['year']));
219			return payment;
220		}
221	} catch(error) {
222		console.error(error);
223	}
224   
225	return null;
226}
227
228/* getUserData */
229// ==========================
230/* Allow us to find the user data via Participant Code, Participant ID and E-Mail */
231export async function getUserData(config, isadmin = false)
232{
233    if(!config.hasOwnProperty('participant_code') && 
234       !config.hasOwnProperty('participant_id') &&
235       !config.hasOwnProperty('email'))
236        return null;
237    
238    let query_txt = [];
239    for(let [key, value] of Object.entries(config)) {
240        if(typeof value != "string")
241            query_txt.push(`${ key }: ${ value }`);
242        else
243            query_txt.push(`${ key }: "${ common.escapeGraphQL(value) }"`);
244    }
245
246    let query = `query {
247        getUser(${ query_txt.join(',') }) {
248            participant_code
249            participant_id
250            username
251            name
252            lab_name
253            hos_name
254            address
255            district
256            tambon
257            province
258            postcode
259            tel
260            email
261            accept_pdpa
262            user_type {
263                type_id
264                type_code
265                type_name
266            }
267            user_status {
268                type_id
269                type_code
270                type_name
271            }
272            lab_status {
273                type_id
274                type_code
275                type_name
276            }
277            survey_data {
278                sent_id
279                participant_code
280                lab_code
281                sent_date
282                test_date
283                result_date
284                spec_condition
285                condition_comment
286                amt_person
287                chng_lot
288                sodiumcitrate_name
289                survey {
290                    survey_id
291                    survey_no
292                    survey_time
293                    survey_year
294                }
295                person {
296                    person_id
297                    person_name
298                    person_tel
299                    person_mobile
300                }
301                pt_data	{
302                    pt_data_id
303                    pt_isi
304                    pt_reflow
305                    pt_refhigh
306                    pt_lot_no
307                    divide_value
308                    mean_pt
309                    pt_sample_1
310                    pt_sample_1_comment
311                    ratio_pt1_assessment
312                    ratio_pt1_isblunder
313                    pt_sample_2
314                    pt_sample_2_comment
315                    ratio_pt2_assessment
316                    ratio_pt2_isblunder
317                    pt_sample_3
318                    pt_sample_3_comment
319                    ratio_ptsample3
320                    ratio_pt3_assessment
321                    ratio_pt3_isblunder
322                    ratio_pt3_median
323                    ratio_pt3_performance
324                    ratio_pt3_deviation
325                    nw_ratio_pt3
326                    cment_isi
327                    pt_fcodesample1
328                    pt_fcodesample2
329                    pt_fcodesample3
330                }
331                aptt_data {
332                    aptt_data_id
333                    aptt_reflow
334                    aptt_refhigh
335                    aptt_lot_no
336                    mean_aptt
337                    aptt_sample1
338                    aptt_sample1_comment
339                    aptt_sample2
340                    aptt_sample2_comment
341                    aptt_sample3
342                    aptt_sample3_comment
343                    ratio_apttsample1
344                    ratio_apttsample2
345                    ratio_apttsample3
346                    aptt1_assessment
347                    aptt1_isblunder
348                    aptt1_median
349                    aptt1_deviation
350                    aptt1_performance
351                    aptt2_assessment
352                    aptt2_isblunder
353                    aptt2_median
354                    aptt2_deviation
355                    aptt2_performance
356                    aptt3_assessment
357                    aptt3_isblunder
358                    aptt3_median
359                    aptt3_deviation
360                    aptt3_performance
361                    aptt_fcodesample1
362                    aptt_fcodesample2
363                    aptt_fcodesample3
364                }
365                inr_data {
366                    inr_data_id
367                    inr_sample1
368                    inr1_comment
369                    inr_sample2
370                    inr2_comment 
371                    inr1_median
372                    inr1_deviation
373                    inr1_assessment
374                    inr1_isblunder
375                    inr1_performance
376                    inr2_median
377                    inr2_deviation
378                    inr2_assessment
379                    inr2_isblunder
380                    inr2_performance
381                    nw_inr1
382                    nw_inr2
383                }
384                factorviii_data {
385                    factorviii_data_id
386                    factorviii_sample_1
387                    factorviii_sample_1_comment
388                    factorviii_fcodesample1
389                    exam_type
390                    dilution
391                    aptt_lot_no
392                    factorreflow
393                    factorrefhigh
394                    factorref_plasma
395                    factorref_plasma_lot_no
396                    factordef_plasma
397                    factorref_plasma_lot_no
398                    source
399                    source_comment
400                    volunteer_num
401                    standard_curve
402                    factorviii_sample_1
403                    factorviii_sample_1_comment
404                    factorviii_fcodesample1
405                    factorviii_assessment
406                    factorviii_isblunder
407                    standard_uncertainty
408                    grading
409                    rank_grading
410                }
411                machine_info {
412                    machine_code
413                    machine_name
414                    machine_comment
415                }
416                pt_info {
417                    pt_code
418                    pt_name
419                    pt_comment
420                }
421                aptt_info  {
422                    aptt_code
423                    aptt_name
424                    aptt_comment
425                }
426                d_info {
427                    d_code
428                    d_name
429                }
430                e_info  {
431                    e_code
432                    e_name
433                }
434                survey_type
435                survey_status
436                pt_classified_type
437                aptt_classified_type
438                factorviii_classified_type
439            }
440            testing {
441                testing_id
442                year
443                testing_type
444            }
445            tracking {
446                tracking_id
447                sent_year
448                receipt_tracking
449                first_tracking
450                second_tracking
451                third_tracking
452            }
453            num_pt
454            num_aptt
455            num_inr
456            num_factorviii
457            registered_year
458            registered_date
459            archived_data {
460                participant_id
461                username
462                name
463                rank
464                lab_name
465                hos_name
466                address
467                district
468                tambon
469                province
470                postcode
471                registered_year
472                registered_date
473                tel
474                email
475                num_pt
476                num_aptt
477                num_inr
478                num_factorviii
479            }
480            ${ (isadmin || window.ismoderator ) ? `rank` : '' }
481        }
482    }`;
483
484    try {
485		let ret = await gql.sendGQL('query', query);
486
487		if(ret['status'] == 'success') {
488			let member_data = ret['response']['data']['getUser'];
489			return member_data;
490		}
491	} catch(error) {
492		console.error(error);
493	}
494
495	return null;
496}
497
498/* getPayment */
499export async function getPayment(config)
500{
501    /*
502        getPayment(testing_id: ID, participant_code: ID): [Payment]
503        year: String
504        testing_type: Int
505    */
506    let query = '';
507    if(config.hasOwnProperty('participant_code')) {
508        let { participant_code } = config;
509        query = `query {
510            getPayment(participant_code: "${ participant_code }") {
511                year
512                testing_type
513            }
514        }`;
515    } else if(config.hasOwnProperty('testing_id')) {
516        let { testing_id } = config;
517        query = `query {
518            getPayment(testing_id: "${ testing_id }") {
519                year
520                testing_type
521            }
522        }`;
523    } else
524        return null;
525
526    try {
527		let ret = await gql.sendGQL('query', query);
528
529		if(ret['status'] == 'success') {
530			let payment_data = ret['response']['data']['getPayment'];
531			return payment_data;
532		}
533	} catch(error) {
534		console.error(error);
535	}
536
537	return null;
538}
539
540/* 
541    updateUser
542    =========================
543    update the user by the below parameters
544    updateMember(username: String,
545                password: String,
546                name: String,
547                lab_name: String,
548                hos_name: String,
549                address: String,
550                district: String,
551                tambon: String,
552                province: String,
553                postcode: String,
554                tel: String,
555                email: String,
556                participant_code: ID,
557                num_pt: Int,
558                num_aptt: Int,
559                num_inr: Int,
560                num_factorviii: Int) : User
561*/
562export async function updateUser(config)
563{
564    let payload_data = await common.isLoggedin();
565
566    if(!config.hasOwnProperty('participant_code') && payload_data && payload_data['login'] 
566== true) {
567        config['participant_code'] = payload_data['participant_code'];
568    }
569
570    let member_value = [];
571    for(let [key, value] of Object.entries(config)) {
572        if(typeof value !== 'string')
573            member_value.push(`${ key }: ${ value }`);
574        else
575            member_value.push(`${ key }: "${ common.escapeGraphQL(value) }"`);
576    }
577
578    let query = `mutation {
579        updateMember(${ member_value.join(',') }) {
580            participant_code
581            participant_id
582            username
583            name
584            lab_name
585            hos_name
586            address
587            district
588            tambon
589            province
590            postcode
591            tel
592            email
593            user_type {
594                type_id
595                type_code
596                type_name
597            }
598            user_status {
599                type_id
600                type_code
601                type_name
602            }
603            lab_status {
604                type_id
605                type_code
606                type_name
607            }
608            num_pt
609            num_aptt
610            num_inr
611            num_factorviii
612            registered_year
613        }
614    }`;
615
616    try {
617		let ret = await gql.sendMutation({ query });
618
619		if(ret['status'] == 'success') {
620            if(payload_data && payload_data['login'] == true && config['participant_code'] == payload_data['participant_code']) {
621                let token = await auth.refreshToken();
622            }
623
624			let member_data = ret['response']['data']['updateMember'];
625			return member_data;
626		}
627	} catch(error) {
628		console.error(error);
629	}
630
631    return null;
632}
633
634// renew_token
635// ====================
636// renew the access token
637export async function renew_token()
638{
639    let query = '';
640
641    try {
642        query = `mutation {
643            renew_token {
644                token
645            }
646        }`;
647
648        let ret = await gql.sendMutation({ query });
649
650		if(ret['status'] == 'success') {
651			let token = ret['response']['data']['renew_token'];
652			return token['token'];
653		}
654    } catch(error) {
655        console.error(error);
656    }
657
658    return null;
659}
660
661// listUser
662// ===================
663// list all of the user data.
664// iismoderator : is the request is from the moderator or not.
665// show_surveydata : show the laboratory result or not.
666export async function listUser(ismoderator = false, show_surveydata = true)
667{
668    let query = `query {
669        listUser(show_surveydata: ${ show_surveydata }) {
670            participant_code
671            participant_id
672            name
673            lab_name
674            hos_name
675            accept_pdpa
676            address
677            district
678            tambon
679            province
680            postcode
681            tel
682            email
683            user_type {
684                type_id
685                type_code
686                type_name
687            }
688            user_status {
689                type_id
690                type_code
691                type_name
692            }
693            lab_status {
694                type_id
695                type_code
696                type_name
697            }
698            survey_data {
699                sent_id
700                participant_code
701                lab_code
702                sent_date
703                test_date
704                result_date
705                spec_condition
706                condition_comment
707                amt_person
708                chng_lot
709                sodiumcitrate_name
710                survey {
711                    survey_id
712                    survey_no
713                    survey_time
714                    survey_year
715                }
716                person {
717                    person_id
718                    person_name
719                    person_tel
720                    person_mobile
721                }
722                pt_data	{
723                    pt_data_id
724                    pt_isi
725                    pt_reflow
726                    pt_refhigh
727                    pt_lot_no
728                    divide_value
729                    mean_pt
730                    pt_sample_1
731                    pt_sample_1_comment
732                    ratio_ptsample1
733                    ratio_pt1_assessment
734                    ratio_pt1_isblunder
735                    pt_sample_2
736                    pt_sample_2_comment
737                    ratio_ptsample2
738                    ratio_pt2_assessment
739                    ratio_pt2_isblunder
740                    pt_sample_3
741                    pt_sample_3_comment
742                    ratio_ptsample3
743                    ratio_pt3_assessment
744                    ratio_pt3_isblunder
745                    ratio_pt3_median
746                    ratio_pt3_performance
747                    ratio_pt3_deviation
748                    nw_ratio_pt3
749                    cment_isi
750                    pt_fcodesample1
751                    pt_fcodesample2
752                    pt_fcodesample3
753                }
754                aptt_data {
755                    aptt_data_id
756                    aptt_reflow
757                    aptt_refhigh
758                    aptt_lot_no
759                    mean_aptt
760                    aptt_sample1
761                    aptt_sample1_comment
762                    aptt_sample2
763                    aptt_sample2_comment
764                    aptt_sample3
765                    aptt_sample3_comment
766                    ratio_apttsample1
767                    ratio_apttsample2
768                    ratio_apttsample3
769                    aptt1_assessment
770                    aptt1_isblunder
771                    aptt1_median
772                    aptt1_deviation
773                    aptt1_performance
774                    aptt2_assessment
775                    aptt2_isblunder
776                    aptt2_median
777                    aptt2_deviation
778                    aptt2_performance
779                    aptt3_assessment
780                    aptt3_isblunder
781                    aptt3_median
782                    aptt3_deviation
783                    aptt3_performance
784                    aptt_fcodesample1
785                    aptt_fcodesample2
786                    aptt_fcodesample3
787                }
788                inr_data {
789                    inr_data_id
790                    inr_sample1
791                    inr1_comment
792                    inr_sample2
793                    inr2_comment 
794                    inr1_median
795                    inr1_deviation
796                    inr1_assessment
797                    inr1_isblunder
798                    inr1_performance
799                    inr2_median
800                    inr2_deviation
801                    inr2_assessment
802                    inr2_isblunder
803                    inr2_performance
804                    nw_inr1
805                    nw_inr2
806                }
807                factorviii_data {
808                    factorviii_data_id
809                    factorviii_sample_1
810                    factorviii_sample_1_comment
811                    factorviii_fcodesample1
812                    exam_type
813                    dilution
814                    aptt_lot_no
815                    factorreflow
816                    factorrefhigh
817                    factorref_plasma
818                    factorref_plasma_lot_no
819                    factordef_plasma
820                    factorref_plasma_lot_no
821                    source
822                    source_comment
823                    volunteer_num
824                    standard_curve
825                    factorviii_sample_1
826                    factorviii_sample_1_comment
827                    factorviii_fcodesample1
828                    factorviii_assessment
829                    factorviii_isblunder
830                    standard_uncertainty
831                    grading
832                    rank_grading
833                }
834                machine_info {
835                    machine_code
836                    machine_name
837                }
838                machine_comment
839                pt_info {
840                    pt_code
841                    pt_name
842                }
843                pt_comment
844                aptt_info  {
845                    aptt_code
846                    aptt_name
847                }
848                aptt_comment
849                d_info {
850                    d_code
851                    d_name
852                }
853                d_comment
854                e_info  {
855                    e_code
856                    e_name
857                }
858                e_comment
859                survey_type
860                survey_status
861                pt_classified_type
862                aptt_classified_type
863                factorviii_classified_type
864            }
865            testing {
866                testing_id
867                year
868                testing_type
869            }
870            tracking {
871                tracking_id
872                sent_year
873                receipt_tracking
874                first_tracking
875                second_tracking
876                third_tracking
877            }
878            registered_year
879            registered_date
880            archived_data {
881                participant_id
882                username
883                name
884                rank
885                lab_name
886                hos_name
887                address
888                district
889                tambon
890                province
891                postcode
892                registered_year
893                registered_date
894                tel
895                email
896                num_pt
897                num_aptt
898                num_inr
899                num_factorviii
900            }
901            num_pt
902            num_aptt
903            num_inr
904            num_factorviii
905            ${ (ismoderator) ? `
906                rank
907                ` : '' 
908            }
909        }
910    }`;
911
912    try {
913		let ret = await gql.sendGQL('query', query);
914
915		if(ret['status'] == 'success') {
916			let member_data = ret['response']['data']['listUser'];
917			return member_data;
918		}
919	} catch(error) {
920		console.error(error);
921	}
922
923    return null;
924}
925
926// approveMember
927// ==================
928// approve the specified member by changing the lab_status from 0 to 1.
929export async function approveMember(participant_code)
930{
931    let query = '';
932
933    try {
934        query = `mutation {
935            approveMember(participant_code: "${ participant_code }") {
936                participant_code
937            }
938        }`;
939
940        let ret = await gql.sendMutation({ query });
941
942		if(ret['status'] == 'success') {
943			let participant = ret['response']['data']['approveMember'];
944			return participant['participant_code'];
945		}
946    } catch(error) {
947        console.error(error);
948    }
949
950    return null;
951}
952
953// deleteMember
954// =====================
955// delete the specified member according to participant_code
956export async function deleteMember(participant_code)
957{
958    let query = '';
959
960    try {
961        query = `mutation {
962            deleteMember(participant_code: "${ participant_code }")
963        }`;
964
965        let ret = await gql.sendMutation({ query });
966
967		if(ret['status'] == 'success') {
968			let result = ret['response']['data']['deleteMember'];
969			return result;
970		}
971    } catch(error) {
972        console.error(error);
973    }
974
975    return false;
976}
977
978// checkRecurring
979// ======================
980// check that member by checkRecurring to check whether the user is recurred or not.
981export async function checkRecurring(participant_code, register_year)
982{
983    let tracking_arr = await getTracking({ participant_code });
984    if(tracking_arr == null || tracking_arr.length == 0)
985        return false;
986
987    tracking_arr = tracking_arr.sort((a,b) => b['sent_year'] - a['sent_year']);
988
989    if(
990        tracking_arr[0]['sent_year'] == register_year &&
991        tracking_arr.legth > 1
992    ) {
993        return true; //recurring_ret;
994    }
995
996    return false;
997}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.