generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
584 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Maybe } from "$/utils/ts-utils"; | ||
import { NamedRef } from "@eyeseetea/d2-logger/domain/entities/Base"; | ||
import { convertToNumberOrZero } from "../usecases/common/utils"; | ||
import { DataElement } from "./DataElement"; | ||
import { DataValue } from "./DataValue"; | ||
import { Struct } from "./generic/Struct"; | ||
import { Id, Period } from "./Ref"; | ||
|
||
type MidwiferyNursingAttrs = { | ||
midwifery: MidwiferyNursingValue; | ||
personnel: MidwiferyNursingValue; | ||
isMidwiferyGreater: boolean; | ||
period: Period; | ||
countryId: Id; | ||
combination: NamedRef; | ||
}; | ||
|
||
type MidwiferyNursingValue = { | ||
dataElement: DataElement; | ||
dataValue: Maybe<DataValue>; | ||
}; | ||
|
||
export class MidwiferyNursing extends Struct<MidwiferyNursingAttrs>() { | ||
static build(data: MidwiferyNursingAttrs): MidwiferyNursing { | ||
return this.create({ | ||
...data, | ||
isMidwiferyGreater: this.checkIfMidwiferyIsGreater(data.midwifery, data.personnel), | ||
}); | ||
} | ||
|
||
private static checkIfMidwiferyIsGreater( | ||
midwifery: MidwiferyNursingValue, | ||
nursing: MidwiferyNursingValue | ||
): boolean { | ||
if (!midwifery.dataValue && !nursing.dataValue) return false; | ||
|
||
const midwiferyValue = convertToNumberOrZero(midwifery.dataValue?.value); | ||
const nursingValue = convertToNumberOrZero(nursing.dataValue?.value); | ||
|
||
return midwiferyValue > nursingValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/domain/usecases/GetMidwiferyPersonnelDisaggregationsUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Id } from "$/domain/entities/Ref"; | ||
import { SectionDisaggregation } from "$/domain/entities/Settings"; | ||
import { SettingsRepository } from "$/domain/repositories/SettingsRepository"; | ||
import { Future } from "$/domain/entities/generic/Future"; | ||
import _ from "$/domain/entities/generic/Collection"; | ||
import { FutureData } from "$/data/api-futures"; | ||
|
||
export class GetMidwiferyPersonnelDisaggregationsUseCase { | ||
constructor(private settingsRepository: SettingsRepository) {} | ||
|
||
execute(sectionId: Id): FutureData<SectionDisaggregation[]> { | ||
return this.settingsRepository.get().flatMap(settings => { | ||
const section = settings.sections.find(section => section.id === sectionId); | ||
if (!section) | ||
return Future.error(new Error(`Cannot found section settings: ${sectionId}`)); | ||
const disaggregationsSorted = _(section.disaggregations) | ||
.sortBy(disaggregation => disaggregation.name) | ||
.value(); | ||
return Future.success(disaggregationsSorted); | ||
}); | ||
} | ||
} |
Oops, something went wrong.