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

Dheeraj_CTM-625 #4

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions pugh-lab/plugins/trial_match_document_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dateutil.parser
import datetime
from matchengine.plugin_stub import TrialMatchDocumentCreator
import ast

if TYPE_CHECKING:
from matchengine.internals.typing.matchengine_types import TrialMatch, MatchReason
Expand Down Expand Up @@ -53,23 +54,28 @@ def create_trial_matches(self, trial_match: TrialMatch) -> list:
match_doc = {}
match_doc.update(base_match_doc)
match_doc.update(reason_doc)
patient_match_values_dict = {
"genomic_alteration": reason_doc.get("genomic_alteration", ""),
"match_type": reason_doc.get("match_type", ""),
"ms_status": base_match_doc.get("ms_status", ""),
"oncotree_primary_diagnosis_name": base_match_doc.get("oncotree_primary_diagnosis_name", ""),
"age": base_match_doc.get("age", ""),
"er_status": base_match_doc.get("er_status", ""),
"her2_status": base_match_doc.get("her2_status", ""),
"pr_status": base_match_doc.get("pr_status", ""),
"true_hugo_symbol": reason_doc.get("true_hugo_symbol", ""),
"true_variant_classification": reason_doc.get("true_variant_classification", ""),
"variant_category": reason_doc.get("variant_category", ""),
"true_transcript_exon": reason_doc.get("true_transcript_exon", ""),
"true_protein_change": reason_doc.get("true_protein_change", ""),
"prior_treatment_agent": base_match_doc.get("prior_treatment_agent",""),
"oncotree_primary_diagnosis_match_value": base_match_doc.get("oncotree_primary_diagnosis_match_value", "")
}
patient_match_values_dict = {}
for reason in trial_match.match_reasons:
tv = reason.query
if reason.query_kind == "genomic":
patient_match_values_dict.update({
k: v for k, v in reason_doc.items()
if k.upper() in self._GENOMIC_COPY_FIELDS and any(k_part in k or k in k_part for k_part in tv.keys())
})
elif reason.query_kind == "clinical":
patient_match_values_dict.update({
k: v for k, v in base_match_doc.items()
if k.upper() in self._CLINICAL_COPY_FIELDS and any(k_part in k or k in k_part for k_part in tv.keys())
})
elif reason.query_kind == "prior_treatment":
query_str = reason_doc.get("query")
query_dict = ast.literal_eval(query_str)
patient_match_values_dict.update({
k: v for k, v in query_dict.items()
if k.upper() in self._PRIOR_TREATMENT_COPY_FIELDS and any(k_part in k or k in k_part for k_part in tv.keys())
})

patient_match_values_dict.update({'genomic_alteration': reason_doc.get("genomic_alteration", "")})
# Filter out key-value pairs where the value is an empty string
filtered_data = {k: v for k, v in patient_match_values_dict.items() if v != "" and v !="NA"}

Expand Down Expand Up @@ -560,4 +566,12 @@ def _get_sort_order(self, match_document: Dict) -> list:
"ER_STATUS"
}
_TRIAL_COPY_FIELDS = {'protocol_no', 'short_title', 'nickname', 'nct_id'}
_PRIOR_TREATMENT_COPY_FIELDS = {'AGENT'}
_PRIOR_TREATMENT_COPY_FIELDS = {
'AGENT',
'TREATMENT_CATEGORY',
'SUBTYPE',
'AGENT_CLASS',
'SURGERY_TYPE',
'RADIATION_TYPE',
'RADIATION_SITE'
}