Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patient Search - Support Event IDs #1969

Merged
merged 15 commits into from
Oct 29, 2024
Merged

Conversation

mpeels
Copy link
Collaborator

@mpeels mpeels commented Oct 25, 2024

Description

  1. Adds support to Patient search API for the following:
  • Morbidity Report ID
  • Document ID
  • State Case ID
  • ABCs Case ID
  • City/County Case ID
  • Notification ID
  • Treatment ID
  • Vaccination ID
  • Investigation ID
  • Lab Report ID
  • Accession ID
  1. Updates the NiFi process to prevent ABC Case IDs being added to the State Case ID list
  2. Runs automatic UI code generation

Tickets

Updated NiFi query

Added
and (ai.assigning_authority_cd <> 'ABCS' OR ai.assigning_authority_cd IS NULL) to State Case ID section

Added
and ai.assigning_authority_cd='ABCS' to ABCs Case ID section

View Full NiFi SQL Query
SELECT 
  p.person_uid, 
  p.add_time, 
  p.add_user_id, 
  p.as_of_date_admin, 
  p.as_of_date_ethnicity, 
  p.as_of_date_general, 
  p.as_of_date_morbidity, 
  p.as_of_date_sex, 
  p.birth_time, 
  p.birth_time_calc, 
  p.cd, 
  p.curr_sex_cd, 
  p.deceased_ind_cd, 
  p.electronic_ind, 
  p.ethnic_group_ind, 
  p.last_chg_time, 
  p.last_chg_user_id, 
  p.marital_status_cd, 
  p.record_status_cd, 
  p.record_status_time, 
  p.status_cd, 
  p.status_time, 
  p.local_id, 
  p.version_ctrl_nbr, 
  p.edx_ind, 
  p.dedup_match_ind, 
  p.first_nm, 
  p.middle_nm, 
  p.last_nm, 
  p.person_uid id, 
  nested.address, 
  nested.phone, 
  nested.email, 
  nested.name, 
  nested.race, 
  nested.entity_id,
  
  --documentIds
  (SELECT STUFF(
  (
    SELECT ','+ cast(documentId as varchar)
    FROM (
	  SELECT DISTINCT
	    doc.local_id documentId
	  FROM 
	    nbs_document doc WITH (NOLOCK)
        JOIN Participation par WITH (NOLOCK)
          ON doc.nbs_document_uid = par.act_uid
	      AND par.subject_class_cd = 'PSN'
          AND par.record_status_cd = 'ACTIVE'
          AND par.act_class_cd = 'DOC'
          AND par.type_cd = 'SubjOfDoc'
          AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
        JOIN NBS_SRTE..Code_value_general cvg
	      ON cvg.code_set_nm = 'PUBLIC_HEALTH_EVENT'
	      AND cvg.code = doc.doc_type_cd
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) document_ids,

  --morbidityReportIds
  (SELECT STUFF(
  (
    SELECT ','+ cast(morbidityReportId as varchar)
    FROM (
	  SELECT DISTINCT
	    obs.local_id morbidityReportId
      FROM
	    Observation obs
	    JOIN Participation par WITH (NOLOCK)
	      ON par.act_uid = obs.observation_uid
		  AND par.subject_class_cd = 'PSN'
          AND par.record_status_cd = 'ACTIVE'
          AND par.act_class_cd = 'OBS'
          AND par.type_cd = 'SubjOfMorbReport'
	      AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) morbidity_report_ids,
  
  --treatmentIds
  (SELECT STUFF(
  (
    SELECT ','+ cast(treatmentId as varchar)
    FROM (
	  SELECT DISTINCT
	    trt.local_id treatmentId
	  FROM
	    Treatment trt with (NOLOCK)
	    JOIN Participation par WITH (NOLOCK)
	      ON par.act_uid = trt.treatment_uid 
		  AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
	      AND par.act_class_cd = 'TRMT'
	      AND par.record_status_cd = 'ACTIVE' 
          AND par.subject_class_cd='PSN'
		  AND par.type_cd = 'SubjOfTrmt'
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) treatment_ids,

  --vaccinationIds
  (SELECT STUFF(
  (
    SELECT ','+ cast(vaccinationId as varchar)
    FROM (
  SELECT DISTINCT
    inv.local_id vaccinationId
  FROM
    Intervention inv WITH (NOLOCK)
    JOIN Participation par WITH (NOLOCK)
      ON inv.intervention_uid = par.act_uid 
	  AND par.subject_class_cd='PAT' 
  	  AND par.type_cd = 'SubOfVacc' 
	  AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) vaccination_ids,
  
  --State Case Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(stateCaseId as varchar)
    FROM (  
		SELECT ai.root_extension_txt stateCaseId
		FROM 
		  Public_health_case phc
		  JOIN Act_id ai ON phc.public_health_case_uid = ai.act_uid
			and ai.type_cd='STATE'
      and (ai.assigning_authority_cd <> 'ABCS' OR ai.assigning_authority_cd IS NULL)
			and ai.root_extension_txt is not null
			and ai.root_extension_txt<>''
		  JOIN participation par ON par.act_uid = phc.public_health_case_uid 
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) state_case_ids,

  --ABCS Case IDs
  (SELECT STUFF(
  (
    SELECT ','+ cast(abcsCaseId as varchar)
    FROM (  
		SELECT ai.root_extension_txt abcsCaseId
		FROM 
		  Public_health_case phc
		  JOIN Act_id ai ON phc.public_health_case_uid = ai.act_uid
		    and ai.act_id_seq=2
			and ai.type_cd='STATE'
      and ai.assigning_authority_cd='ABCS'
			and ai.root_extension_txt is not null
			and ai.root_extension_txt<>''			
		  JOIN participation par ON par.act_uid = phc.public_health_case_uid 
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) abcs_case_ids,	

  --City Case Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(cityCaseId as varchar)
    FROM (  
		SELECT ai.root_extension_txt cityCaseId
		FROM 
		  Public_health_case phc
		  JOIN Act_id ai ON phc.public_health_case_uid = ai.act_uid
			and ai.type_cd='CITY'
			and ai.root_extension_txt is not null
			and ai.root_extension_txt<>''
		  JOIN participation par ON par.act_uid = phc.public_health_case_uid 
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
    ) tmp
    FOR XML PATH('')
  ), 1, 1, '')) city_case_ids,			

  --Notification Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(notificationId as varchar)
    FROM (  
		SELECT noti.local_id notificationId
		FROM 
		  Public_health_case phc
		  JOIN Act_relationship ar ON ar.target_act_uid=phc.public_health_case_uid
		    AND ar.type_cd='Notification'
			AND ar.target_class_cd='CASE'
			AND ar.source_class_cd='NOTF'
			AND ar.record_status_cd='ACTIVE'
		  JOIN notification noti ON noti.notification_uid=ar.source_act_uid
		  JOIN participation par ON par.act_uid = phc.public_health_case_uid 
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
      ) tmp
      FOR XML PATH('')
    ), 1, 1, '')) notification_ids,

  --Investigation Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(investigationId as varchar)
    FROM (  
		SELECT phc.local_id investigationId
		FROM 
		  Public_health_case phc
		  JOIN participation par ON par.act_uid = phc.public_health_case_uid 
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
      ) tmp
      FOR XML PATH('')
    ), 1, 1, '')) investigation_ids,


  --Lab Report Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(labReportId as varchar)
    FROM (  
		SELECT
		  obs.local_id labReportId
		FROM 
		  observation obs
		  JOIN participation par ON par.act_uid = obs.observation_uid
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
      ) tmp
      FOR XML PATH('')
    ), 1, 1, '')) lab_report_ids,
	
	
  --Accession Ids
  (SELECT STUFF(
  (
    SELECT ','+ cast(accessionId as varchar)
    FROM (  
		SELECT ai.root_extension_txt accessionId
		FROM 
		  observation obs
		  JOIN act_id ai ON ai.act_uid = obs.observation_uid
		    AND ai.type_cd='FN'
			and ai.root_extension_txt is not null
			and ai.root_extension_txt<>''
		  JOIN participation par ON par.act_uid = obs.observation_uid
		    AND par.subject_entity_uid IN (select person_uid from Person p2 where p2.person_parent_uid=p.person_parent_uid)
      ) tmp
      FOR XML PATH('')
    ), 1, 1, '')) accession_ids

FROM 
  person p WITH (NOLOCK)
  OUTER apply (
    SELECT 
      * 
    FROM 
      -- address
      (
        SELECT 
          (
            SELECT 
              STRING_ESCAPE(pl.street_addr1, 'json') streetAddr1, 
              STRING_ESCAPE(pl.street_addr2, 'json') streetAddr2, 
              STRING_ESCAPE(pl.city_desc_txt, 'json') city, 
              pl.zip_cd zip, 
              pl.cnty_cd cntyCd, 
              pl.state_cd state, 
              pl.cntry_cd cntryCd,
 			  [county].code_desc_txt cntyText,
			  [state].state_nm stateText,
			  [country].code_short_desc_txt cntryText
            FROM 
              Entity_locator_participation elp WITH (NOLOCK)
              JOIN Postal_locator pl WITH (NOLOCK) ON elp.locator_uid = pl.postal_locator_uid 
 			  left join NBS_SRTE..State_county_code_value [county] on [county].code = pl.cnty_cd
			  left join NBS_SRTE..State_code [state] on [state].state_cd = pl.state_cd
			  left join NBS_SRTE..Country_code [country] on [country].code = pl.cntry_cd
            WHERE 
              elp.entity_uid = p.person_uid 
              AND elp.class_cd = 'PST' 
              AND elp.status_cd = 'A' FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS address
      ) AS address, 
      -- person phone
      (
        SELECT 
          (
            SELECT
			  REPLACE(REPLACE(tl.phone_nbr_txt,'-',''),' ','') telephoneNbr,
              tl.extension_txt extensionTxt,
			  elp.cd typeCd,
              elp.use_cd useCd
            FROM
              Entity_locator_participation elp WITH (NOLOCK)
              JOIN Tele_locator tl WITH (NOLOCK) ON elp.locator_uid = tl.tele_locator_uid 
            WHERE 
              elp.entity_uid = p.person_uid 
              AND elp.class_cd = 'TELE' 
              AND elp.status_cd = 'A' 
              AND tl.phone_nbr_txt IS NOT NULL FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS phone
      ) AS phone, 
      -- person email
      (
        SELECT 
          (
            SELECT 
              STRING_ESCAPE(tl.email_address, 'json') emailAddress 
            FROM 
              Entity_locator_participation elp WITH (NOLOCK)
              JOIN Tele_locator tl WITH (NOLOCK) ON elp.locator_uid = tl.tele_locator_uid 
            WHERE 
              elp.entity_uid = p.person_uid 
              AND elp.class_cd = 'TELE' 
              AND elp.status_cd = 'A' 
              AND tl.email_address IS NOT NULL FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS email
      ) AS email, 
      -- person_names
      (
        SELECT 
          (
            SELECT 
			  STRING_ESCAPE(REPLACE(pn.last_nm,'-',' '), 'json') lastNm,
              soundex(pn.last_nm) lastNmSndx, 
              STRING_ESCAPE(pn.middle_nm, 'json') middleNm, 
              STRING_ESCAPE(pn.first_nm, 'json') firstNm, 
              soundex(pn.first_nm) firstNmSndx, 
              pn.nm_use_cd, 
              pn.nm_suffix nmSuffix, 
              pn.nm_degree nmDegree 
            FROM 
              person_name pn WITH (NOLOCK)
            WHERE 
              person_uid = p.person_uid FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS name
      ) AS name, 
      -- person races
      (
        SELECT 
          (
            SELECT 
              pr.race_cd raceCd, 
              pr.race_desc_txt raceDescTxt, 
              pr.race_category_cd raceCategoryCd 
            FROM 
              Person_race pr WITH (NOLOCK)
            WHERE 
              person_uid = p.person_uid FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS race
      ) AS race, 
      -- Entity id
      (
        SELECT 
          (
            SELECT 
              ei.type_cd typeCd, 
              ei.record_status_cd recordStatusCd, 
			  STRING_ESCAPE(REPLACE(REPLACE(ei.root_extension_txt,'-',''),' ',''), 'json') rootExtensionTxt
            FROM 
              entity_id ei WITH (NOLOCK)
            WHERE 
              ei.entity_uid = p.person_uid FOR json path, 
              INCLUDE_NULL_VALUES
          ) AS entity_id
      ) AS entity_id
  ) AS nested 
WHERE 
  p.person_uid in(${person_ids})
  AND p.person_uid = p.person_parent_uid;

Checklist before requesting a review

  • PR focuses on a single story
  • Code has been fully tested to meet acceptance criteria
  • PR is reasonably small and reviewable (Generally less than 10 files and 500 changed lines)
  • All new functions/classes/components reasonably small
  • Functions/classes/components focused on one responsibility
  • Code easy to understand and modify (clarity over concise/clever)
  • PRs containing TypeScript follow the Do's and Don'ts
  • PR does not contain hardcoded values (Uses constants)
  • All code is covered by unit or feature tests

@mpeels mpeels marked this pull request as ready for review October 25, 2024 20:57
@mpeels mpeels requested a review from stevegsa October 25, 2024 20:58
Copy link
Collaborator

@adamloup-enquizit adamloup-enquizit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 11/11 would search again

@mpeels mpeels requested a review from alaapbharadwaj October 28, 2024 21:01
Copy link

Copy link
Collaborator

@adamloup-enquizit adamloup-enquizit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@stevegsa stevegsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! 🚀

@mpeels mpeels merged commit 7775276 into main Oct 29, 2024
3 checks passed
@mpeels mpeels deleted the CNFT1-3343-patient-search-event-id branch October 29, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants