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

(fix) Added start date to cohort payload #78

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true,
"tsconfigRootDir": "__dirname"
},
"plugins": ["@typescript-eslint"],
"root": true,
"rules": {
// turned off to keep the diff small for now
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-misused-promises": "off",
// The following rules need `noImplicitAny` to be set to `true` in our tsconfig. They are too restrictive for now, but should be reconsidered in future
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/unbound-method": "off",
// Nitpicky. Prefer `interface T` over type T
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-exports": "error",
// Use `import type` instead of `import` for type imports
"@typescript-eslint/consistent-type-imports": [
"error",
{
"fixStyle": "inline-type-imports"
}
],
// Use Array<T> instead of T[] consistently
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-restricted-imports": [
"error",
{
"paths": [
// These two rules ensure that we're importing lodash and lodash-es correctly. Not doing so can bloat our bundle size significantly.
{
"name": "lodash",
"message": "Import specific methods from `lodash`. e.g. `import map from 'lodash/map'`"
},
{
"name": "lodash-es",
"importNames": ["default"],
"message": "Import specific methods from `lodash-es`. e.g. `import { map } from 'lodash-es'`"
},
// These two rules ensure that we're importing Carbon components and icons from the correct packages (after v10). May be removed in the future.
{
"name": "carbon-components-react",
"message": "Import from `@carbon/react` directly. e.g. `import { Toggle } from '@carbon/react'`"
},
{
"name": "@carbon/icons-react",
"message": "Import from `@carbon/react/icons`. e.g. `import { ChevronUp } from '@carbon/react/icons'`"
}
]
}
]
}
}
10 changes: 0 additions & 10 deletions .eslintrc.js

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node.js CI
name: OpenMRS CI

on:
push:
Expand All @@ -25,7 +25,7 @@ jobs:
node-version: "18"
- run: yarn install --immutable
- run: yarn verify
- run: yarn build
- run: yarn turbo build
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
run: yarn install --immutable

- run: yarn version "$(node -e "console.log(require('semver').inc(require('./package.json').version, 'patch'))")-pre.${{ github.run_number }}"
- run: yarn build
- run: yarn turbo build
- run: git config user.email "[email protected]" && git config user.name "OpenMRS CI"
- run: git add . && git commit -m "Prerelease version" --no-verify
- run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish --tag next
Expand Down Expand Up @@ -102,6 +102,6 @@ jobs:
with:
node-version: "18"
registry-url: 'https://registry.npmjs.org'
- run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish
- run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ dist/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

.turbo
3 changes: 1 addition & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

set -e # die on error

yarn run verify

yarn verify
15 changes: 9 additions & 6 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[main]
host = https://www.transifex.com

[openmrs-esm-fast-data-entry-app.esm-fast-data-entry-app]
file_filter = translations/<lang>.json
minimum_perc = 0
source_file = translations/en.json
source_lang = en
type = KEYVALUEJSON
[o:openmrs:p:openmrs-esm-fast-data-entry-app:r:esm-fast-data-entry-app]
file_filter = translations/<lang>.json
source_file = translations/en.json
source_lang = en
type = KEYVALUEJSON
minimum_perc = 0
replace_edited_strings = false
keep_translations = false
resource_name = esm-fast-data-entry-app
55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"scripts": {
"start": "openmrs develop",
"serve": "webpack serve --mode=development",
"build": "webpack --mode production",
"build": "webpack --mode production --color",
"analyze": "webpack --mode=production --env.analyze=true",
"lint": "eslint \"src/**/*.ts\" \"src/**/*.tsx\" --fix --max-warnings=0 -c .eslintrc.js",
"lint": "eslint \"src/**/*.ts\" \"src/**/*.tsx\" --fix --max-warnings=0",
"prettier": "prettier --write \"src/**/*.{ts,tsx}\" --list-different",
"typescript": "tsc",
"test": "jest --config jest.config.json --passWithNoTests",
"verify": "concurrently 'yarn:lint' 'yarn:test' 'yarn:typescript'",
"verify": "turbo lint typescript test",
"coverage": "yarn test -- --coverage ",
"postinstall": "husky install",
"extract-translations": "i18next 'src/**/*.tsx' --config ./tools/i18next-parser.config.js"
Expand Down Expand Up @@ -49,46 +49,47 @@
"swr": "2.x"
},
"devDependencies": {
"@carbon/react": "^1.9.0",
"@carbon/react": "^1.37.0",
"@openmrs/esm-framework": "next",
"@swc-node/loader": "^1.3.5",
"@swc/core": "^1.2.245",
"@swc/jest": "^0.2.22",
"@testing-library/dom": "^7.20.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@swc-node/loader": "^1.3.7",
"@swc/core": "^1.3.84",
"@swc/jest": "^0.2.29",
"@testing-library/dom": "^7.31.2",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^28.1.7",
"@types/react-dom": "^18.0.6",
"@types/jest": "^28.1.8",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"@types/testing-library__jest-dom": "^5.14.5",
"@types/webpack-env": "^1.16.0",
"@typescript-eslint/parser": "^5.14.0",
"concurrently": "^6.2.0",
"@types/testing-library__jest-dom": "^5.14.9",
"@types/webpack-env": "^1.18.1",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"concurrently": "^6.5.1",
"css-loader": "^6.8.1",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.3.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-react-app": "^7.0.1",
"eslint-config-ts-react-important-stuff": "^3.0.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.1.3",
"jest-cli": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lodash-es": "^4.17.21",
"openmrs": "next",
"prettier": "^2.3.0",
"pretty-quick": "^3.1.0",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^11.18.4",
"react-router-dom": "^6.3.0",
"semver": "^7.3.7",
"react-i18next": "^11.18.6",
"react-router-dom": "^6.15.0",
"semver": "^7.5.4",
"swc-loader": "^0.2.3",
"swr": "^2.2.4",
"typescript": "^4.7.3",
"webpack": "^5.73.0",
"turbo": "^1.10.13",
"typescript": "^4.9.5",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/FormBootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ const FormBootstrap = ({
handleEncounterCreate,
handleOnValidate,
showDiscardSubmitButtons: false,
preFilledQuestions: { ...activeSessionMeta },
preFilledQuestions: {
...activeSessionMeta,
encDate: activeSessionMeta.sessionDate,
},
}}
/>
)}
Expand Down
67 changes: 46 additions & 21 deletions src/add-group-modal/AddGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
} from "@carbon/react";
import { TrashCan } from "@carbon/react/icons";
import { useTranslation } from "react-i18next";
import { ExtensionSlot, showToast, usePatient } from "@openmrs/esm-framework";
import {
ExtensionSlot,
fetchCurrentPatient,
showToast,
usePatient,
} from "@openmrs/esm-framework";
import styles from "./styles.scss";
import GroupFormWorkflowContext from "../context/GroupFormWorkflowContext";
import { usePostCohort } from "../hooks";
Expand Down Expand Up @@ -111,7 +116,7 @@ const NewGroupForm = (props) => {
<PatientRow
patient={patient}
removePatient={removePatient}
key={index}
key={patient.uuid}
/>
))}
</ul>
Expand All @@ -125,7 +130,7 @@ const NewGroupForm = (props) => {
</FormLabel>
<div className={styles.searchBar}>
<MemExtension
extensionSlotName="patient-search-bar-slot"
name="patient-search-bar-slot"
state={{
selectPatientAction: updatePatientList,
buttonProps: {
Expand All @@ -139,14 +144,14 @@ const NewGroupForm = (props) => {
};

const AddGroupModal = ({
patients = undefined,
isCreate = undefined,
groupName = "",
cohortUuid = undefined,
isOpen,
handleCancel,
onPostSubmit,
}) => {
patients = undefined,
isCreate = undefined,
groupName = "",
cohortUuid = undefined,
isOpen,
onPostCancel,
onPostSubmit,
}) => {
const { setGroup } = useContext(GroupFormWorkflowContext);
const { t } = useTranslation();
const [errors, setErrors] = useState({});
Expand Down Expand Up @@ -191,32 +196,52 @@ const AddGroupModal = ({
);

const updatePatientList = useCallback(
(patient) => {
setPatientList((patientList) => {
if (!patientList.find((p) => p.uuid === patient)) {
return [...patientList, { uuid: patient }];
} else {
return patientList;
}
});
(patientUuid) => {
if (!patientList.find((p) => p.uuid === patientUuid)) {
fetchCurrentPatient(patientUuid).then((result) => {
const newPatient = {
uuid: patientUuid,
name: [result?.name?.[0]?.given, result?.name?.[0]?.family].join(
" "
),
};
setPatientList(
[...patientList, newPatient].sort((a, b) =>
a.name?.localeCompare(b?.name, { sensitivity: "base" })
)
);
});
}
setErrors((errors) => ({ ...errors, patientList: null }));
},
[setPatientList]
[patientList, setPatientList]
);

const handleSubmit = () => {
if (validate()) {
const startDate = new Date().toISOString();
post({
uuid: cohortUuid,
name: name,
cohortMembers: patientList.map((p) => ({ patient: p.uuid })),
startDate: startDate,
cohortMembers: patientList.map((p) => ({
patient: p.uuid,
startDate: startDate,
Copy link
Member

@denniskigen denniskigen Mar 25, 2024

Choose a reason for hiding this comment

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

I can't find the relevant info on whether cohortMembers supports a startDate property, @ibacher, @dkayiwa. Could you verify this?

Copy link
Member

Choose a reason for hiding this comment

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

It should.

I don't love defaulting this to the current date. This should probably be something the user can edit when adding a member to the group.

Copy link
Member

Choose a reason for hiding this comment

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

Does that sound reasonable, @icrc-psousa?

})),
});
if (onPostSubmit) {
onPostSubmit();
}
}
};

const handleCancel = () => {
setPatientList(patients || []);
if (onPostCancel) {
onPostCancel();
}
};

useEffect(() => {
if (result) {
setGroup({
Expand Down
6 changes: 3 additions & 3 deletions src/add-group-modal/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@use '@carbon/styles/scss/spacing';
@use '@carbon/colors';
@use '@carbon/layout';

.modal {
:global(.cds--modal) {
Expand Down Expand Up @@ -36,7 +36,7 @@

.patientName {
flex-grow: 1;
padding-left: spacing.$spacing-05;
padding-left: layout.$spacing-05;
}

.loading {
Expand All @@ -45,5 +45,5 @@
flex-direction: column;
justify-content: center;
align-items: center;
row-gap: spacing.$spacing-05;
row-gap: layout.$spacing-05;
}
Loading