Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new script] [programs] Copy data values from old data elements to new data elements on specific tracker program's program stage #67

Open
wants to merge 16 commits into
base: development
Choose a base branch
from

Conversation

p3rcypj
Copy link

@p3rcypj p3rcypj commented Jan 5, 2025

📌 References

📝 Implementation

Added script in order to copy data values from certain program stage without modyifing old values. It should just add new data values with same properties but with the data element id as the target data element specified (from the pair specified)

Source_DE1 ➝ Target_DE3
Source_DE2 ➝ Target_DE4

🔥 Testing

yarn start:dev programs copy-data-values \
    --url=http://$DHIS2_USER:$DHIS2_PASSWORD@localhost:8080 \
    --program-stage-id=sgSKZRoWE9b \
    --save-report='./copy-data-values-report.txt' \
    qwfxR2TQkUn-L5x9z9BAgR8 \
    N0p2yOsEy7a-wSCh46cADN6 \
    R1MphCO50la-DrTaMDJAQoS \
    FHBb7rMzYEL-s8hgq0Y8SJs

PS.: add --post to send the payload

Docker: docker.eyeseetea.com/ocg/dhis2-data:2.37.8-pro

Added tests using Copilot Edits:

  • should copy data values successfully
  • should throw error if data element types do not match
  • should throw error if some data elements are missing
  • should throw error if target data values are not empty
  • should return empty array if there is no data value with some source data element id

@p3rcypj p3rcypj requested review from tokland and adrianq January 5, 2025 11:45
@p3rcypj
Copy link
Author

p3rcypj commented Jan 5, 2025

Not sure on which section should I add an example of this script on the README

Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-line comments:

src/data/DataElementsD2Repository.ts Outdated Show resolved Hide resolved
filter: { id: { in: ids } },
},
});

const { dataElements } = await metadata$.getData();
const dataElements = (await metadata$.getData()).dataElements;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why that change? the original looks more declarative to me

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed to me also. I made the change while testing because it was more comfortable for me but I forgot to reverse it

src/domain/usecases/CopyProgramStageDataValuesUseCase.ts Outdated Show resolved Hide resolved
src/domain/usecases/CopyProgramStageDataValuesUseCase.ts Outdated Show resolved Hide resolved
src/domain/usecases/CopyProgramStageDataValuesUseCase.ts Outdated Show resolved Hide resolved
src/domain/usecases/CopyProgramStageDataValuesUseCase.ts Outdated Show resolved Hide resolved
src/scripts/commands/programs.ts Outdated Show resolved Hide resolved
@p3rcypj p3rcypj requested a review from tokland January 7, 2025 12:54
Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, code-wise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants