1
我想通過保持相應的patient_id iam在1行中獲取數據,但是如果通過給出函數的輸入參數執行_patient_id,則iam數據將插入到ams中.ams_trans_integration_events 4行如何使用以下代碼在1行中獲取數據
ELSIF(_integration_type = 34),然後/ 病人登記/
select row_to_json(a.*) from (
select
m.mpi_ref_id as "refId",
p.patient_isactive as "patIsActive",
p.patient_created_by as "patientCreatedBy",
m.mpi_lk_external_mpi as "patientMpi",
p.patient_first_name as "patientFirstName",
p.patient_middle_name as "patientMiddleName",
p.patient_last_name as "patientLastName",
p.patient_gender as "patientGender",
p.patient_email as "patientEmail",
p.patient_birthdate as "patientDob",
p.patient_mobile::varchar as "patientMobile",
2 as "partnerId",
p.patient_maritalstatus AS "patientMaritalStatus",
p.patient_education_level AS "patientEducationLevel",
p.patient_identification_mark AS "patientIdentificationMark",
p.patient_is_estimated AS "patientIsEstimated",
p.patient_salutation AS "patientSalutation",
p.patient_blood_group AS "patientBloodGroup",
p.patient_mother_tongue AS "patientMotherTongue",
true AS "patIdentifierIsactive",
i.pat_identifier_dl AS "patIdentifierDl",
i.pat_identifier_uid AS "patIdentifierUid",
i.pat_identifier_pan_no AS "patIdentifierPanNo",
i.pat_identifier_passport AS "patIdentifierPassport",
(select json_agg(patDetails)
from (
select patient_language_language_id AS "languageId"
from xch.xch_transmap_patient_language
where patient_language_pat_id = _patient_id and patient_language_is_active = true
)patDetails) as "patientLanguageIds",
(select json_agg(patPersnlDetails)
from (
select cp.pat_cnt_land_line_no AS "homePhone",
cp.pat_cnt_mobile_no AS "mobile1",
cp.pat_cnt_email_id as "email",
cp.pat_cnt_land_line_no1 as "workPhone",
cp.pat_cnt_mobile_no1 as "mobile2",
cp.pat_cnt_mthd_of_cmctn as "mthdOfComm"
from xch.xch_transmasmap_patient_contact pc
left join xch.xch_transmas_patient_contact cp on cp.pat_cnt_id = pc.pat_contact_cnt_id
where pc.pat_contact_pat_id = _patient_id and pc.pat_contact_cnt_type_id = 1 and pc.pat_contact_isactive = true
)patPersnlDetails)as "patientPersnlDetails",
(select json_agg(patMailingAddressDetails)
from (
select cp.pat_cnt_address AS "address",
cp.pat_cnt_area AS "area",
cp.pat_cnt_pincode as "pinCode",
cp.pat_cnt_city as "city",
cp.pat_cnt_state as "state"
from xch.xch_transmasmap_patient_contact pc
left join xch.xch_transmas_patient_contact cp on cp.pat_cnt_id = pc.pat_contact_cnt_id
where pc.pat_contact_pat_id = _patient_id and pc.pat_contact_cnt_type_id = 4 and pc.pat_contact_isactive = true
)patMailingAddressDetails)as "patientMailingAddressDetails",
(select json_agg(patEmergencyCnt1Details)
from (
select cp.pat_cnt_first_name AS "firstName",
cp.pat_cnt_last_name AS "lastName",
cp.pat_cnt_relationship_id as "relationship",
cp.pat_cnt_email_id as "email",
cp.pat_cnt_land_line_no as "homePhone",
cp.pat_cnt_mobile_no AS "mobilePhone",
cp.pat_cnt_area AS "area",
cp.pat_cnt_pincode as "pinCode",
cp.pat_cnt_city AS "city",
cp.pat_cnt_state AS "state",
cp.pat_cnt_address as "address"
from xch.xch_transmasmap_patient_contact pc
left join xch.xch_transmas_patient_contact cp on cp.pat_cnt_id = pc.pat_contact_cnt_id
where pc.pat_contact_pat_id = _patient_id and pc.pat_contact_cnt_type_id = 2 and pc.pat_contact_isactive = true
)patEmergencyCnt1Details)as "patientEmergencyCnt1Details",
(select json_agg(patEmergencyCnt2Details)
from (
select cp.pat_cnt_first_name AS "firstName",
cp.pat_cnt_last_name AS "lastName",
cp.pat_cnt_relationship_id as "relationship",
cp.pat_cnt_email_id as "email",
cp.pat_cnt_land_line_no as "homePhone",
cp.pat_cnt_mobile_no AS "mobilePhone",
cp.pat_cnt_area AS "area",
cp.pat_cnt_pincode as "pinCode",
cp.pat_cnt_city AS "city",
cp.pat_cnt_state AS "state",
cp.pat_cnt_address as "address"
from xch.xch_transmasmap_patient_contact pc
left join xch.xch_transmas_patient_contact cp on cp.pat_cnt_id = pc.pat_contact_cnt_id
where pc.pat_contact_pat_id = _patient_id and pc.pat_contact_cnt_type_id = 3 and pc.pat_contact_isactive = true
)patEmergencyCnt2Details)as "patientEmergencyCnt2Details"/*,
(select json_agg(patTpaInsuranceDetails)
from (
select
itp.pat_policy_type_id as "patPolicyTypeId",
itp.pat_policy_proposer_relation AS "relationWithProposerEmployee",
itp.pat_policy_ins_company_id AS "insuranceCompany",
itp.pat_policy_ins_id AS "insurancePolicy",
itp.pat_policy_ins_grp_policy AS "insGroupPolicy",
itp.pat_policy_ins_valid_till AS "insPolicyValidTill",
itp.pat_policy_tpa_company_id AS "tpaCompany",
itp.pat_policy_tpa_id AS "tpaPolicy",
itp.pat_policy_tpa_grp_policy AS "tpaGroupPolicy",
itp.pat_policy_tpa_valid_till AS "tpaPolicyValidTill",
CASE WHEN _enc_order_ids = 0 THEN 0 ELSE itp.pat_policy_id END AS "patPolicyId",
itp.pat_policy_pat_enc_id as "policyPatEncId",
itp.pat_policy_created_by AS "patPolicyCreatedBy",
itp.pat_policy_isactive as "patPolicyIsactive"
from xch.xch_trans_patient_ins_tpa_policy itp
where itp.pat_policy_pat_id = _patient_id and itp.pat_policy_isactive = true
)patTpaInsuranceDetails)as "patientTpaInsuranceDetails"*/
from xch.xch_transmas_patient p
left join xch.xch_transmasmap_mpi_link m on m.mpi_lk_xch_mpi=p.patient_mpi
left join xch.xch_transmas_patient_identifier i on i.pat_identifier_pat_id=p.patient_id
--LEFT JOIN xch.xch_transmasmap_patient_contact c on c.pat_contact_pat_id=p.patient_id and c.pat_contact_isactive=true
--LEFT JOIN xch.xch_transmas_patient_contact pc on pc.pat_cnt_id=c.pat_contact_cnt_id and pc.pat_cnt_isactive=true
--LEFT JOIN xch.xch_trans_patient_ins_tpa_policy itp ON itp.pat_policy_pat_id=p.patient_id
where p.patient_id= _patient_id)a into integration_;
IAM獲得4行插入到像下面ams.ams_trans_integration_events表,但我需要只插入1行表這是最後一行
{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"[email protected]","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"[email protected]","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":"ITPL","pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"[email protected]","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":[{"firstName":"Smitha","lastName":"D","relationship":108,"email":"[email protected]","homePhone":8895685787,"mobilePhone":9057806789,"area":"Madhura Nagar","pinCode":574768,"city":103826,"state":4152,"address":"4/2/760,Near Minerva School"}]}
{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"[email protected]","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"[email protected]","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"[email protected]","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":[{"firstName":"Smitha","lastName":"D","relationship":108,"email":"[email protected]","homePhone":8895685787,"mobilePhone":9057806789,"area":"Madhura Nagar","pinCode":574768,"city":103826,"state":4152,"address":"4/2/760,Near Minerva School"}]}
{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"[email protected]","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"[email protected]","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"[email protected]","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":null}
{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"[email protected]","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"[email protected]","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":null,"patientEmergencyCnt2Details":null}
你想獲得哪一行出四.. –
實際上IAM獲得4行這樣 – user7850428
如果你得到4一樣的嗎?行,在'SELECT'後面加'DISTINCT''' –