Skip to content

Commit

Permalink
Create rule logic separation (#1187)
Browse files Browse the repository at this point in the history
* Refactor enableDisable, dateCompare

* Hide/unhide

* Require if

* Create rule feature

* Hide/unhide subsection

* EnableDisable subsection

* Testing

* Rename, additional testing

* Cnft1 1839 (#1167)

* Pagination fixed for NamesTable

* Fixed PhoneAndEmailTable.tsx

* Pagination for Address table

* use only refetch for reload

* removed synchronous then function

* added synchronous functions

---------

Co-authored-by: Michael Davis <[email protected]>

* CNFT2-2214 Business Rules Bug Fix (#1181)

* CNFT2-2213 Ungroup Questions: close menu (#1180)

* [CNFT1-2077] Lab Report Search Testing (#1172)

* lab report testing baseline

* CNFT1-2090 Stored Procedures for Importation of data into CliniDeID - MSGOUTE (#1173)

* Case insensitive identification search (#1179)

* CNFT2-2098 Drag drop border (#1184)

* Add quick code to autocomplete display name (#1182)

* CNFT2-2100 Questions gap (#1186)

* CNFT2-2221 Group Data mart repeat number 0 (#1185)

* adding functionality for event search tabbing by converting patient an… (#1178)

* adding functionality for event search tabing by converting patient and event search to buttons and made styles accordingly

* adding a new component for tabs and using them in advanced search for patient and event search

* formatting new files

* adding sass modules

* removing class names and moving the styles into the module

* Fix  in finder with added space

* Fix test

---------

Co-authored-by: Michael Peels <[email protected]>
Co-authored-by: Michael Davis <[email protected]>
Co-authored-by: Michael Davis <[email protected]>
Co-authored-by: Lakshmi Narayanan Ramakrishnan <[email protected]>
Co-authored-by: John Lee <[email protected]>
Co-authored-by: Adam Loup <[email protected]>
Co-authored-by: Sergei Veselev <[email protected]>
Co-authored-by: Steve Urciuoli <[email protected]>
Co-authored-by: Henry Clark <[email protected]>
  • Loading branch information
10 people authored Mar 18, 2024
1 parent c1d81ee commit 559ddea
Show file tree
Hide file tree
Showing 54 changed files with 3,510 additions and 4,027 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void a_patient_phone_is_added() {
RandomUtil.getRandomDateInPast(),
RandomUtil.oneFrom("AN", "BP", "CP", "NET", "FAX", "PH"),
RandomUtil.oneFrom("SB", "EC", "H", "MC", "WP", "TMP"),
RandomUtil.getRandomString(),
RandomUtil.getRandomString(19),
faker.phoneNumber().cellPhone(),
faker.phoneNumber().extension(),
faker.internet().emailAddress(),
faker.internet().url(),
RandomUtil.getRandomString(15));
RandomUtil.getRandomString(19));

controller.add(newRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export { CreateConceptRequest } from './models/CreateConceptRequest';
export type { CreateConditionRequest } from './models/CreateConditionRequest';
export { CreateDateQuestionRequest } from './models/CreateDateQuestionRequest';
export { CreateNumericQuestionRequest } from './models/CreateNumericQuestionRequest';
export { CreateRuleRequest } from './models/CreateRuleRequest';
export type { CreateRuleResponse } from './models/CreateRuleResponse';
export type { CreateSectionRequest } from './models/CreateSectionRequest';
export type { CreateSubSectionRequest } from './models/CreateSubSectionRequest';
export type { CreateTabRequest } from './models/CreateTabRequest';
Expand Down Expand Up @@ -88,6 +86,7 @@ export type { ReadConditionRequest } from './models/ReadConditionRequest';
export type { ReportingInfo } from './models/ReportingInfo';
export type { Resource } from './models/Resource';
export { Rule } from './models/Rule';
export { RuleRequest } from './models/RuleRequest';
export type { SearchPageRuleRequest } from './models/SearchPageRuleRequest';
export type { Section } from './models/Section';
export type { SelectableCondition } from './models/SelectableCondition';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

import type { SourceValue } from './SourceValue';

export type CreateRuleRequest = {
export type RuleRequest = {
anySourceValue: boolean;
comparator: CreateRuleRequest.comparator;
comparator: RuleRequest.comparator;
description?: string;
ruleFunction: CreateRuleRequest.ruleFunction;
ruleFunction: RuleRequest.ruleFunction;
sourceIdentifier: string;
sourceText?: string;
sourceValues?: Array<SourceValue>;
targetIdentifiers: Array<string>;
targetType: CreateRuleRequest.targetType;
targetType: RuleRequest.targetType;
targetValueText?: Array<string>;
};

export namespace CreateRuleRequest {
export namespace RuleRequest {

export enum comparator {
EQUAL_TO = 'EQUAL_TO',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { CreateRuleRequest } from '../models/CreateRuleRequest';
import type { CreateRuleResponse } from '../models/CreateRuleResponse';
import type { Page_Rule_ } from '../models/Page_Rule_';
import type { Rule } from '../models/Rule';
import type { RuleRequest } from '../models/RuleRequest';
import type { SearchPageRuleRequest } from '../models/SearchPageRuleRequest';

import type { CancelablePromise } from '../core/CancelablePromise';
Expand All @@ -15,7 +14,7 @@ export class PageRuleControllerService {

/**
* createBusinessRule
* @returns CreateRuleResponse Created
* @returns Rule Created
* @throws ApiError
*/
public static createBusinessRuleUsingPost({
Expand All @@ -31,8 +30,8 @@ export class PageRuleControllerService {
/**
* request
*/
request: CreateRuleRequest,
}): CancelablePromise<CreateRuleResponse> {
request: RuleRequest,
}): CancelablePromise<Rule> {
return __request(OpenAPI, {
method: 'POST',
url: '/nbs/page-builder/api/v1/pages/{id}/rules',
Expand Down Expand Up @@ -167,35 +166,29 @@ export class PageRuleControllerService {

/**
* updatePageRule
* @returns CreateRuleResponse OK
* @returns Rule OK
* @returns any Created
* @throws ApiError
*/
public static updatePageRuleUsingPut({
authorization,
id,
request,
ruleId,
}: {
authorization: string,
/**
* id
*/
id: number,
/**
* request
*/
request: CreateRuleRequest,
request: RuleRequest,
/**
* ruleId
*/
ruleId: number,
}): CancelablePromise<CreateRuleResponse | any> {
}): CancelablePromise<Rule | any> {
return __request(OpenAPI, {
method: 'PUT',
url: '/nbs/page-builder/api/v1/pages/{id}/rules/{ruleId}',
path: {
'id': id,
'ruleId': ruleId,
},
headers: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateRuleRequest, PageRuleControllerService, Rule } from 'apps/page-builder/generated';
import { RuleRequest, PageRuleControllerService, Rule } from 'apps/page-builder/generated';
import { FormProvider, useForm, useWatch } from 'react-hook-form';
import { Breadcrumb } from 'breadcrumb';
import styles from './AddBusinessRule.module.scss';
Expand All @@ -16,7 +16,7 @@ export type SourceValueProp = {
};

export const AddBusinessRule = () => {
const form = useForm<CreateRuleRequest>({
const form = useForm<RuleRequest>({
defaultValues: { targetType: Rule.targetType.QUESTION, anySourceValue: false }
});
const watch = useWatch(form);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
CreateRuleRequest,
RuleRequest,
PageRuleControllerService,
PagesQuestion,
PagesSection,
Expand All @@ -21,7 +21,7 @@ import { useAlert } from 'alert';
import { ConfirmationModal } from 'confirmation';

export const EditBusinessRule = () => {
const form = useForm<CreateRuleRequest>();
const form = useForm<RuleRequest>();
const watch = useWatch(form);
const navigate = useNavigate();
const { ruleId } = useParams();
Expand All @@ -43,7 +43,7 @@ export const EditBusinessRule = () => {
ruleId: Number(ruleId)
}).then((response: Rule) => {
fetchSourceValues(response.sourceQuestion.codeSetName ?? '');
setSelectedSourceValues(response.sourceValues);
setSelectedSourceValues(response.sourceValues?.map((s) => s.trim()));
setInitialSourceIdentifiers(response.sourceQuestion.questionIdentifier ?? '');
setInitialTargetIdentifiers(response.targets.map((target) => target.targetIdentifier ?? '') ?? []);

Expand Down Expand Up @@ -137,7 +137,6 @@ export const EditBusinessRule = () => {
try {
await PageRuleControllerService.updatePageRuleUsingPut({
authorization: authorization(),
id: page?.id ?? 0,
ruleId: Number(ruleId) ?? 0,
request: data
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, ButtonGroup, Checkbox, Icon, Label, Modal, ModalRef, Radio } from '@trussworks/react-uswds';
import { CreateRuleRequest, PagesQuestion, PagesSubSection, Rule } from 'apps/page-builder/generated';
import { RuleRequest, PagesQuestion, PagesSubSection, Rule } from 'apps/page-builder/generated';
import { Controller, useFormContext, useWatch } from 'react-hook-form';
import styles from './BusinessRulesForm.module.scss';
import { SelectInput } from 'components/FormInputs/SelectInput';
Expand Down Expand Up @@ -33,7 +33,7 @@ export const BusinessRulesForm = ({
editTargetQuestions,
editTargetSubsections
}: Props) => {
const form = useFormContext<CreateRuleRequest>();
const form = useFormContext<RuleRequest>();
const watch = useWatch(form);
const sourceQuestionModalRef = useRef<ModalRef>(null);
const targetQuestionModalRef = useRef<ModalRef>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
width: 69.25rem;
max-width: 69.25rem;
}
.usa-modal__main {
height: 80svh;
}
}

.source-value-multi-select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
display: flex;
flex-direction: column;
padding: 1.5rem;
height: 46.5rem;
height: 100%;
justify-content: space-between;

.body {
height: 100%;
overflow-y: auto;
height: 100%;
overflow-y: auto;
.headerMessage {
border-top: 1px solid colors.$base-lightest;
padding-top: 1.5rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateRuleRequest, PagesSubSection } from 'apps/page-builder/generated';
import { RuleRequest, PagesSubSection } from 'apps/page-builder/generated';
import { useGetPageDetails } from 'apps/page-builder/page/management';
import { MultiSelectInput } from 'components/selection/multi';
import { useEffect, useState } from 'react';
Expand All @@ -12,7 +12,7 @@ const SubSectionsDropdown = ({ onSelect }: Props) => {
const [subSections, setSubSections] = useState<PagesSubSection[]>([]);
const [selectedSubsections, setSelectedSubsections] = useState<string[]>([]);

const form = useFormContext<CreateRuleRequest>();
const form = useFormContext<RuleRequest>();

const { page } = useGetPageDetails();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
display: flex;
flex-direction: column;
padding: 1.5rem;
height: 46.5rem;
height: 100%;
justify-content: space-between;

.body {
overflow-y: auto;
height: 100%;
overflow-y: auto;
height: 100%;
.headerMessage {
border-top: 1px solid colors.$base-lightest;
padding-top: 1.5rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package gov.cdc.nbs.questionbank.entity.pagerule;

import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import gov.cdc.nbs.questionbank.page.command.PageContentCommand;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

import gov.cdc.nbs.questionbank.pagerules.command.PageRuleCommand;

import java.time.Instant;

@AllArgsConstructor
@NoArgsConstructor
@Getter
Expand Down Expand Up @@ -84,26 +85,37 @@ public class WaRuleMetadata {
private String targetType;


public WaRuleMetadata(PageRuleCommand.AddPageRule command) {
this.ruleCd = command.ruleRequest().ruleFunction().getValue();
this.ruleDescText = command.ruleRequest().description();
this.sourceValues = command.ruleData().sourceValues();
this.logic = command.ruleRequest().comparator().getValue();
this.sourceQuestionIdentifier = command.ruleData().sourceIdentifier();
this.targetQuestionIdentifier = command.ruleData().targetIdentifiers();
this.targetType = command.ruleRequest().targetType().toString();
this.addTime = command.requestedOn();
this.addUserId = command.userId();
this.lastChgTime = command.requestedOn();
this.recordStatusCd = ACTIVE;
this.lastChgUserId = command.userId();
this.recordStatusTime = command.requestedOn();
this.errormsgText = command.ruleData().errorMsgText();
this.jsFunction = command.ruleData().jsFunctionNameHelper().jsFunction();
this.jsFunctionName = command.ruleData().jsFunctionNameHelper().jsFunctionName();
public WaRuleMetadata(PageContentCommand.AddRuleCommand command) {
this.waTemplateUid = command.page();
this.targetType = command.targetType();
this.ruleCd = command.ruleFunction();
this.ruleDescText = command.description();
this.logic = command.comparator();
this.sourceValues = command.sourceValues();
this.sourceQuestionIdentifier = command.sourceIdentifier();
this.targetQuestionIdentifier = command.targetIdentifiers();
this.errormsgText = command.errorMessage();
this.jsFunction = command.javascript();
this.jsFunctionName = command.javascriptName();
this.waTemplateUid = command.page();
this.ruleExpression = command.ruleData().ruleExpression();
this.userRuleId = "Rule" + this.id;
this.ruleExpression = command.expression();
this.userRuleId = "Rule" + command.ruleId();
added(command);
}


public void update(PageContentCommand.UpdateRuleCommand command) {
this.targetType = command.targetType();
this.ruleDescText = command.description();
this.logic = command.comparator();
this.sourceValues = command.sourceValues();
this.sourceQuestionIdentifier = command.sourceIdentifier();
this.targetQuestionIdentifier = command.targetIdentifiers();
this.errormsgText = command.errorMessage();
this.jsFunction = command.javascript();
this.jsFunctionName = command.javascriptName();
this.ruleExpression = command.expression();
updated(command);
}

public WaRuleMetadata(long pageId, PageContentCommand.AddRule command) {
Expand All @@ -117,12 +129,17 @@ public WaRuleMetadata(long pageId, PageContentCommand.AddRule command) {
}

private void added(PageContentCommand command) {
this.recordStatusCd = ACTIVE;
this.addTime = command.requestedOn();
this.addUserId = command.userId();
this.lastChgTime = command.requestedOn();
this.lastChgUserId = command.userId();
this.recordStatusTime = command.requestedOn();
}

private void updated(PageContentCommand command) {
this.lastChgTime = command.requestedOn();
this.lastChgUserId = command.userId();
}

public static WaRuleMetadata clone(WaRuleMetadata original) {
Expand All @@ -146,8 +163,7 @@ public static WaRuleMetadata clone(WaRuleMetadata original) {
original.getUserRuleId(),
original.getLogic(),
original.getSourceValues(),
original.getTargetType()
);
original.getTargetType());

}

Expand Down
Loading

0 comments on commit 559ddea

Please sign in to comment.