diff --git a/nbri_ehr/resources/data/birth_condition.tsv b/nbri_ehr/resources/data/birth_condition.tsv
new file mode 100644
index 0000000..bdb4e26
--- /dev/null
+++ b/nbri_ehr/resources/data/birth_condition.tsv
@@ -0,0 +1,3 @@
+value title sort_order
+L Live 1
+D Dead 2
diff --git a/nbri_ehr/resources/data/breeding_type.tsv b/nbri_ehr/resources/data/breeding_type.tsv
new file mode 100644
index 0000000..dea0f78
--- /dev/null
+++ b/nbri_ehr/resources/data/breeding_type.tsv
@@ -0,0 +1,10 @@
+value title sort_order
+A Assigned Breeding Protocol 1
+C Cull 2
+H Held from Mating Activity 3
+M Multi-Male 4
+P Project Breeding 5
+Q Testing as Breeder 6
+S Single Male Harem 7
+T Time-Mated 8
+O Not Assigned 9
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/death_type.tsv b/nbri_ehr/resources/data/death_type.tsv
new file mode 100644
index 0000000..700a88d
--- /dev/null
+++ b/nbri_ehr/resources/data/death_type.tsv
@@ -0,0 +1,14 @@
+value title sort_order
+A Experimental 1
+D Spontaneous/Normal 2
+F Fetal 3
+FD Fetal Death 4
+FL Fetal Live 5
+FN Fetal found at necropsy 6
+FX Fetal experimental 7
+K Cull (scheduled) 8
+M Medical cull (non-scheduled) 9
+ND Non-vaginal (C-section) dead 10
+NT Not pregnant at assessment 11
+S Cull 12
+X Experimental 13
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/delivery_mode.tsv b/nbri_ehr/resources/data/delivery_mode.tsv
new file mode 100644
index 0000000..cea8a58
--- /dev/null
+++ b/nbri_ehr/resources/data/delivery_mode.tsv
@@ -0,0 +1,4 @@
+value title
+V Vaginal
+N Surgical-clinical
+NX Surgical experimental
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/editable_lookups.tsv b/nbri_ehr/resources/data/editable_lookups.tsv
index 90cc8af..d0ed33a 100644
--- a/nbri_ehr/resources/data/editable_lookups.tsv
+++ b/nbri_ehr/resources/data/editable_lookups.tsv
@@ -18,10 +18,12 @@ ehr_lookups bcs_score Clinical Body Condition Score Clinical observation fixed v
ehr_lookups behavior_abnormality Clinical Behavior Abnormality Clinical observation fixed values.
ehr_lookups behavior_mgmt_codes Behavior Behavior Management Codes Behavior observation fixed values.
ehr_lookups behavior_types Behavior Behavior Types Behavior observation fixed values.
+ehr_lookups birth_condition Colony Management Birth Condition Birth condition values.
ehr_lookups blood_draw_reason Clinical Blood Draw Reason Used in blood draw datasets.
ehr_lookups blood_draw_tube_type Clinical Blood Draw Tube Type Used in blood draw datasets.
ehr_lookups blood_sample_type Clinical Blood Sample Types Used in blood draw datasets.
ehr_lookups blood_tube_volumes Clinical Blood Tube Volumes Used in blood draw datasets.
+ehr_lookups breeding_type Colony Management Breeding Type Breeding group assignment codes.
ehr_lookups cage_type Colony Management Cage Type Used in cage details.
ehr_lookups calculated_status_codes Colony Management Calculated Status Animal status values.
ehr_lookups capillary_refill_time Clinical Capillary Refill Times Used clinical observations.
@@ -36,8 +38,10 @@ ehr_lookups country Colony Management Country
ehr_lookups country_category Colony Management Country Category
ehr_lookups daily_enrich_codes Behavior Daily enrichment codes.
ehr_lookups data_category Clinical Data Categories Used in datasets.
-ehr_lookups death_reason Colony Management Death Reason
-ehr_lookups delivery_state Colony Management Delivery State
+ehr_lookups death_reason Colony Management Death Reason
+ehr_lookups death_type Colony Management Death Type Death type codes.
+ehr_lookups delivery_mode Colony Management Delivery Mode
+ehr_lookups delivery_state Colony Management Delivery State
ehr_lookups dental_obs Clinical Dental Observation Types Clinical observation values.
ehr_lookups derm_obs Clinical Dermatologic Observation Types Clinical observation values.
ehr_lookups digit_amputation Clinical Digit Amputation Clinical observation fixed values.
diff --git a/nbri_ehr/resources/data/flag_categories.tsv b/nbri_ehr/resources/data/flag_categories.tsv
new file mode 100644
index 0000000..2e815bf
--- /dev/null
+++ b/nbri_ehr/resources/data/flag_categories.tsv
@@ -0,0 +1,11 @@
+Category Description Enforce Single Flag Per Animal? Omit When Displaying Default Flags? Highlight Flags of This Category? Date Disabled
+Behavioral Behavioral observations, abnormal-behavior designations and enrichment provided to the animal. false false false
+Capture Restraint and handling limitations. false false true
+Clinical Clinical conditions, procedures and veterinary designations. false false false
+Experimental Experimental treatments, inoculations and implants. false false true
+Genetics Genetic background, ancestry, inbreeding and genomic characterization. false true false
+Hold Animal held or reserved for a specific project, investigator or shipment. false false false
+Reproduction Breeding, contraception, pregnancy, fostering and rearing designations. false false false
+Socially housed Social rank, pairing, group-formation and social-housing-exemption designations. false false false
+Status Administrative status and availability designations. false false true
+Training Training program participation and progress. false false false
diff --git a/nbri_ehr/resources/data/flag_values.tsv b/nbri_ehr/resources/data/flag_values.tsv
new file mode 100644
index 0000000..8a075a7
--- /dev/null
+++ b/nbri_ehr/resources/data/flag_values.tsv
@@ -0,0 +1,11 @@
+Category Meaning Description Date Disabled ObjectId
+Behavioral Behavioral FLAG 1 Behavioral FLAG 1
+Capture Capture FLAG 1 Capture FLAG 1
+Clinical Clinical FLAG 1 Clinical FLAG 1
+Experimental Experimental FLAG 1 Experimental FLAG 1
+Genetics Genetics FLAG 1 Genetics FLAG 1
+Hold Hold FLAG 1 Hold FLAG 1
+Reproduction Reproduction FLAG 1 Reproduction FLAG 1
+Socially housed Socially housed FLAG 1 Socially housed FLAG 1
+Status Status FLAG 1 Status FLAG 1
+Training Training FLAG 1 Training FLAG 1
diff --git a/nbri_ehr/resources/data/gender_codes.tsv b/nbri_ehr/resources/data/gender_codes.tsv
index 01c67fb..a55c8a7 100644
--- a/nbri_ehr/resources/data/gender_codes.tsv
+++ b/nbri_ehr/resources/data/gender_codes.tsv
@@ -1,4 +1,4 @@
code meaning
-1 unknown
-2 female
-3 male
\ No newline at end of file
+U Unknown
+F Female
+M Male
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/lookup_sets.tsv b/nbri_ehr/resources/data/lookup_sets.tsv
index 613eb8e..c465f4a 100644
--- a/nbri_ehr/resources/data/lookup_sets.tsv
+++ b/nbri_ehr/resources/data/lookup_sets.tsv
@@ -16,8 +16,10 @@ bcs_score BCS Store value title
behavior_abnormality Behavior Abnormality value
behavior_mgmt_codes Behavior Management Codes value
behavior_types Behavior Types value
+birth_condition Birth Condition value title
blood_draw_reason Blood Draw Reason value
blood_sample_type Blood Sample Types value
+breeding_type Breeding Type value title
cage_type Cage Type value title
capillary_refill_time Capillary Refill Time value
card_format Card Format value title
@@ -31,6 +33,8 @@ country_category Country Category value title
daily_enrich_codes Daily Enrichment Codes value
data_category Data Category Field Values value
death_reason Death Reason value
+death_type Death Type value title
+delivery_mode Delivery Mode value title
delivery_state Delivery State value title
dental_obs Dental Observations value
derm_obs Dermatologic Observations value
@@ -98,6 +102,7 @@ req_order_type Req Order Type value title
respiratory_observations Respiratory Observations value title
sib_score SIB Score value
skin_problem Skin Problem value
+status_codes Status Code Field Values value title
stool_score Stool Score value
stool_types Stool Types value
tb_obs_score TB Obs Score value
diff --git a/nbri_ehr/resources/data/lookupsManifest.tsv b/nbri_ehr/resources/data/lookupsManifest.tsv
index defb466..9f32d12 100644
--- a/nbri_ehr/resources/data/lookupsManifest.tsv
+++ b/nbri_ehr/resources/data/lookupsManifest.tsv
@@ -18,10 +18,12 @@ bcs_score
behavior_abnormality
behavior_mgmt_codes
behavior_types
+birth_condition
blood_draw_reason
blood_draw_tube_type
blood_sample_type
blood_tube_volumes
+breeding_type
cage_type
calculated_status_codes
capillary_refill_time
@@ -35,6 +37,8 @@ country_category
daily_enrich_codes
data_category
death_reason
+death_type
+delivery_mode
delivery_state
dental_obs
derm_obs
@@ -51,6 +55,8 @@ expense_class
fecal_score
fecal_smear_score
feed_assess_types
+flag_categories
+flag_values
gastro_types
gender_codes
general_obs
@@ -108,7 +114,10 @@ routes
sib_score
source
snomed
+species
+species_codes
skin_problem
+status_codes
stool_score
stool_types
tb_obs_score
diff --git a/nbri_ehr/resources/data/lookupsManifestTest.tsv b/nbri_ehr/resources/data/lookupsManifestTest.tsv
index b2006c8..d64c8ba 100644
--- a/nbri_ehr/resources/data/lookupsManifestTest.tsv
+++ b/nbri_ehr/resources/data/lookupsManifestTest.tsv
@@ -12,15 +12,18 @@ amount_units
app_score
arrival_type
arthritis_types
+att_score
bandage_observations
bcs_score
behavior_abnormality
behavior_mgmt_codes
behavior_types
+birth_condition
blood_draw_reason
blood_draw_tube_type
blood_sample_type
blood_tube_volumes
+breeding_type
cage_type
calculated_status_codes
capillary_refill_time
@@ -34,6 +37,8 @@ country_category
daily_enrich_codes
data_category
death_reason
+death_type
+delivery_mode
delivery_state
dental_obs
derm_obs
@@ -50,6 +55,8 @@ expense_class
fecal_score
fecal_smear_score
feed_assess_types
+flag_categories
+flag_values
gastro_types
gender_codes
general_obs
diff --git a/nbri_ehr/resources/data/pregnancy_result.tsv b/nbri_ehr/resources/data/pregnancy_result.tsv
index 1c615bc..819182e 100644
--- a/nbri_ehr/resources/data/pregnancy_result.tsv
+++ b/nbri_ehr/resources/data/pregnancy_result.tsv
@@ -1,3 +1,7 @@
value title
-1 Stillborn
-2 Abort
\ No newline at end of file
+NT No Tissue
+FD Fetal Death
+FN Found at necropsy
+FX Live, Term, euthanized at birth
+ND Live, Died day of birth (lungs inflated)
+FL Fetal Delivery, live in Utero
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/source.tsv b/nbri_ehr/resources/data/source.tsv
index 0d893c4..5c3f18a 100644
--- a/nbri_ehr/resources/data/source.tsv
+++ b/nbri_ehr/resources/data/source.tsv
@@ -1,108 +1,103 @@
code meaning
-1 Adv Bioscience Labs
-2 Alamogordo PrimateFaclty
-3 Alpha Genesis, Inc.
-4 Barton West End Farm
-5 Battelle Memorial Inst
-6 Baylor Research Inst
-7 BIOCULTURE (MTIUS) LTD
-8 Bioculture US LLC
-9 BIOQUAL, Inc.
-10 Boehringer Ingelheim
-11 Boston University
-12 Buckshire Corporation
-13 Caribbean Primate Rsrch
-14 CBNC
-15 CDC
-16 Charles River Laboratory
-17 Charles River/Reno
-18 Chimp Haven
-19 China/Guangxi GF Sci Pri
-20 Chiron Corp
-21 CiToxLab North America
-22 Covance Research Prod
-23 CR Rsrch Models Houston
-24 Ctr Captive Chimp Care
-25 Cynologics Ltd
-26 DHMRI
-27 Duke Univ Medical Ctr
-28 Durham Research Center
-29 Emory University YPRC
-30 Envigo Global Services
-31 Guangdong Landau Biotech
-32 Hainan, China
-33 Harvard Medical School
-34 Indonesia (Pt. W. Sat)
-35 Johns Hopkins University
-36 LC Preclinical Research
-37 Lovelace Biomedical
-38 LRRI
-39 LSU Health Science BR
-40 LSU Health Science NO
-41 LSU Health Science Shv
-42 Mannheimer Foundation
-43 Mass. General Hospital
-44 MD Anderson Cancer Ctr.
-45 Merck & Co (Rahway)
-46 Merck & Co (WP)
-47 Merck Research Labs WP
-48 Nationwide Children's
-49 New England NPRC
-50 New York University
-51 NIAID (Bioqual)
-52 NIAID Morgan Island
-53 NIAID NIH Animal Ctr
-54 NICHD/NIH
-55 NIH
-56 NIH Animal Center
-57 NINDS NIH Animal Ctr
-58 Novartis Pharm. Corp.
-59 Novartis Vaccines Srl
-60 NYU School of Medicine
-61 Oregon NPRC
-62 Pfizer
-63 Pfizer-Andover
-64 Pfizer-Pearl River
-65 PreLabs
-66 Primate Products
-67 Primedica Labs
-68 PrimGen
-69 Primgen CSP
-70 RainForest Adventures
-71 Republic of Mauritius
-72 Rocky Mountain Lab
-73 Save the Chimps
-74 Siconbrec Inc
-75 Sierra Biomedical
-76 SNBL-SRC
-77 SRI International
-78 St. Jude Childrens Rsrch
-79 St. Kitts
-80 Stanford Univ School Med
-81 Stony Brook University
-82 SUNY Downstate Medical
-83 SW Found Biomed Rsrch
-84 Texas Biomed
-85 Three Springs Scientific
-86 Tulane NPC (Covington)
-87 Tulane Univ Medical Ctr
-88 Univ Alabama Birmingham
-89 Univ of Illinois
-90 Univ of Kansas Med Ctr
-91 Univ of Maryland
-92 Univ of Nebraska Med Ctr
-93 Univ of Pittsburgh
-94 Univ of Texas at Austin
-95 Univ of Washington NPRC
-96 Univ of Wisconsin
-97 Univ Tex MD Anderson CC
-98 USAMRICD
-99 USAMRIID
-100 Virginia Commonwealth U
-101 WakeForest School of Med
-102 WaNPRC
-103 Worldwide Primates, Inc.
-104 WRAIR
-105 Wyeth-Ayerst Rsrch (PR)
-106 Yale Univ Sch Medicine
-107 Yerkes Regional PRC
\ No newline at end of file
+AAI Asiatic Animal Imports
+BIOQUAL Bioqual, Incorporated
+BRANDEIS Brandeis University
+CA-DPH Calif Dept Public Health Facilities
+CA-DOH California State Department of Health
+CPRC Carribean Primate Center
+CWRU Case Western Reserve University
+UCD-CNS Center for Neuroscience, UCD
+CR-KL Charles River - Key Lois
+CRL Charles River Labs
+CRRP Charles River Research Primates Inc
+BROOKFIELD Chicago Zoological Park (Brookfield Zoo)
+CHILDRENS Childrens Hospital
+CHIMR Christ Hospital Inst. for Medical Res.
+CSU Colorado State University
+CORNELL Cornell University
+COULSTON Coulston Foundation
+COVANCE Covance Research Products, Inc.
+PRIMGEN CSP-Primgen
+CUTTER Cutter Lab
+DMT Del Mundo Trading
+EPZ El Paso Zoological Gardens
+ENVIGO Envigo
+HAHNEMANN Hahnemann University
+HL Hazelton Laboratories
+HLA Hazelton Laboratories America Inc.
+UNK Institution Unknown
+ISU-VDL Iowa State Univ, Vet Diagnostic Lab
+JVL Jan Vacek Limited
+JHMC Jewish Hospital & Medical Center
+JRI Johnson Research Institute
+KNLPC Kunming National Laboratory Primate Ctr.
+LABS Laboratory Animal Breeders and Services
+LABSINDO Labsindo
+LEMSIP LEMSIP, New York Medical Center, RDI
+LAIR Letterman Army Res Inst-Presidio
+LB Litton Bionetics
+LLU Loma Linda University
+MSU-MI Michigan State University
+MSU-MT Montana State University
+MPI MPI Research
+NASA-ARC NASA-Ames Research Center
+NAMRL Naval Aerospace Medical Research Lab
+NEPRC New England Primate Research Center
+NIHAC NIH Animal Center
+ORPRC Oregon Regional Primate Research Center
+PARC-SAF Parc Safari African
+PPC Perrine Primate Center
+PPP Peruvian Primatological Project
+PET-FARM Pet Farm
+PRIMLAB Primate Laboratory
+PPI Primate Products, Incorporated
+PRIVATE Private Party
+RIEPT Res. Inst. of Exp. Pathology & Therapy
+SALK Salk Institute
+SFGH San Francisco General Hospital
+SNBL Shin Nippon Biomedical Laboratories
+SICONBREC Siconbrec
+SBM Sierra Biomedical
+SKB Smith, Kline, Beecham
+SIU Southern Illinois University
+SIU-SOM Southern Illinois University Med School
+SORI Southern Research Institute
+SFRE Southwest Foundation for Res. & Educ.
+SWRF Southwest Research Foundation
+SWRI Southwest Research Institute
+SOPF Stanford Outdoor Primate Facility
+SRI Stanford Research Institute
+SUNY-SB State Univ of New York at Stony Brook
+SXZ Suzhou Xishan Zhongke Lab Animal Co.
+SYNTEX Syntex (USA) Incorporated
+TARPON Tarpon Zoo
+TTUHSC Texas Tech Health Science Center
+BROOKS-AFB Texas, Brooks Air Force Base
+TPI The Parkinson's Institute
+TNPRC Tulane (Delta) Regional Primate Res Ctr
+UCB UC Berkeley
+UCLA UC Los Angeles
+UCR UC Riverside
+UCSD UC San Diego
+UCSF UC San Francisco Vivarium
+UC-ARS Univ of Calif, Animal Resources Service
+GPC Univ of Gottingen Primate Center
+UH-RAF Univ of Hawaii, Research Animal Facility
+OUHSC Univ of Oklahoma Health Sci. Center
+UTHSC-H Univ of Texas, Health Sci Ctr, Houston
+UCHSC University of Colorado Health Sciences
+UCMC University of Colorado Medical Center
+UIC University of Illinois at Chicago
+UNV University of Nevada
+UNM University of New Mexico
+UPR University of Puerto Rico
+UTSCC University of Texas System Cancer Center
+UNK-CN Unknown Institution, China
+VBS Valley Biosystems
+WFSM Wake Forest School of Medicine
+WANPRC Washington Regional Primate Research Ctr
+WHMC Wilford Hall Medical Center
+WRPRC Wisconsin Regional Primate Research Ctr
+WAI Woodward Asiatic Imports
+WWP World Wide Primates, Inc.
+YPRC Yemassee Primate Research Center
diff --git a/nbri_ehr/resources/data/species.tsv b/nbri_ehr/resources/data/species.tsv
index c95e4bd..12d3118 100644
--- a/nbri_ehr/resources/data/species.tsv
+++ b/nbri_ehr/resources/data/species.tsv
@@ -1,7 +1,15 @@
Common Scientific Name Id Prefix Mhc Prefix Max Blood Draw (mL/kg) Max Percent Blood Drawn Blood Reconstitution Interval (Days) Cites Code Date Disabled USDA Gestation
-African Green Monkey Chlorocebus aethiops AGM 3.0000 1.0000 7.0000
-Brown-Tufted Capuchin Cebus apella CAP 3.0000 1.0000 7.0000
-Cynomolgus Macaque Macaca fascicularis CYN 3.0000 1.0000 7.0000
-Marmoset 3.0000 1.0000 7.0000
-Pig-Tailed Macaque Macaca nemestrina PIG 3.0000 1.0000 7.0000
-Rhesus Macaque Macaca mulatta RHM 3.0000 1.0000 7.0000
\ No newline at end of file
+Rhesus Macaque Macaca Mulatta 3.0000 1.0000 7.0000
+Pig-Tailed Macaque Macaca Nemestrina 3.0000 1.0000 7.0000
+Bonnet Macaque Macaca Radiata 3.0000 1.0000 7.0000
+Olive Baboon Papio Anubis 3.0000 1.0000 7.0000
+Yellow Baboon Papio Cynocephalus 3.0000 1.0000 7.0000
+Squirrel Monkey Saimiri Sciureus 3.0000 1.0000 7.0000
+African Green Monkey Chlorocebus Aethiops 3.0000 1.0000 7.0000
+Domestic Dog Canis Familiaris 3.0000 1.0000 7.0000
+Formosan Rock Macaque Macaca Cyclopis 3.0000 1.0000 7.0000
+Japanese Macaque Macaca Fuscata 3.0000 1.0000 7.000
+Talapoin Monkey Cercopithecus Talapoin 3.0000 1.0000 7.0000
+Sykes' Monkey Cercopithecus M Albogulari 3.0000 1.0000 7.0000
+Dusky Titi Monkey Callicebus Moloch 3.0000 1.0000 7.0000
+Brown-Tufted Capuchin Cebus Apella 3.0000 1.0000 7.0000
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/species_codes.tsv b/nbri_ehr/resources/data/species_codes.tsv
index df698e7..feb4100 100644
--- a/nbri_ehr/resources/data/species_codes.tsv
+++ b/nbri_ehr/resources/data/species_codes.tsv
@@ -1,7 +1,15 @@
Code Scientific Name Common Name Description Genus Species Date Disabled
-1 Chlorocebus aethiops AGM African Green Monkey 3
-10 Macaca mulatta RHM Rhesus Macaque 3
-18 Marmoset 3
-4 Cebus apella CAP Brown-Tufted Capuchin 3
-7 Macaca fascicularis CYN Cynomolgus Macaque 3
-9 Macaca nemestrina PIG Pig-Tailed Macaque 3
\ No newline at end of file
+MMU Macaca Mulatta Rhesus Macaque
+MNE Macaca Nemestrina Pig-Tailed Macaque
+MRA Macaca Radiata Bonnet Macaque
+PAN Papio Anubis Olive Baboon
+PCY Papio Cynocephalus Yellow Baboon
+SSC Saimiri Sciureus Squirrel Monkey
+CAE Chlorocebus Aethiops African Green / Vervet
+DOG Canis Familiaris Domestic Dog
+MCY Macaca Cyclopis Formosan Rock Macaque
+MFU Macaca Fuscata Japanese Macaque
+CTA Cercopithecus Talapoin Talapoin Monkey
+CMA Cercopithecus M Albogulari Sykes' Monkey
+CMO Callicebus Moloch Dusky Titi Monkey
+CAP Cebus Apella Brown-Tufted Capuchin
\ No newline at end of file
diff --git a/nbri_ehr/resources/data/status_codes.tsv b/nbri_ehr/resources/data/status_codes.tsv
new file mode 100644
index 0000000..b131086
--- /dev/null
+++ b/nbri_ehr/resources/data/status_codes.tsv
@@ -0,0 +1,5 @@
+value title
+Alive Alive
+Dead Dead
+Escaped Escaped
+Shipped Shipped
diff --git a/nbri_ehr/resources/data/weight_ranges.tsv b/nbri_ehr/resources/data/weight_ranges.tsv
index bb2c94f..dca47bd 100644
--- a/nbri_ehr/resources/data/weight_ranges.tsv
+++ b/nbri_ehr/resources/data/weight_ranges.tsv
@@ -1,3 +1,5 @@
Species Min Weight Max Weight
-Cynomolgus 0.0 20.0
-Rhesus 0.0 35.0
\ No newline at end of file
+CMO 0.04 2.2
+MCY 0.2 16.0
+MMU 0.2 30.0
+MNE 0.2 30.0
diff --git a/nbri_ehr/resources/queries/ehr/project.query.xml b/nbri_ehr/resources/queries/ehr/project.query.xml
index d2db2ca..5b72f21 100644
--- a/nbri_ehr/resources/queries/ehr/project.query.xml
+++ b/nbri_ehr/resources/queries/ehr/project.query.xml
@@ -47,6 +47,13 @@
true
+
+
+ core
+ Users
+ UserId
+ DisplayName
+ true
diff --git a/nbri_ehr/resources/queries/ehr_lookups/buildings.js b/nbri_ehr/resources/queries/ehr_lookups/buildings.js
index 3fca085..b5e9890 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/buildings.js
+++ b/nbri_ehr/resources/queries/ehr_lookups/buildings.js
@@ -7,6 +7,19 @@ var LABKEY = require("labkey");
var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
+// Width of ehr_lookups.buildings.name. The description it is derived from is a wider column, so it can overrun the
+// key; reject it here rather than letting the database raise an unreadable error.
+var MAX_NAME_LENGTH = 100;
+
+// 'name' is not user editable, so it is absent from the incoming row map and the value this script derives has
+// nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.
+function managedColumns() {
+ return {
+ insert: ["name"],
+ update: ["name"],
+ };
+}
+
function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.description) {
@@ -25,7 +38,19 @@ function onUpsert(row, oldRow, errors){
return;
}
- row.name = row.description + '-' + row.area;
+ if (row.description.length > MAX_NAME_LENGTH) {
+ errors['description'] = 'Description is too long: it becomes the building key, which cannot exceed ' + MAX_NAME_LENGTH + ' characters.';
+ return;
+ }
+
+ // The description alone identifies the building now that the area is no longer folded in, so a duplicate
+ // would collide on the key. Say so here instead of surfacing a constraint violation on a hidden column.
+ if (triggerHelper.totalRecords("ehr_lookups", "buildings", "name", row.description) > 0) {
+ errors['description'] = 'A building described as ' + row.description + ' already exists. Building descriptions must be unique.';
+ return;
+ }
+
+ row.name = row.description;
}
}
}
diff --git a/nbri_ehr/resources/queries/ehr_lookups/cage.js b/nbri_ehr/resources/queries/ehr_lookups/cage.js
index e19a2b7..0e71832 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/cage.js
+++ b/nbri_ehr/resources/queries/ehr_lookups/cage.js
@@ -7,6 +7,19 @@ var LABKEY = require("labkey");
var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
+// Width of ehr_lookups.cage.location. The derived key builds on the room key, which is itself derived, so it can
+// overrun the column; reject it here rather than letting the database raise an unreadable error.
+var MAX_LOCATION_LENGTH = 100;
+
+// 'location' is not user editable, so it is absent from the incoming row map and the value this script
+// derives has nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.
+function managedColumns() {
+ return {
+ insert: ["location"],
+ update: ["location"],
+ };
+}
+
function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.location) {
@@ -20,9 +33,16 @@ function onUpsert(row, oldRow, errors){
return;
}
- row.location = row.room;
+ let location = row.room;
if (row.cage)
- row.location += '-' + row.cage;
+ location += '-' + row.cage;
+
+ if (location.length > MAX_LOCATION_LENGTH) {
+ errors['cage'] = 'Room and cage are too long: they combine to a ' + location.length + ' character location key, which cannot exceed ' + MAX_LOCATION_LENGTH + '.';
+ return;
+ }
+
+ row.location = location;
}
}
}
diff --git a/nbri_ehr/resources/queries/ehr_lookups/cage.query.xml b/nbri_ehr/resources/queries/ehr_lookups/cage.query.xml
index 97b1549..3d15c46 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/cage.query.xml
+++ b/nbri_ehr/resources/queries/ehr_lookups/cage.query.xml
@@ -9,6 +9,11 @@
Room
+
+ ehr_lookups
+ rooms
+ room
+ true
diff --git a/nbri_ehr/resources/queries/study/historicalOther.query.xml b/nbri_ehr/resources/queries/ehr_lookups/flag_values.query.xml
similarity index 58%
rename from nbri_ehr/resources/queries/study/historicalOther.query.xml
rename to nbri_ehr/resources/queries/ehr_lookups/flag_values.query.xml
index 37e2754..c6531be 100644
--- a/nbri_ehr/resources/queries/study/historicalOther.query.xml
+++ b/nbri_ehr/resources/queries/ehr_lookups/flag_values.query.xml
@@ -1,13 +1,13 @@
-
+
-
- Type
+
+ Value
-
\ No newline at end of file
+
diff --git a/nbri_ehr/resources/queries/ehr_lookups/rooms.js b/nbri_ehr/resources/queries/ehr_lookups/rooms.js
index caea28b..18a10a2 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/rooms.js
+++ b/nbri_ehr/resources/queries/ehr_lookups/rooms.js
@@ -8,6 +8,19 @@ var console = require("console");
var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
+// Width of ehr_lookups.rooms.room. The derived key is built from values the user supplies, so it can overrun the
+// column; reject it here rather than letting the database raise an unreadable error.
+var MAX_ROOM_LENGTH = 100;
+
+// 'room' is not user editable, so it is absent from the incoming row map and the value this script derives has
+// nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.
+function managedColumns() {
+ return {
+ insert: ["room"],
+ update: ["room"],
+ };
+}
+
function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.name) {
@@ -15,8 +28,8 @@ function onUpsert(row, oldRow, errors){
return;
}
- if (!row.floor) {
- errors['floor'] = 'Floor is required.';
+ if (!row.building) {
+ errors['building'] = 'Building is required.';
return;
}
@@ -26,7 +39,13 @@ function onUpsert(row, oldRow, errors){
return;
}
- row.room = row.name + '-' + row.floor;
+ let room = row.building + '-' + row.name;
+ if (room.length > MAX_ROOM_LENGTH) {
+ errors['name'] = 'Building and room name are too long: they combine to a ' + room.length + ' character room key, which cannot exceed ' + MAX_ROOM_LENGTH + '.';
+ return;
+ }
+
+ row.room = room;
}
}
}
diff --git a/nbri_ehr/resources/queries/ehr_lookups/rooms.query.xml b/nbri_ehr/resources/queries/ehr_lookups/rooms.query.xml
index dd7b89f..0b522c5 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/rooms.query.xml
+++ b/nbri_ehr/resources/queries/ehr_lookups/rooms.query.xml
@@ -6,8 +6,10 @@
Rooms
-
+
+
+ /nbri_ehr/cageDetails.view?room=${room}truefalsefalse
@@ -17,6 +19,14 @@
falsefalse
+
+
+ true
+ false
+ false
+ false
+
diff --git a/nbri_ehr/resources/queries/ehr_lookups/rooms/.qview.xml b/nbri_ehr/resources/queries/ehr_lookups/rooms/.qview.xml
index 0bfbf5b..f8c6e5e 100644
--- a/nbri_ehr/resources/queries/ehr_lookups/rooms/.qview.xml
+++ b/nbri_ehr/resources/queries/ehr_lookups/rooms/.qview.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/nbri_ehr/resources/queries/ehr_lookups/weight_ranges.query.xml b/nbri_ehr/resources/queries/ehr_lookups/weight_ranges.query.xml
new file mode 100644
index 0000000..b5f2f4d
--- /dev/null
+++ b/nbri_ehr/resources/queries/ehr_lookups/weight_ranges.query.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
diff --git a/nbri_ehr/resources/queries/nbri_ehr/AnimalReqOrder.query.xml b/nbri_ehr/resources/queries/nbri_ehr/AnimalReqOrder.query.xml
index 5c829e1..e282d4d 100644
--- a/nbri_ehr/resources/queries/nbri_ehr/AnimalReqOrder.query.xml
+++ b/nbri_ehr/resources/queries/nbri_ehr/AnimalReqOrder.query.xml
@@ -96,7 +96,7 @@
ehr_lookupsroomsroom
- name
+ room
diff --git a/nbri_ehr/resources/queries/nbri_ehr/Conception.query.xml b/nbri_ehr/resources/queries/nbri_ehr/Conception.query.xml
index 0eb26a8..7fc6298 100644
--- a/nbri_ehr/resources/queries/nbri_ehr/Conception.query.xml
+++ b/nbri_ehr/resources/queries/nbri_ehr/Conception.query.xml
@@ -14,16 +14,28 @@
Conception Date
-
- Conception Date
- Conception Term Date
+
+ Estimated
+ Conception date is estimated rather than observed
+ true
+
+ Task Id
+ ALWAYS_OFF
+
+ ehr
+ tasks
+ taskid
+ rowid
+
+ /ehr/dataEntryFormDetails.view?formType=${TaskId/formtype}&taskid=${TaskId}
+ Status
@@ -31,6 +43,62 @@
qcstaterowid
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FF0000
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FF0000
+
+
+
+
+
+ FBEC5D
+
+
+
+
+
+ FBEC5D
+
+
diff --git a/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.query.xml b/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.query.xml
index 866a7da..b315c2b 100644
--- a/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.query.xml
+++ b/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.query.xml
@@ -11,9 +11,17 @@
Conception Id
+
+ Estimated
+ Conception date is estimated rather than observed
+ Conception Outcome
+
+ Offspring
+ Animal born from this conception, if a birth record references it
+
diff --git a/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.sql b/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.sql
index 4554f1d..ae7697f 100644
--- a/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.sql
+++ b/nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.sql
@@ -8,16 +8,19 @@ SELECT
c.ConceptId,
c.ConceptDate,
c.ConceptTermDate,
+ c.Estimated,
c.Sire,
CASE
WHEN b.conceptId IS NOT NULL THEN 'Live Birth'
WHEN po.conceptId IS NOT NULL THEN COALESCE(po.result, 'Unknown')
ELSE 'Unknown'
END AS conceptionOutcome,
+ b.offspring,
c.Remark,
c.QCState AS qcstate
FROM Conception c
-LEFT JOIN (SELECT DISTINCT b.conceptId FROM study.birth b WHERE b.conceptId IS NOT NULL) b
+-- a conception yields at most one birth; the aggregate only guards against duplicates the birth trigger warns about but does not block
+LEFT JOIN (SELECT b.conceptId, MAX(b.Id) AS offspring FROM study.birth b WHERE b.conceptId IS NOT NULL GROUP BY b.conceptId) b
ON b.conceptId = c.ConceptId
LEFT JOIN (SELECT p.conceptId, MAX(p.result.title) AS result FROM study.pregnancy p WHERE p.conceptId IS NOT NULL GROUP BY p.conceptId) po
ON po.conceptId = c.ConceptId
diff --git a/nbri_ehr/resources/queries/study/BehaviorClinRemarks/.qview.xml b/nbri_ehr/resources/queries/study/BehaviorClinRemarks/.qview.xml
index 4e381e4..243ffad 100644
--- a/nbri_ehr/resources/queries/study/BehaviorClinRemarks/.qview.xml
+++ b/nbri_ehr/resources/queries/study/BehaviorClinRemarks/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/ClinicalClinRemarks/.qview.xml b/nbri_ehr/resources/queries/study/ClinicalClinRemarks/.qview.xml
index c3ca1ea..86bc194 100644
--- a/nbri_ehr/resources/queries/study/ClinicalClinRemarks/.qview.xml
+++ b/nbri_ehr/resources/queries/study/ClinicalClinRemarks/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/activeBehaviorCases/.qview.xml b/nbri_ehr/resources/queries/study/activeBehaviorCases/.qview.xml
index b08797c..6026d97 100644
--- a/nbri_ehr/resources/queries/study/activeBehaviorCases/.qview.xml
+++ b/nbri_ehr/resources/queries/study/activeBehaviorCases/.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/activeClinicalCases/.qview.xml b/nbri_ehr/resources/queries/study/activeClinicalCases/.qview.xml
index b08797c..6026d97 100644
--- a/nbri_ehr/resources/queries/study/activeClinicalCases/.qview.xml
+++ b/nbri_ehr/resources/queries/study/activeClinicalCases/.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/aliases.sql b/nbri_ehr/resources/queries/study/aliases.sql
index a1b279f..4ed9962 100644
--- a/nbri_ehr/resources/queries/study/aliases.sql
+++ b/nbri_ehr/resources/queries/study/aliases.sql
@@ -15,5 +15,4 @@ FROM nbri_ehr.IdHistory
UNION
SELECT Id,
Alias as alias
-FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress'
-'
\ No newline at end of file
+FROM study.alias where Id.demographics.calculated_status != 'Alive - In Progress'
\ No newline at end of file
diff --git a/nbri_ehr/resources/queries/study/alopecia/.qview.xml b/nbri_ehr/resources/queries/study/alopecia/.qview.xml
index f889f92..b514468 100644
--- a/nbri_ehr/resources/queries/study/alopecia/.qview.xml
+++ b/nbri_ehr/resources/queries/study/alopecia/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/arrival.js b/nbri_ehr/resources/queries/study/arrival.js
index 251c651..2010ffd 100644
--- a/nbri_ehr/resources/queries/study/arrival.js
+++ b/nbri_ehr/resources/queries/study/arrival.js
@@ -40,7 +40,6 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
row.birth = row['Id/demographics/birth'] || null;
row.gender = row['Id/demographics/gender'] || null;
row.geographic_origin = row['Id/demographics/geographic_origin'] || null;
- row.source = row.sourceFacility || null;
if (row.QCStateLabel) {
row.qcstate = helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId();
diff --git a/nbri_ehr/resources/queries/study/arrival.query.xml b/nbri_ehr/resources/queries/study/arrival.query.xml
index ffe2108..0955496 100644
--- a/nbri_ehr/resources/queries/study/arrival.query.xml
+++ b/nbri_ehr/resources/queries/study/arrival.query.xml
@@ -66,7 +66,8 @@
ehr_lookupssource
- meaning
+ code
+ meaning
diff --git a/nbri_ehr/resources/queries/study/assignment.query.xml b/nbri_ehr/resources/queries/study/assignment.query.xml
index 1cf7a36..df55a2e 100644
--- a/nbri_ehr/resources/queries/study/assignment.query.xml
+++ b/nbri_ehr/resources/queries/study/assignment.query.xml
@@ -21,6 +21,18 @@
true
+
+
+ CoAssignments
+ false
+ true
+
+ study
+ assignmentTotalCoAssigned
+ lsid
+
+
diff --git a/nbri_ehr/resources/queries/study/behaviorCases/.qview.xml b/nbri_ehr/resources/queries/study/behaviorCases/.qview.xml
index b08797c..6026d97 100644
--- a/nbri_ehr/resources/queries/study/behaviorCases/.qview.xml
+++ b/nbri_ehr/resources/queries/study/behaviorCases/.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/behaviorObservations/.qview.xml b/nbri_ehr/resources/queries/study/behaviorObservations/.qview.xml
index a48d5a5..5a68b93 100644
--- a/nbri_ehr/resources/queries/study/behaviorObservations/.qview.xml
+++ b/nbri_ehr/resources/queries/study/behaviorObservations/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/birth.js b/nbri_ehr/resources/queries/study/birth.js
index e3e5fd0..cd0cce1 100644
--- a/nbri_ehr/resources/queries/study/birth.js
+++ b/nbri_ehr/resources/queries/study/birth.js
@@ -38,7 +38,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
//when updating a record that already carries this conception id, the existing row accounts for one match
var conceptIdThreshold = (oldRow && oldRow.conceptId === row.conceptId) ? 1 : 0;
if (triggerHelper.totalRecords('study', 'birth', 'conceptId', row.conceptId) > conceptIdThreshold) {
- EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by another birth record', 'INFO');
+ EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by another birth record', 'WARN');
}
if (triggerHelper.totalRecords('study', 'pregnancy', 'conceptId', row.conceptId) > 0) {
diff --git a/nbri_ehr/resources/queries/study/birth.query.xml b/nbri_ehr/resources/queries/study/birth.query.xml
index 8eccc34..18a5a92 100644
--- a/nbri_ehr/resources/queries/study/birth.query.xml
+++ b/nbri_ehr/resources/queries/study/birth.query.xml
@@ -8,11 +8,18 @@
-
-
+ Birth Date
+
+ Conception Id
+
+ nbri_ehr
+ Conception
+ ConceptId
+
+ Birth Location80
@@ -25,6 +32,25 @@
cage
+
+ Delivery Mode
+ false
+
+ ehr_lookups
+ delivery_mode
+ value
+ title
+
+
+
+ Birth Condition
+
+ ehr_lookups
+ birth_condition
+ value
+ title
+
+ Project
@@ -43,12 +69,13 @@
title
-
- Conception Id
+
+ Breeding Type
- nbri_ehr
- Conception
- ConceptId
+ ehr_lookups
+ breeding_type
+ value
+ title
diff --git a/nbri_ehr/resources/queries/study/blood/.qview.xml b/nbri_ehr/resources/queries/study/blood/.qview.xml
index 831d6b5..c382d83 100644
--- a/nbri_ehr/resources/queries/study/blood/.qview.xml
+++ b/nbri_ehr/resources/queries/study/blood/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/breeder/.qview.xml b/nbri_ehr/resources/queries/study/breeder/.qview.xml
index 448bd0f..bba85e1 100644
--- a/nbri_ehr/resources/queries/study/breeder/.qview.xml
+++ b/nbri_ehr/resources/queries/study/breeder/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/cases/.qview.xml b/nbri_ehr/resources/queries/study/cases/.qview.xml
index 340d770..a2f1fbc 100644
--- a/nbri_ehr/resources/queries/study/cases/.qview.xml
+++ b/nbri_ehr/resources/queries/study/cases/.qview.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/cases/Active Behavior Cases.qview.xml b/nbri_ehr/resources/queries/study/cases/Active Behavior Cases.qview.xml
index 8333562..7f83fe9 100644
--- a/nbri_ehr/resources/queries/study/cases/Active Behavior Cases.qview.xml
+++ b/nbri_ehr/resources/queries/study/cases/Active Behavior Cases.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/cases/Active Clinical Cases.qview.xml b/nbri_ehr/resources/queries/study/cases/Active Clinical Cases.qview.xml
index 6081418..7554046 100644
--- a/nbri_ehr/resources/queries/study/cases/Active Clinical Cases.qview.xml
+++ b/nbri_ehr/resources/queries/study/cases/Active Clinical Cases.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/cases/All Behavior Cases.qview.xml b/nbri_ehr/resources/queries/study/cases/All Behavior Cases.qview.xml
index 261b1bb..25baf96 100644
--- a/nbri_ehr/resources/queries/study/cases/All Behavior Cases.qview.xml
+++ b/nbri_ehr/resources/queries/study/cases/All Behavior Cases.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/cases/All Clinical Cases.qview.xml b/nbri_ehr/resources/queries/study/cases/All Clinical Cases.qview.xml
index 73fb0b2..e0dd66f 100644
--- a/nbri_ehr/resources/queries/study/cases/All Clinical Cases.qview.xml
+++ b/nbri_ehr/resources/queries/study/cases/All Clinical Cases.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/chemistryResults.query.xml b/nbri_ehr/resources/queries/study/chemistryResults.query.xml
index caa0e9e..154a0ae 100644
--- a/nbri_ehr/resources/queries/study/chemistryResults.query.xml
+++ b/nbri_ehr/resources/queries/study/chemistryResults.query.xml
@@ -1,7 +1,7 @@
-
+
@@ -15,6 +15,18 @@
Type
+
+
+ Ref Range
+ true
+ false
+
+ study
+ chemistryRefRange
+ lsid
+
+
diff --git a/nbri_ehr/resources/queries/study/chemistryResults/.qview.xml b/nbri_ehr/resources/queries/study/chemistryResults/.qview.xml
index 02467cb..3cc536b 100644
--- a/nbri_ehr/resources/queries/study/chemistryResults/.qview.xml
+++ b/nbri_ehr/resources/queries/study/chemistryResults/.qview.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinicalCases/.qview.xml b/nbri_ehr/resources/queries/study/clinicalCases/.qview.xml
index b08797c..6026d97 100644
--- a/nbri_ehr/resources/queries/study/clinicalCases/.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinicalCases/.qview.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinicalObservations/.qview.xml b/nbri_ehr/resources/queries/study/clinicalObservations/.qview.xml
index 7b1fc1a..0fe5c32 100644
--- a/nbri_ehr/resources/queries/study/clinicalObservations/.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinicalObservations/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinical_observations/.qview.xml b/nbri_ehr/resources/queries/study/clinical_observations/.qview.xml
index daaa82d..8d99f0c 100644
--- a/nbri_ehr/resources/queries/study/clinical_observations/.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinical_observations/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinical_observations/Alopecia Scores.qview.xml b/nbri_ehr/resources/queries/study/clinical_observations/Alopecia Scores.qview.xml
index 0a05b82..589eba9 100644
--- a/nbri_ehr/resources/queries/study/clinical_observations/Alopecia Scores.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinical_observations/Alopecia Scores.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinical_observations/Behavior.qview.xml b/nbri_ehr/resources/queries/study/clinical_observations/Behavior.qview.xml
index f7566f3..6c017a8 100644
--- a/nbri_ehr/resources/queries/study/clinical_observations/Behavior.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinical_observations/Behavior.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinical_observations/Clinical.qview.xml b/nbri_ehr/resources/queries/study/clinical_observations/Clinical.qview.xml
index adf8cf8..e8cff6b 100644
--- a/nbri_ehr/resources/queries/study/clinical_observations/Clinical.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinical_observations/Clinical.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinical_observationsSummary/.qview.xml b/nbri_ehr/resources/queries/study/clinical_observationsSummary/.qview.xml
index a48d5a5..5a68b93 100644
--- a/nbri_ehr/resources/queries/study/clinical_observationsSummary/.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinical_observationsSummary/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinremarks/.qview.xml b/nbri_ehr/resources/queries/study/clinremarks/.qview.xml
index 903f88d..d96725e 100644
--- a/nbri_ehr/resources/queries/study/clinremarks/.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinremarks/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinremarks/Behavior.qview.xml b/nbri_ehr/resources/queries/study/clinremarks/Behavior.qview.xml
index 24f5a40..007434b 100644
--- a/nbri_ehr/resources/queries/study/clinremarks/Behavior.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinremarks/Behavior.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/clinremarks/Clinical.qview.xml b/nbri_ehr/resources/queries/study/clinremarks/Clinical.qview.xml
index 6cb3771..3123f8c 100644
--- a/nbri_ehr/resources/queries/study/clinremarks/Clinical.qview.xml
+++ b/nbri_ehr/resources/queries/study/clinremarks/Clinical.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/deaths.js b/nbri_ehr/resources/queries/study/deaths.js
index 79883b4..abe7bc4 100644
--- a/nbri_ehr/resources/queries/study/deaths.js
+++ b/nbri_ehr/resources/queries/study/deaths.js
@@ -6,7 +6,6 @@
require("ehr/triggers").initScript(this);
var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
-var validIds = [];
var idMap = {};
var deathIdMap = {};
@@ -26,9 +25,7 @@ function onInit(event, helper){
return;
for(var i=0; i < results.rows.length; i++) {
- validIds.push(results.rows[i]["Id"]["value"])
idMap[results.rows[i]["Id"]["value"]] = {calculated_status: results.rows[i]["calculated_status"]["value"], QCStateLabel: results.rows[i]["QCState/Label"]["value"]};
- // console.log(idMap[results.rows[i]["Id"]["value"]]);
}
},
failure: function (error) {
@@ -84,13 +81,27 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
//only allow death record to be created if the animal is in the demographics table
if (idMap[row.Id]) {
+ // deathIdMap has no entry for the animal on initial import, and any of these values can be null
+ var status = idMap[row.Id].calculated_status ? idMap[row.Id].calculated_status.toUpperCase() : null;
+ var priorDeathQCState = deathIdMap[row.Id] && deathIdMap[row.Id].QCStateLabel ? deathIdMap[row.Id].QCStateLabel.toUpperCase() : null;
+ var rowQCState = row.QCStateLabel ? row.QCStateLabel.toUpperCase() : null;
+
+ // deathIdMap is a snapshot taken before any row was processed, so it cannot see earlier rows of this same
+ // save. Track them separately: study.deaths is demographic, so a second row for one animal cannot be saved.
+ var deathsInTransaction = helper.getProperty('deathsInTransaction') || {};
+
+ var errorMsg = null;
+
// check if a death record already exists for this animal
- if (idMap[row.Id].calculated_status.toUpperCase() === 'DEAD' && deathIdMap[row.Id].QCStateLabel.toUpperCase() === 'COMPLETED') {
- EHR.Server.Utils.addError(scriptErrors, 'Id', 'Death record already exists for this animal.', 'ERROR');
+ if (status === 'DEAD' && priorDeathQCState === 'COMPLETED') {
+ errorMsg = 'Death record already exists for this animal.';
}
// check if the animal is at the center
- else if (idMap[row.Id].calculated_status.toUpperCase() === 'SHIPPED') {
- EHR.Server.Utils.addError(scriptErrors, 'Id', 'Animal is not at the center.', 'ERROR');
+ else if (status === 'SHIPPED') {
+ errorMsg = 'Animal is not at the center.';
+ }
+ else if (deathsInTransaction[row.Id]) {
+ errorMsg = 'This animal is entered more than once. Only one death record per animal can be saved.';
}
// Check if an animal that's being entered is pending any request/review.
// Note 1: When trying to enter a new record for an animal, the QCState = 'IN PROGRESS'.
@@ -98,23 +109,28 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
// the QCState will get set to 'Review Required' - this way we can distinguish between the two states in the Death/Necropsy workflow.
// If a user tries to submit a new Death record (identified by QCState = 'IN PROGRESS') for an animal that
// already has a pending request/review status in study.deaths, then below error message will be displayed.
- else if (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' &&
- deathIdMap[row.Id] && deathIdMap[row.Id].QCStateLabel &&
- (deathIdMap[row.Id].QCStateLabel.toUpperCase() === 'REQUEST: PENDING' ||
- deathIdMap[row.Id].QCStateLabel.toUpperCase() === 'REVIEW REQUIRED')) {
- EHR.Server.Utils.addError(scriptErrors, 'Id', 'Death record is pending review for this animal', 'ERROR');
+ else if (rowQCState === 'IN PROGRESS' &&
+ (priorDeathQCState === 'REQUEST: PENDING' || priorDeathQCState === 'REVIEW REQUIRED')) {
+ errorMsg = 'Death record is pending review for this animal';
}
// if 'Save Draft' record already exists, it doesn't allow to 'Save Draft' or 'Submit Death'
// on the same animal again - throws an error "duplicate key value violates unique constraint"
// So, added this check to allow 'Save Draft' record to be saved only once.
- else if (oldRow === undefined && row.QCStateLabel.toUpperCase() === 'IN PROGRESS' &&
- deathIdMap[row.Id] && deathIdMap[row.Id].QCStateLabel &&
- deathIdMap[row.Id].QCStateLabel.toUpperCase() === 'IN PROGRESS') {
- EHR.Server.Utils.addError(scriptErrors, 'Id', 'Death/Necropsy data entry is in progress for this animal', 'ERROR');
+ else if (oldRow === undefined && rowQCState === 'IN PROGRESS' && priorDeathQCState === 'IN PROGRESS') {
+ errorMsg = 'Death/Necropsy data entry is in progress for this animal';
+ }
+ // study.deaths is demographic (one row per animal), so any other new row for an animal with an existing
+ // record would fail on the unique constraint; report it as a validation error instead. Test record
+ // existence, not QC state: ETL/import-sourced rows can carry a null QCState.
+ else if (oldRow === undefined && deathIdMap[row.Id]) {
+ errorMsg = 'A death record already exists for this animal (' + (deathIdMap[row.Id].QCStateLabel || 'unknown state') + ').';
}
- else if (!helper.isValidateOnly() && row.Id && row.date && row.QCStateLabel.toUpperCase() === 'COMPLETED') {
- if (validIds.indexOf(row.id) !== -1) {
+ if (errorMsg) {
+ EHR.Server.Utils.addError(scriptErrors, 'Id', errorMsg, 'ERROR');
+ }
+ else {
+ if (!helper.isValidateOnly() && row.Id && row.date && rowQCState === 'COMPLETED') {
// update demographics
demographicsUpdates.push({
@@ -128,26 +144,33 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
helper.getJavaHelper().updateDemographicsRecord(demographicsUpdates);
console.log('updated demographics death date for animal: ' + row.Id);
}
- else {
- console.log(row.id + " is not a valid animal id");
+
+ if (!helper.isValidateOnly() && row.date && row.QCStateLabel && EHR.Server.Security.getQCStateByLabel(row.QCStateLabel).PublicData) {
+ var qcstate = helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId();
+
+ //add/update weight record
+ var weightRecord = {
+ Id: row.Id,
+ date: row.date,
+ weight: row.deathWeight,
+ taskid: row.taskid,
+ qcstate: qcstate,
+ performedby: row.performedby
+ };
+ if (triggerHelper.upsertWeightRecord(weightRecord, false)) {
+ helper.addTableModified('study', 'weight');
+ }
}
- }
- if(row.QCStateLabel && EHR.Server.Security.getQCStateByLabel(row.QCStateLabel).PublicData) {
- var qcstate = helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId();
-
- //add/update weight record
- var weightRecord = {
- Id: row.Id,
- date: row.date,
- weight: row.deathWeight,
- taskid: row.taskid,
- qcstate: qcstate,
- performedby: row.performedby
- };
- triggerHelper.upsertWeightRecord(weightRecord);
+ // mark only rows that passed, so a duplicate of a failed row reports that row's underlying error
+ deathsInTransaction[row.Id] = true;
+ helper.setProperty('deathsInTransaction', deathsInTransaction);
}
}
+ // insert-only: updates of existing death records keep their prior behavior
+ else if (oldRow === undefined) {
+ EHR.Server.Utils.addError(scriptErrors, 'Id', 'Id not found in the demographics table.', 'ERROR');
+ }
}
}
diff --git a/nbri_ehr/resources/queries/study/deaths.query.xml b/nbri_ehr/resources/queries/study/deaths.query.xml
index 35c2e6a..e28e2f0 100644
--- a/nbri_ehr/resources/queries/study/deaths.query.xml
+++ b/nbri_ehr/resources/queries/study/deaths.query.xml
@@ -7,6 +7,15 @@
Death Date
+
+ Death Type
+
+ ehr_lookups
+ death_type
+ value
+ title
+
+ Disposition
diff --git a/nbri_ehr/resources/queries/study/deaths/.qview.xml b/nbri_ehr/resources/queries/study/deaths/.qview.xml
index fdc063c..56eecec 100644
--- a/nbri_ehr/resources/queries/study/deaths/.qview.xml
+++ b/nbri_ehr/resources/queries/study/deaths/.qview.xml
@@ -6,6 +6,7 @@
+
diff --git a/nbri_ehr/resources/queries/study/demographics.query.xml b/nbri_ehr/resources/queries/study/demographics.query.xml
index bff3d17..f6fafa6 100644
--- a/nbri_ehr/resources/queries/study/demographics.query.xml
+++ b/nbri_ehr/resources/queries/study/demographics.query.xml
@@ -99,9 +99,6 @@
meaning
-
- Source
- CITES
diff --git a/nbri_ehr/resources/queries/study/demographics/.qview.xml b/nbri_ehr/resources/queries/study/demographics/.qview.xml
index 56f1f23..d232062 100644
--- a/nbri_ehr/resources/queries/study/demographics/.qview.xml
+++ b/nbri_ehr/resources/queries/study/demographics/.qview.xml
@@ -4,7 +4,7 @@
-
+
@@ -12,7 +12,6 @@
-
diff --git a/nbri_ehr/resources/queries/study/demographicsCagemates.sql b/nbri_ehr/resources/queries/study/demographicsCagemates.sql
index b3464b7..4219925 100644
--- a/nbri_ehr/resources/queries/study/demographicsCagemates.sql
+++ b/nbri_ehr/resources/queries/study/demographicsCagemates.sql
@@ -22,10 +22,15 @@ SELECT
FROM study.housing h
JOIN study.housing h2
-ON (h2.Id.demographics.calculated_status = 'Alive'
- AND (h.cage = h2.cage))
+-- cage holds a location key that already encodes the room, so caged animals match on cage alone. Group/pen rooms have
+-- no cage, so those fall back to the room, which is only consulted when neither side has a cage.
+ON ((h.cage = h2.cage OR (h.cage IS NULL AND h2.cage IS NULL AND h.room = h2.room))
+ AND h2.Id.demographics.calculated_status = 'Alive'
+ AND h2.enddateTimeCoalesced >= now()
+ AND h2.qcstate.publicdata = true)
WHERE h.enddateTimeCoalesced >= now()
+AND h.qcstate.publicdata = true
GROUP BY h.id, h.room, h.cage
) t ON (t.id = d.id)
diff --git a/nbri_ehr/resources/queries/study/demographicsSource.sql b/nbri_ehr/resources/queries/study/demographicsSource.sql
index 9de9dfd..6ee341e 100644
--- a/nbri_ehr/resources/queries/study/demographicsSource.sql
+++ b/nbri_ehr/resources/queries/study/demographicsSource.sql
@@ -17,7 +17,7 @@ SELECT
WHEN T1.EarliestArrival IS NULL AND d.birth IS NOT NULL THEN true
ELSE false
END as fromCenter,
- d.source as source,
+ T2.sourceFacility as source,
CASE
WHEN T1.EarliestArrival IS NULL AND d.birth IS NOT NULL THEN 'Born at NBRI'
diff --git a/nbri_ehr/resources/queries/study/departure.query.xml b/nbri_ehr/resources/queries/study/departure.query.xml
index 19845d1..5955592 100644
--- a/nbri_ehr/resources/queries/study/departure.query.xml
+++ b/nbri_ehr/resources/queries/study/departure.query.xml
@@ -13,7 +13,8 @@
ehr_lookupssource
- meaning
+ code
+ meaning
diff --git a/nbri_ehr/resources/queries/study/drug/.qview.xml b/nbri_ehr/resources/queries/study/drug/.qview.xml
index 3b72268..8489e4d 100644
--- a/nbri_ehr/resources/queries/study/drug/.qview.xml
+++ b/nbri_ehr/resources/queries/study/drug/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/drug/Behavior.qview.xml b/nbri_ehr/resources/queries/study/drug/Behavior.qview.xml
index a9769cb..1688ad3 100644
--- a/nbri_ehr/resources/queries/study/drug/Behavior.qview.xml
+++ b/nbri_ehr/resources/queries/study/drug/Behavior.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/exemptions/.qview.xml b/nbri_ehr/resources/queries/study/exemptions/.qview.xml
index 7e4278b..cdd0721 100644
--- a/nbri_ehr/resources/queries/study/exemptions/.qview.xml
+++ b/nbri_ehr/resources/queries/study/exemptions/.qview.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/nbri_ehr/resources/queries/study/flags.query.xml b/nbri_ehr/resources/queries/study/flags.query.xml
index 570a645..00a8119 100644
--- a/nbri_ehr/resources/queries/study/flags.query.xml
+++ b/nbri_ehr/resources/queries/study/flags.query.xml
@@ -23,8 +23,8 @@
ehr_lookupsflag_values
- objectid
- value
+ value
+ Description
diff --git a/nbri_ehr/resources/queries/study/flags/.qview.xml b/nbri_ehr/resources/queries/study/flags/.qview.xml
index bf12e57..3f15f5b 100644
--- a/nbri_ehr/resources/queries/study/flags/.qview.xml
+++ b/nbri_ehr/resources/queries/study/flags/.qview.xml
@@ -2,12 +2,12 @@
-
+
-
+
diff --git a/nbri_ehr/resources/queries/study/housing.query.xml b/nbri_ehr/resources/queries/study/housing.query.xml
index eeb5e0d..e1a21a3 100644
--- a/nbri_ehr/resources/queries/study/housing.query.xml
+++ b/nbri_ehr/resources/queries/study/housing.query.xml
@@ -21,7 +21,6 @@
ehr_lookupscagelocation
- cage
@@ -31,7 +30,7 @@
ehr_lookupsroomsroom
- name
+ room
@@ -45,6 +44,19 @@
+
+
+ Total Cagemates
+ false
+ true
+
+ study
+ housingTotalRoommates
+ lsid
+
+
-
-
- varchar
- http://cpas.labkey.com/Study#ParticipantId
-
- ptid
-
-
-
- timestamp
- http://cpas.labkey.com/Study#VisitDate
- http://cpas.labkey.com/Study#VisitDate
-
-
- varchar
-
-
- varchar
-
-
- Historical Other
- Captures miscellaneous historical health and research records for primates that do not fit other specific categories.
-