using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Xml;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace SimpleCS
{
static class StringExtensions
{
public static string EmptyToNull(this string s)
=> String.IsNullOrEmpty(s) ? null : s;
}
class Program
{
const string Json =
@"[
{
'date_of_visit_year': '2017',
'date_of_visit_month': '6',
'date_of_visit_day': '6',
'date_of_last_surveillance_visit_year': '2017',
'date_of_last_surveillance_visit_month': '4',
'date_of_last_surveillance_visit_day': '4',
'weight': '',
'weight_unknown': 'Unknown',
'date_of_weight_collected_year': '',
'date_of_weight_collected_month': '',
'date_of_weight_collected_day': '',
'height': '',
'height_unknown': 'Unknown',
'date_of_height_collected_year': '',
'date_of_height_collected_month': '',
'date_of_height_collected_day': '',
'zip_code': '85950',
'health_insurances': [
'Indian Health Service'
],
'health_insurances_segments': {
'Indian Health Service': false
},
'patient_highest_education_level': 'Pre-elementary',
'patient_grade_level': null,
'employment_status': 'Employed full-time',
'family_history_of_bleeding_disorder': 'false',
'genetic_mutation': 'false',
'htc_service_locations': [
'HTC outreach clinic'
],
'used_hemlibra_prior_to_collection': 'false',
'cba_draw_not_available': '',
'cba_draw_date_estimation_type': '',
'cba_draw_date_year': '',
'cba_draw_date_month': '',
'cba_draw_date_day': '',
'cba_draw_result': '',
'cba_draw_result_other': '',
'cba_draw_result_is_negative': '',
'nba_draw_not_available': '',
'nba_draw_date_estimation_type': '',
'nba_draw_date_year': '',
'nba_draw_date_month': '',
'nba_draw_date_day': '',
'nba_draw_result': '',
'nba_draw_result_other': '',
'nba_draw_result_is_negative': '',
'inhibitor_not_done': 'No Results Available',
'inhibitor_titer_draw_date_estimation_type': '',
'inhibitor_titer_draw_date_year': '',
'inhibitor_titer_draw_date_month': '',
'inhibitor_titer_draw_date_day': '',
'inhibitor_result': '',
'inhibitor_result_not_detected': '',
'below_inhibitor_reference_value': '',
'highest_historic_inhibitor_titer_value': '',
'highest_historic_inhibitor_titer_unknown': 'Unknown',
'has_history_of_iti': 'false',
'highest_prior_inhibitor_titer_value': '',
'highest_prior_inhibitor_titer_unknown': '',
'iti_use_since_last_reporting_period': [],
'history_of_immune_modulation_therapy': 'false',
'current_products': null,
'current_products_unknown': 'Unknown',
'current_treatment_regimen': 'Episodic (on-demand)',
'use_of_clotting_factor_concentrate': '',
'prophylaxis_start_date_known': '',
'prophylaxis_start_date_estimation_type': '',
'prophylaxis_start_date_year': '',
'prophylaxis_start_date_month': '',
'prophylaxis_start_date_day': '',
'prophylaxis_age_estimation_type': '',
'prophylaxis_age_unit': '',
'prophylaxis_age_value': '',
'joint_bleeds_before_prophylaxis': '',
'approximate_percentage_of_missed_doses': '',
'active_prophylaxis_medications': [],
'use_of_clotting_factor_concentrate_unknown': null,
'products_used_since_last_udc_visit': null,
'products_used_unknown': 'None',
'history_of_allergic_reaction': 'false',
'historical_allergens': null,
'diagnosed_with_tm_since_last_visit': 'false',
'history_of_cvad_placement': 'false',
'history_of_cvad_complications': 'false',
'cvad_complications': null,
'cvad_complications_unknown': '',
'history_of_ich': 'false',
'ich_events': [],
'history_of_joint_bleeds': 'false',
'is_first_joint_bleed_since_last_visit': '',
'first_joint_bleed_start_date_known': '',
'first_joint_bleed_age_estimation_type': '',
'first_joint_bleed_age_value': '',
'first_joint_bleed_age_unit': '',
'first_joint_bleed_estimation_type': '',
'first_joint_bleed_year': '',
'first_joint_bleed_month': '',
'first_joint_bleed_day': '',
'number_of_bleeds_ankle_left': '',
'number_of_bleeds_ankle_right': '',
'number_of_bleeds_elbow_left': '',
'number_of_bleeds_elbow_right': '',
'number_of_bleeds_hip_left': '',
'number_of_bleeds_hip_right': '',
'number_of_bleeds_knee_left': '',
'number_of_bleeds_knee_right': '',
'number_of_bleeds_shoulder_left': '',
'number_of_bleeds_shoulder_right': '',
'collection_method_ankle_left': null,
'collection_method_ankle_right': null,
'collection_method_elbow_left': null,
'collection_method_elbow_right': null,
'collection_method_hip_left': null,
'collection_method_hip_right': null,
'collection_method_knee_left': null,
'collection_method_knee_right': null,
'collection_method_shoulder_left': null,
'collection_method_shoulder_right': null,
'number_of_bleeds_ankle_left_unknown': '',
'number_of_bleeds_ankle_right_unknown': '',
'number_of_bleeds_elbow_left_unknown': '',
'number_of_bleeds_elbow_right_unknown': '',
'number_of_bleeds_hip_left_unknown': '',
'number_of_bleeds_hip_right_unknown': '',
'number_of_bleeds_knee_left_unknown': '',
'number_of_bleeds_knee_right_unknown': '',
'number_of_bleeds_shoulder_left_unknown': '',
'number_of_bleeds_shoulder_right_unknown': '',
'treated_bleed_events_collection_methods': [
'Paper Log'
],
'treated_bleed_events_count': '4',
'history_of_general_bleeds': 'No',
'history_of_gastrointestinal_bleeds': '',
'history_of_genitourinary_hematuria_bleeds': '',
'history_of_genitourinary_other_bleeds': '',
'history_of_head_extracranial_bleeds': '',
'history_of_muscle_bleeds': '',
'history_of_nasal_mucosa_bleeds': '',
'history_of_oral_bleeds': '',
'history_of_soft_tissue_bleeds': '',
'history_of_spine_bleeds': '',
'history_of_other_bleeds': '',
'associated_with_gastrointestinal_bleeds': null,
'associated_with_genitourinary_hematuria_bleeds': null,
'associated_with_genitourinary_other_bleeds': null,
'associated_with_head_extracranial_bleeds': null,
'associated_with_muscle_bleeds': null,
'associated_with_nasal_mucosa_bleeds': null,
'associated_with_oral_bleeds': null,
'associated_with_soft_tissue_bleeds': null,
'associated_with_spine_bleeds': null,
'associated_with_other_bleeds': null,
'history_of_invasive_joint_procedure': 'No',
'history_of_synovectomy_arthroscopic': '',
'history_of_synovectomy_open': '',
'history_of_synovectomy_radioisotopic': '',
'history_of_synovectomy_unknown': '',
'history_of_surgical_fusion_arthrodesis': '',
'history_of_joint_replacement_arthroplasty': '',
'history_of_other_joint_procedure': '',
'joint_locations_synovectomy_arthroscopic': null,
'joint_locations_synovectomy_open': null,
'joint_locations_synovectomy_radioisotopic': null,
'joint_locations_synovectomy_unknown': null,
'joint_locations_surgical_fusion_arthrodesis': null,
'joint_locations_joint_replacement_arthroplasty': null,
'joint_locations_other_joint_procedure': null,
'effect_on_activity_level': 'Limited school or work and limited recreational activity levels',
'has_chronic_pain': 'false',
'chronic_pain_frequency': '',
'has_used_opioids': null,
'opioid_use_frequency': '',
'has_visited_er': 'false',
'er_visit_frequency': '',
'has_been_admitted_as_inpatient': 'false',
'number_of_inpatient_admissions': '',
'number_of_nights_as_inpatient': '',
'days_missed': '0',
'history_of_hepatitis_a_vaccination': 'false',
'hepatitis_a_vaccinations': [],
'history_of_hepatitis_b_vaccination': 'false',
'hepatitis_b_vaccinations': [],
'circumcision_performed': 'false',
'circumcision_with_excessive_bleeding': '',
'circumcision_performed_with_clotting_factor': '',
'iron_replacement_therapy': '',
'menstrual_bleeding': '',
'hysterectomy_performed': '',
'hysterectomy_performed_date_estimation_type': '',
'hysterectomy_performed_date_year': '',
'hysterectomy_performed_date_month': '',
'hysterectomy_performed_date_day': '',
'history_of_hepatocellular_carcinoma': 'No',
'history_of_leukemia': 'No',
'history_of_other_cancer': 'No',
'history_of_fracture_of_bone': 'No',
'history_of_osteopenia': 'No',
'history_of_osteoporosis': 'No',
'history_of_acute_ischemic_stroke': 'No',
'history_of_atrial_fibrillation': 'No',
'history_of_coronary_artery_disease': 'No',
'history_of_congestive_heart_failure': 'No',
'history_of_myocardial_infarction': 'No',
'history_of_transient_ischemic_attack': 'No',
'history_of_chronic_kidney_disease': 'No',
'history_of_kidney_stones': 'No',
'history_of_nephrotic_syndrome': 'No',
'history_of_ascites': 'No',
'history_of_cirrhosis': 'No',
'history_of_hepatic_fibrosis': 'No',
'history_of_splenomegaly': 'No',
'history_of_varices': 'No',
'history_of_deep_vein_thrombosis': 'No',
'history_of_pulmonary_embolism': 'No',
'history_of_anxiety': 'No',
'history_of_depression': 'No',
'history_of_diabetes_mellitus': 'No',
'history_of_hypertension': 'No',
'history_of_iron_deficiency_anemia': 'No',
'history_of_pseudotumor': 'No',
'history_of_coronary_angioplasty': 'No',
'history_of_coronary_stent_placement': 'No',
'history_of_coronary_artery_bypass_graft': 'No',
'history_of_peritoneal_dialysis': 'No',
'history_of_hemodialysis': 'No',
'history_of_heart_valve_replacement': 'No',
'history_of_heart_valve_repair': 'No',
'history_of_kidney_transplant': 'No',
'history_of_liver_transplant': 'No',
'history_of_peripheral_revascularization': 'No',
'has_undergone_surgery': 'No',
'all_procedures_undergone_segments': {},
'metadata': {
'id': 20,
'subject_id': 6,
'study_id': 1,
'edited_at': '2022-01-27T21:08:01.333Z',
'created_at': '2022-01-27T21:05:31.289Z',
'updated_at': '2022-01-27T21:08:01.353Z',
'status': 'submitted',
'grouping': '2022-1',
'htc_id': 353,
'submitter_id': 2,
'is_update': false,
'submitted_by': 'Colonel Admin',
'deleted': false,
'form_id': 874876025,
'study_subject_identifier': '35M8JUAWG',
'grouping_uuid': 359195779
}
}
]";
static void UseDynamicDictionaries()
{
var records = JsonConvert.DeserializeObject<Dictionary<dynamic, dynamic>[]>(Json);
var record = records.First();
var nba_draw_result = record.ContainsKey("nba_draw_result") &&
record["nba_draw_result"] != ""
? record["nba_draw_result"]
: null;
var grouping_uuid = record.ContainsKey("metadata") &&
record["metadata"].ContainsKey("grouping_uuid")
? record["metadata"]["grouping_uuid"]
: null;
}
static void UseJObjects()
{
var records = JArray.Parse(Json);
var record = records.First();
var nba_draw_result = record.SelectToken("nba_draw_result")
?.Value<string>()
.EmptyToNull();
var grouping_uuid = record.SelectToken("metadata.grouping_uuid")
?.Value<int>();
}
static void Main(string[] args)
{
UseJObjects();
UseDynamicDictionaries();
}
}
}