Skip to content

Commit

Permalink
fix: fix ProgramDataElement and TrackedEntityAttibute type definition…
Browse files Browse the repository at this point in the history
… according to DHIS. Map formName and code undefineds to empty strings and emit console.warn about it.

Revert Codec utils since it's not needed to validate the DHIS api response
  • Loading branch information
MatiasArriola committed Dec 19, 2024
1 parent ace4a78 commit 452d11d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 195 deletions.
7 changes: 2 additions & 5 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-19T11:55:32.909Z\n"
"PO-Revision-Date: 2024-12-19T11:55:32.909Z\n"

msgid "There was a problem with {{dataElementErrorIdentifiers}}"
msgstr ""
"POT-Creation-Date: 2024-12-19T15:42:35.172Z\n"
"PO-Revision-Date: 2024-12-19T15:42:35.172Z\n"

msgid "Facilities"
msgstr ""
Expand Down
5 changes: 1 addition & 4 deletions i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-12-19T11:55:32.909Z\n"
"POT-Creation-Date: 2024-12-19T15:42:35.172Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"

msgid "There was a problem with {{dataElementErrorIdentifiers}}"
msgstr ""

msgid "Facilities"
msgstr ""

Expand Down
19 changes: 4 additions & 15 deletions src/data/entities/D2Program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Id } from "../../domain/entities/Ref";
import { Codec, Schema } from "../../utils/codec";

export type ProgramRuleActionType =
| "DISPLAYTEXT"
Expand Down Expand Up @@ -43,25 +42,15 @@ export interface ProgramStage {
}

export interface ProgramDataElement {
code: string;
code?: string;
id: string;
name: string;
formName: string;
formName?: string;
valueType: string;
optionSet?: { id: string };
sortOrder?: number | undefined;
}

export const ProgramDataElementModel: Codec<ProgramDataElement> = Schema.object({
code: Schema.string,
id: Schema.string,
name: Schema.string,
formName: Schema.string,
valueType: Schema.string,
optionSet: Schema.optional(Schema.object({ id: Schema.string })),
sortOrder: Schema.optional(Schema.number),
});

export interface OptionSet {
id: string;
name: string;
Expand All @@ -78,9 +67,9 @@ export interface Option {

export interface TrackedEntityAttibute {
id: string;
code: string;
code?: string;
name: string;
formName: string;
formName?: string;
sortOrder: number;
valueType: string;
optionSet?: { id: string };
Expand Down
6 changes: 0 additions & 6 deletions src/data/repositories/SurveyFormD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { Questionnaire } from "../../domain/entities/Questionnaire/Questionnaire
import { ASTGUIDELINE_TYPES } from "../../domain/entities/ASTGuidelines";
import { getSurveyChildCount, SurveyChildCountType } from "../utils/surveyChildCountHelper";
import { TrackerPostResponse } from "@eyeseetea/d2-api/api/tracker";
import { validateDataElements } from "../utils/validationHelper";

const OU_CHUNK_SIZE = 500;
export class SurveyD2Repository implements SurveyRepository {
Expand Down Expand Up @@ -90,11 +89,6 @@ export class SurveyD2Repository implements SurveyRepository {
};
});

const dataElementErrors = validateDataElements(dataElementsWithSortOrder);
if (dataElementErrors) {
return Future.error(new Error(dataElementErrors));
}

const sortedTrackedentityAttr = resp.programTrackedEntityAttributes
? _(
_(resp.programTrackedEntityAttributes)
Expand Down
17 changes: 10 additions & 7 deletions src/data/utils/questionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ const SPECIES_QUESTION_FORNAME = "Specify the specie";
const ANTIBIOTIC_QUESTION_FORNAME = "Specify the antibiotic";
const getQuestionBase = (
id: Id,
code: string,
code: string | undefined,
name: string,
formName: string,
formName: string | undefined,
sortOrder: number | undefined
): QuestionBase => {
if (formName === undefined || code === undefined) {
console.debug("formName or code undefined. Defaulting to ''", { id, name, code, formName });
}
return {
id: id,
code: code, //code
code: code ?? "",
name: name,
text: formName, //formName
text: formName ?? "",
isVisible: true,
sortOrder: sortOrder,
errors: [],
Expand Down Expand Up @@ -81,9 +84,9 @@ const getSelectQuestionBase = (
export const getQuestion = (
valueType: string,
id: Id,
code: string,
code: string | undefined,
name: string,
formName: string,
formName: string | undefined,
sortOrder: number | undefined,
options: Option[],
optionSet?: { id: string },
Expand Down Expand Up @@ -128,7 +131,7 @@ export const getQuestion = (
case "EMAIL":
case "TEXT": {
if (optionSet) {
const isSpeciesQuestion = formName.includes(SPECIES_QUESTION_FORNAME);
const isSpeciesQuestion = formName?.includes(SPECIES_QUESTION_FORNAME) ?? false;
const isAntibioticQuestion = name.startsWith(ANTIBIOTIC_QUESTION_FORNAME);

const selectBase = getSelectQuestionBase(base, options, optionSet, dataValue);
Expand Down
20 changes: 0 additions & 20 deletions src/data/utils/validationHelper.ts

This file was deleted.

126 changes: 0 additions & 126 deletions src/utils/codec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/utils/validations.ts

This file was deleted.

0 comments on commit 452d11d

Please sign in to comment.