Skip to content

Commit

Permalink
feat: return descriptions for HWCR export (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilcox authored Nov 26, 2024
1 parent fe37b29 commit d7b0652
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 37 deletions.
156 changes: 135 additions & 21 deletions backend/src/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ActionInput } from "./dto/action-input";
@Injectable()
export class CaseFileService {
constructor(
private prisma: PrismaService,
private readonly prisma: PrismaService,
private readonly caseFileActionService: CaseFileActionService,
) {}

Expand Down Expand Up @@ -337,18 +337,78 @@ export class CaseFileService {
select: {
wildlife_guid: true,
species_code: true,
age_code: true,
sex_code: true,
age_code_wildlife_age_codeToage_code: {
select: {
age_code: true,
short_description: true,
},
},
sex_code_wildlife_sex_codeTosex_code: {
select: {
sex_code: true,
short_description: true,
},
},
identifying_features: true,
threat_level_code: true,
hwcr_outcome_code: true,
threat_level_code_wildlife_threat_level_codeTothreat_level_code: {
select: {
threat_level_code: true,
short_description: true,
},
},
hwcr_outcome_code_wildlife_hwcr_outcome_codeTohwcr_outcome_code: {
select: {
hwcr_outcome_code: true,
short_description: true,
},
},
create_utc_timestamp: true,
drug_administered: {
select: {
drug_administered_guid: true,
wildlife_guid: true,
drug_code_drug_administered_drug_codeTodrug_code: {
select: {
drug_code: true,
short_description: true,
},
},
drug_method_code_drug_administered_drug_method_codeTodrug_method_code: {
select: {
drug_method_code: true,
short_description: true,
},
},
drug_remaining_outcome_code_drug_administered_drug_remaining_outcome_codeTodrug_remaining_outcome_code:
{
select: {
drug_remaining_outcome_code: true,
short_description: true,
},
},
vial_number: true,
drug_used_amount: true,
additional_comments_text: true,
create_utc_timestamp: true,
},
where: {
active_ind: true,
},
},
ear_tag: {
select: {
ear_tag_guid: true,
wildlife_guid: true,
ear_code_ear_tag_ear_codeToear_code: {
select: {
ear_code: true,
short_description: true,
},
},
ear_tag_identifier: true,
create_utc_timestamp: true,
},
where: {
active_ind: true,
},
Expand Down Expand Up @@ -1604,8 +1664,27 @@ export class CaseFileService {
private findEquipmentDetails = async (caseIdentifier: string): Promise<Equipment[]> => {
const actions = await this.prisma.action.findMany({
where: { case_guid: caseIdentifier },
include: {
equipment: true,
select: {
action_type_action_xref_guid: true,
action_guid: true,
actor_guid: true,
action_date: true,
active_ind: true,
equipment: {
select: {
equipment_guid: true,
active_ind: true,
equipment_code: true,
equipment_location_desc: true,
create_utc_timestamp: true,
was_animal_captured: true,
equipment_code_equipment_equipment_codeToequipment_code: {
select: {
short_description: true,
},
},
},
},
},
});

Expand Down Expand Up @@ -1670,6 +1749,7 @@ export class CaseFileService {
({
id: equipment.equipment_guid,
typeCode: equipment.equipment_code,
typeDescription: equipment.equipment_code_equipment_equipment_codeToequipment_code.short_description,
activeIndicator: equipment.active_ind,
address: equipment.equipment_location_desc,
xCoordinate: longitudeString,
Expand Down Expand Up @@ -1715,26 +1795,46 @@ export class CaseFileService {
const {
wildlife_guid: id,
species_code: species,
sex_code: sex,
age_code: age,
threat_level_code: categoryLevel,
sex_code_wildlife_sex_codeTosex_code: sexObject,
age_code_wildlife_age_codeToage_code: ageObject,
threat_level_code_wildlife_threat_level_codeTothreat_level_code: categoryLevelObject,
identifying_features: identifyingFeatures,
hwcr_outcome_code: outcome,
hwcr_outcome_code_wildlife_hwcr_outcome_codeTohwcr_outcome_code: outcomeObject,
ear_tag,
drug_administered,
action,
} = item;

const sex = sexObject?.sex_code;
const sexDescription = sexObject?.short_description;

const age = ageObject?.age_code;
const ageDescription = ageObject?.short_description;

const categoryLevel = categoryLevelObject?.threat_level_code;
const categoryLevelDescription = categoryLevelObject?.short_description;

const outcome = outcomeObject?.hwcr_outcome_code;
const outcomeDescription = outcomeObject?.short_description;

const tags = ear_tag
.sort((a, b) => a.create_utc_timestamp.getTime() - b.create_utc_timestamp.getTime())
.map(({ ear_tag_guid: id, ear_code: ear, ear_tag_identifier: identifier }, idx) => {
return {
id,
ear,
identifier,
order: idx + 1,
};
});
.map(
(
{ ear_tag_guid: id, ear_code_ear_tag_ear_codeToear_code: earObject, ear_tag_identifier: identifier },
idx,
) => {
const ear = earObject?.ear_code;
const earDescription = earObject?.short_description;
return {
id,
ear,
earDescription,
identifier,
order: idx + 1,
};
},
);

const drugs = drug_administered
.sort((a, b) => a.create_utc_timestamp.getTime() - b.create_utc_timestamp.getTime())
Expand All @@ -1743,21 +1843,31 @@ export class CaseFileService {
{
drug_administered_guid: id,
vial_number: vial,
drug_code: drug,
drug_code_drug_administered_drug_codeTodrug_code: drugObject,
drug_method_code_drug_administered_drug_method_codeTodrug_method_code: drugMethodObject,
drug_remaining_outcome_code_drug_administered_drug_remaining_outcome_codeTodrug_remaining_outcome_code:
drugRemainingObject,
drug_used_amount: amountUsed,
drug_method_code: injectionMethod,
drug_remaining_outcome_code: remainingUse,
additional_comments_text: additionalComments,
},
idx,
) => {
const drug = drugObject?.drug_code;
const drugDescription = drugObject?.short_description;
const injectionMethod = drugMethodObject?.drug_method_code;
const injectionMethodDescription = drugMethodObject?.short_description;
const remainingUse = drugRemainingObject?.drug_remaining_outcome_code;
const remainingUseDescription = drugRemainingObject?.short_description;
return {
id,
vial,
drug,
drugDescription,
amountUsed,
injectionMethod,
injectionMethodDescription,
remainingUse,
remainingUseDescription,
additionalComments,
order: idx + 1,
};
Expand Down Expand Up @@ -1791,10 +1901,14 @@ export class CaseFileService {
id,
species,
sex,
sexDescription,
age,
ageDescription,
categoryLevel,
categoryLevelDescription,
identifyingFeatures,
outcome,
outcomeDescription,
order: idx + 1,
};

Expand Down
9 changes: 9 additions & 0 deletions backend/src/case_file/case_file_types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Note {
type EquipmentDetails {
id: String
typeCode: String
typeDescription: String
activeIndicator: Boolean
address: String
xCoordinate: String
Expand All @@ -59,10 +60,14 @@ type Wildlife {
id: String
species: String!
sex: String
sexDescription: String
age: String
ageDescription: String
categoryLevel: String
categoryLevelDescription: String
identifyingFeatures: String
outcome: String
outcomeDescription: String
tags: [EarTag]
drugs: [Drug]
actions: [CaseFileAction]
Expand All @@ -72,6 +77,7 @@ type Wildlife {
type EarTag {
id: String
ear: String
earDescription: String
identifier: String
order: Int
}
Expand All @@ -80,9 +86,12 @@ type Drug {
id: String
vial: String
drug: String
drugDescription: String
amountUsed: String
injectionMethod: String
injectionMethodDescription: String
remainingUse: String
remainingUseDescription: String
additionalComments: String
order: Int
}
Expand Down
46 changes: 32 additions & 14 deletions backend/src/case_file/dto/subject-query-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,54 @@ export interface SubjectQueryResult {
action_date: Date;
}[];
wildlife_guid: string;
threat_level_code: string;
threat_level_code_wildlife_threat_level_codeTothreat_level_code: {
threat_level_code: string;
short_description: string;
};
identifying_features: string;
sex_code: string;
age_code: string;
hwcr_outcome_code: string;
sex_code_wildlife_sex_codeTosex_code: {
sex_code: string;
short_description: string;
};
age_code_wildlife_age_codeToage_code: {
age_code: string;
short_description: string;
};
hwcr_outcome_code_wildlife_hwcr_outcome_codeTohwcr_outcome_code: {
hwcr_outcome_code: string;
short_description: string;
};
species_code: string;
create_utc_timestamp: Date;
drug_administered: {
drug_administered_guid: string;
wildlife_guid: string;
drug_code: string;
drug_method_code: string;
drug_remaining_outcome_code: string;
drug_code_drug_administered_drug_codeTodrug_code: {
drug_code: string;
short_description: string;
};
drug_method_code_drug_administered_drug_method_codeTodrug_method_code: {
drug_method_code: string;
short_description: string;
};
drug_remaining_outcome_code_drug_administered_drug_remaining_outcome_codeTodrug_remaining_outcome_code: {
drug_remaining_outcome_code: string;
short_description: string;
};
vial_number: string;
drug_used_amount: string;
additional_comments_text: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
update_utc_timestamp: Date;
}[];
ear_tag: {
ear_tag_guid: string;
wildlife_guid: string;
ear_code: string;
ear_code_ear_tag_ear_codeToear_code: {
ear_code: string;
short_description: string;
};
ear_tag_identifier: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
update_utc_timestamp: Date;
}[];
}[];
}
10 changes: 8 additions & 2 deletions backend/src/case_file/entities/wildlife-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export interface Wildlife {
id: string;
species: string;
sex?: string;
sexDescription?: string;
age?: string;
ageDescription?: string;
categoryLevel?: string;
categoryLevelDescription?: string;
identifyingFeatures?: string;
outcome?: string;
outcomeDescription?: string;
tags?: Array<EarTag>;
drugs?: Array<DrugUsed>;
actions?: Array<CaseFileAction>;
Expand All @@ -17,17 +21,19 @@ export interface Wildlife {
export interface EarTag {
id: string;
ear: string;
earDescription: string;
identifier: string;
}

export interface DrugUsed {
id: string;

vial: string;
drug: string;
drugDescription: string;
amountUsed: string;
injectionMethod: string;

injectionMethodDescription: string;
remainingUse?: string;
remainingUseDescription?: string;
additionalComments?: string;
}

0 comments on commit d7b0652

Please sign in to comment.