Skip to content

Commit

Permalink
Merge pull request #21 from jy95/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
jy95 authored Apr 5, 2024
2 parents 9fa0919 + c124e38 commit ed62f55
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 31 deletions.
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
64 changes: 44 additions & 20 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ export class FhirDosageUtils {
}

/**
* Turn multiple FHIR Dosage object into text
* Does this array of Dosage objects contains only "sequential" instructions ?
*/
fromMultipleDosageToText(dosages: Dosage[]): string {
// As we can have concurrent / sequential instructions, we need a generic algorithm to do the job

containsOnlySequentialInstructions(dosages: Dosage[]): boolean {
// 1. Collect all sequences number
let sequencesNumbers = dosages
.map((d) => d.sequence)
Expand All @@ -222,16 +220,19 @@ export class FhirDosageUtils {
// 3. We have a "sequential" situation in two cases
// A) No sequence number were provided
// B) All sequence numbers are different
if (
return (
encounteredSequenceNumbers.size === 0 ||
encounteredSequenceNumbers.size === dosages.length
) {
const dosagesAsText = dosages.map((d) => this.fromDosageToText(d));
return fromListToString(this.i18nInstance, dosagesAsText, "then");
}
);
}

// 4. We have both "sequential" and "concurrent" instructions - time to see what is the configuration
let groups: Record<number, string[]> = {};
/**
* Turn this array of Dosage objects into a data structure useful to handle "sequential" and "concurrent" instructions (cf. "sequence" property).
* @returns {Dosage[][]} - A two-dimensional array where each inner array contains Dosage objects belonging to the same sequence numberr.
*/
groupBySequence(dosages: Dosage[]) {
// Prepare variables
let groups: Record<number, Dosage[]> = {};
let sequences = new Set<number>();

for (let idx = 0; idx < dosages.length; idx++) {
Expand All @@ -242,14 +243,11 @@ export class FhirDosageUtils {
// If no sequence number, assume it is idx + 1
let sequenceNr = dosage.sequence || idx + 1;

// Generate the text version
let dosageAsText = this.fromDosageToText(dosage);

// Retrieve of create previous entries for this sequence number
let localGroup = groups[sequenceNr] || [];

// Add entry
localGroup.push(dosageAsText);
localGroup.push(dosage);

// Pushback result
groups[sequenceNr] = localGroup;
Expand All @@ -258,13 +256,39 @@ export class FhirDosageUtils {
sequences.add(sequenceNr);
}

// 5. Now that data structures are filled, it is a piece of cake to generate the result
let sequentialInstructions: string[] = [...sequences.values()].map(
(sequence) => {
let concurrentInstructions = groups[sequence];
// By using the Set values, we are sure it is returned in the way Dosages were written
return [...sequences.values()].map((sequence) => {
let concurrentInstructions = groups[sequence];
return concurrentInstructions;
});
}

/**
* Turn multiple FHIR Dosage objects into text
*/
fromMultipleDosageToText(dosages: Dosage[]): string {
// As we can have concurrent / sequential instructions, we need a generic algorithm to do the job
const hasOnlySequentialInstructions =
this.containsOnlySequentialInstructions(dosages);

// Sequential instructions
if (hasOnlySequentialInstructions) {
const dosagesAsText = dosages.map((d) => this.fromDosageToText(d));
return fromListToString(this.i18nInstance, dosagesAsText, "then");
}

// We have both "sequential" and "concurrent" instructions - time to see what is the configuration
let sortedDosages = this.groupBySequence(dosages);

// Now that data structures are filled, it is a piece of cake to generate the result
let sequentialInstructions: string[] = sortedDosages.map(
(concurrentInstructions) => {
let concurrentInstructionsAsString = concurrentInstructions.map(
(dosage) => this.fromDosageToText(dosage),
);
return fromListToString(
this.i18nInstance,
concurrentInstructions,
concurrentInstructionsAsString,
"and",
);
},
Expand Down

0 comments on commit ed62f55

Please sign in to comment.