Skip to content

Commit

Permalink
Merge pull request #482 from abertnamanya/fix-orderEntry
Browse files Browse the repository at this point in the history
Order Entry fixes
  • Loading branch information
mozzy11 authored Aug 17, 2023
2 parents a601703 + c3e0f96 commit 1361f14
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 17 deletions.
7 changes: 4 additions & 3 deletions frontend/src/components/addOrder/AddOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const AddOrder = (props) => {
const {orderFormValues, setOrderFormValues, samples} = props;
const componentMounted = useRef(true);
const [otherSamplingVisible, setOtherSamplingVisible] = useState(false);
const [programs, setPrograms] = useState([]);
const [providers, setProviders] = useState([]);
const [paymentOptions, setPaymentOptions] = useState([]);
const [samplingPerformed, setSamplingPerformed] = useState([]);
Expand All @@ -21,6 +20,7 @@ const AddOrder = (props) => {
const {setNotificationVisible, setNotificationBody} = useContext(NotificationContext);
const [siteNames, setSiteNames] = useState([]);
const [configurationProperties, setConfigurationProperties] = useState([{id: "", value: ""}]);
const [phoneFormat, setPhoneFormat] = useState("");


const handleDatePickerChange = (datePicker, date) => {
Expand Down Expand Up @@ -239,6 +239,8 @@ const AddOrder = (props) => {
const siteNameConfig = findConfigurationProperty("restrictFreeTextRefSiteEntry");
const requesterConfig = findConfigurationProperty("restrictFreeTextProviderEntry");

setPhoneFormat(findConfigurationProperty("phoneFormat"));

setOrderFormValues({
...orderFormValues, currentDate: currentDate, sampleOrderItems: {
...orderFormValues.sampleOrderItems,
Expand Down Expand Up @@ -287,7 +289,6 @@ const AddOrder = (props) => {

const getSampleEntryPreform = (response) => {
if (componentMounted.current) {
setPrograms(response.sampleOrderItems.programList);
setSiteNames(response.sampleOrderItems.referringSiteList)
setPaymentOptions(response.sampleOrderItems.paymentOptions);
setSamplingPerformed(response.sampleOrderItems.testLocationCodeList);
Expand Down Expand Up @@ -419,7 +420,7 @@ const AddOrder = (props) => {
disabled={allowRequesterOptions !== "false"}
onChange={handleRequesterWorkPhone}
value={orderFormValues.sampleOrderItems.providerWorkPhone}
onMouseLeave={handlePhoneNoValidation} labelText="Requester Phone: +225-xx-xx-xx-xx: "
onMouseLeave={handlePhoneNoValidation} labelText={`Requester Phone: ${phoneFormat}`}
id="providerWorkPhoneId" className="inputText"/>

<TextInput name="providerFax" labelText="Requester's Fax Number: "
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/addOrder/OrderReferralRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const OrderReferralRequest = ({
const updateReferralRequest = [...referralRequests];
let testValue = {};
let defaultSelect = {};
selectedTests.map((test, i) => {

selectedTests.length > 0 && selectedTests.map((test, i) => {
let id = index + "_" + test.id;
testValue = {
id: test.id, value: test.name
Expand All @@ -83,12 +84,13 @@ const OrderReferralRequest = ({
onChange={(e) => handleReasonForReferral(e, i)}/>,
referrer: <CustomTextInput id={"referrer_" + id}
defaultValue={referralRequests[i].referrer ? referralRequests[i].referrer : obj.referrer}
onChange={(value) => handleReferrer(value, i)}/>,
onChange={(value) => handleReferrer(value, i)} labelText={""}/>,
institute: <CustomSelect id={"referredInstituteId_" + id} options={referralOrganizations}
value={referralRequests[i].institute ? referralRequests[i].institute : null}
onChange={(e) => handleInstituteSelect(e, i)}
defaultSelect={defaultSelect}/>,
sentDate: <CustomDatePicker id={"sendDate_" + id} autofillDate={true}
className="orderReferralSentDate"
value={referralRequests[i].sentDate ? referralRequests[i].sentDate : null}
onChange={(date) => handleSentDatePicker(date, i)} labelText={""}/>,
testName: <CustomSelect id={"shadowReferredTest_" + id} defaultSelect={testValue}/>,
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/components/addOrder/SampleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const SampleType = (props) => {
rejectionReason: "",
collectionTime: ""
});
const defaultSelect = {id: "", value: ""};


const defaultSelect = {id: "", value: "Choose Rejection Reason"};

function handleCollectionDate(date) {
setSampleXml({
Expand Down Expand Up @@ -178,8 +178,33 @@ const SampleType = (props) => {
}
}


function addReferralRequest(test) {
setReferralRequests([...referralRequests, {
reasonForReferral: referralReasons[0].id,
referrer: user.firstName + " " + user.lastName,
institute: referralOrganizations[0].id,
sentDate: "",
testId: test.id
}]);
}

function removeReferralRequest(test) {
let index = 0;
for (let x in referralRequests) {
if (referralRequests[x].testId === test.id) {
const newReferralRequests = referralRequests;
newReferralRequests.splice(index, 1);
setReferralRequests([...newReferralRequests]);
break;
}
index++;
}
}

const handleFetchSampleTypeTests = (e, index) => {
setSelectedTests([]);
setReferralRequests([]);
const {value} = e.target;
const selectedSampleTypeOption = sampleTypesRef.current.options[sampleTypesRef.current.selectedIndex].text
setSelectedSampleType({
Expand Down Expand Up @@ -213,6 +238,9 @@ const SampleType = (props) => {

useEffect(() => {
props.sampleTypeObject({requestReferralEnabled: requestTestReferral, sampleObjectIndex: index});
if (!requestTestReferral) {
setReferralRequests([]);
}
}, [requestTestReferral]);


Expand Down Expand Up @@ -397,7 +425,8 @@ const SampleType = (props) => {
<CustomTimePicker id={"collectionTime_" + index}
onChange={(time) => handleCollectionTime(time)}
className="inputText" labelText="Collection Time"/>

</div>
<div className="inlineDiv">
<CustomTextInput id={"collector_" + index} onChange={(value) => handleCollector(value)}
defaultValue={""} labelText="Collector" className="inputText"/>
</div>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/addOrder/add-order.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
margin-left: 5px;
}

.cds--accordion__heading{
background-color:#d9d8d9
}

.cds--accordion__content {
padding: 0px !important;
}
Expand Down Expand Up @@ -142,3 +146,8 @@
text-align: center;
margin-top: 10px;
}

.orderReferralSentDate input{
width: 13rem !important;
}

37 changes: 33 additions & 4 deletions frontend/src/components/common/CreatePatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CreatePatientForm extends React.Component {
educationList : [] ,
maritalStatuses : [],
nationalities : [],
phoneFormat: "",
showActionsButton: props.showActionsButton,
formAction: "ADD"
}
Expand Down Expand Up @@ -99,11 +100,13 @@ class CreatePatientForm extends React.Component {
}
}
}

componentDidMount() {
this._isMounted = true;
getFromOpenElisServer("/rest/health-regions", this.fetchHeathRegions);
getFromOpenElisServer("/rest/education-list", this.fetchEducationList);
getFromOpenElisServer("/rest/marital-statuses", this.fetchMaritalStatuses);
getFromOpenElisServer("/rest/configuration-properties", this.fetchConfigurationProperties)
// getFromOpenElisServer("/rest/nationalities", this.fetchNationalities);
this.repopulatePatientInfo();
}
Expand All @@ -125,6 +128,20 @@ class CreatePatientForm extends React.Component {
}
}

accessionNumberValidationResponse = (res) => {
if (res.status === false) {
this.context.setNotificationVisible(true);
this.context.setNotificationBody({kind: NotificationKinds.error, title: "Notification Message", message: res.body});
}

}

handleSubjectNoValidation = (numberType,fieldId,numberValue) =>{
if(numberValue !== ""){
getFromOpenElisServer(`/rest/subjectNumberValidationProvider?fieldId=${fieldId}&numberType=${numberType}&subjectNumber=${numberValue}`, this.accessionNumberValidationResponse);
}
}

fetchMaritalStatuses = (statuses) => {
if (this._isMounted) {
this.setState({ maritalStatuses: statuses })
Expand All @@ -142,6 +159,16 @@ class CreatePatientForm extends React.Component {
this._healthDistricts = districts
}

fetchConfigurationProperties = (res) => {
if (res.length > 0) {
const filterProperty = res.find((config) => config.id === "phoneFormat");
console.log(filterProperty)
if (filterProperty !== undefined) {
this.setState({phoneFormat: filterProperty.value});
}
}
}

handleSubmit = (values) => {
console.log(JSON.stringify(values))
postToOpenElisServer("/rest/patient-management" ,JSON.stringify(values) , this.handlePost)
Expand Down Expand Up @@ -198,13 +225,15 @@ class CreatePatientForm extends React.Component {
<Field name="subjectNumber"
>
{({ field }) =>
<TextInput value={values.subjectNumber} name={field.name} labelText="Unique Health ID number" id={field.name} className="inputText" />
<TextInput value={values.subjectNumber} name={field.name} labelText="Unique Health ID number" id={field.name} className="inputText"
onMouseOut={()=>{this.handleSubjectNoValidation("subjectNumber","subjectNumberID",values.subjectNumber)}}/>
}
</Field>
<Field name="nationalId"
>
{({ field }) =>
<TextInput value={values.nationalId} name={field.name} labelText="National Id" id={field.name} className="inputText" />
<TextInput value={values.nationalId} name={field.name} labelText="National Id" id={field.name} className="inputText"
onMouseOut={()=>{this.handleSubjectNoValidation("nationalId","nationalID",values.nationalId)}}/>

}
</Field>
Expand Down Expand Up @@ -254,7 +283,7 @@ class CreatePatientForm extends React.Component {
<Field name="patientContact.person.primaryPhone"
>
{({ field }) =>
<TextInput value={values.patientContact?.person.primaryPhone} name={field.name} labelText="Contact Phone" id={field.name} className="inputText" />
<TextInput value={values.patientContact?.person.primaryPhone} name={field.name} labelText={`Contact Phone: ${this.state.phoneFormat}`} id={field.name} className="inputText" />
}
</Field>
<div className="error">
Expand All @@ -273,7 +302,7 @@ class CreatePatientForm extends React.Component {
<Field name="primaryPhone"
>
{({ field }) =>
<TextInput value={values.primaryPhone} name={field.name} labelText="Phone" id={field.name} className="inputText" />
<TextInput value={values.primaryPhone} name={field.name} labelText={`Phone: ${this.state.phoneFormat}`} id={field.name} className="inputText" />
}
</Field>
</div>
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/components/common/SearchPatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import { patientSearchHeaderData } from '../data/PatientResultsTableHeaders'
import { Formik, Field } from 'formik'
import SearchPatientFormValues from '../formModel/innitialValues/SearchPatientFormValues'

import {NotificationContext} from "../layout/Layout";
import {NotificationKinds} from "./CustomNotification";

class SearchPatientForm extends React.Component {
static contextType = NotificationContext;

constructor (props) {
super(props)
this.state = {
Expand All @@ -44,9 +49,14 @@ class SearchPatientForm extends React.Component {
}

fetchPatientResults = (patientsResults) => {
patientsResults.forEach(item => item.id = item.patientID)
// console.log(JSON.stringify(patientsResults))
this.setState({ patientSearchResults: patientsResults })
if(patientsResults.length > 0){
patientsResults.forEach(item => item.id = item.patientID)
// console.log(JSON.stringify(patientsResults))
this.setState({ patientSearchResults: patientsResults })
}else{
this.context.setNotificationBody({title: "Notification Message", message: "No patients found matching search terms", kind: NotificationKinds.warning})
this.context.setNotificationVisible(true);
}
}

fetchPatientDetails = (patientDetails) => {
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<minor.version>8</minor.version>
<state.version>0</state.version> <!-- 0 = alpha, 1 = beta, 2 = rc, 3 = deployable -->
<fix.version>8</fix.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<liquibase.propertyFile>${project.basedir}/liquibase/liquibase.properties</liquibase.propertyFile>
<castor.version>1.4.1</castor.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ private void addField(ExtendedPatientSearchResults patient, String fieldName, St
}

private void setDate(ExtendedPatientSearchResults patient, String dateString) throws ParseException {

String dateFormat = "yyyy-MM-dd";
String dateTimeFormat = "yyyy-MM-dd HH:mm:ss.S";
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ private List<IdValuePair> getConfigurationProperties() {
ConfigurationProperties.Property.restrictFreeTextProviderEntry)));
configs.add(new IdValuePair("restrictFreeTextRefSiteEntry", ConfigurationProperties.getInstance().getPropertyValue(
ConfigurationProperties.Property.restrictFreeTextRefSiteEntry)));
configs.add(new IdValuePair("phoneFormat", ConfigurationProperties.getInstance().getPropertyValue(
Property.PHONE_FORMAT)));
configs.add(new IdValuePair("currentDateAsText", DateUtil.getCurrentDateAsText()));
configs.add(new IdValuePair("currentTimeAsText", DateUtil.getCurrentTimeAsText()));
return configs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.openelisglobal.common.rest.provider;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import org.apache.commons.validator.GenericValidator;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.common.provider.validation.IAccessionNumberValidator;
import org.openelisglobal.common.provider.validation.ProgramAccessionValidator;
import org.openelisglobal.common.services.PhoneNumberService;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.project.service.ProjectService;
import org.openelisglobal.project.valueholder.Project;
import org.openelisglobal.sample.util.AccessionNumberUtil;
import org.openelisglobal.sample.util.CI.ProjectForm;
import org.openelisglobal.search.service.SearchResultsService;
import org.openelisglobal.spring.util.SpringContext;
import org.owasp.encoder.Encode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Expand All @@ -29,6 +37,8 @@ public class CommonValidationsRestController {
@Autowired
protected ProjectService projectService;

protected SearchResultsService searchResultsService = SpringContext.getBean(SearchResultsService.class);

public CommonValidationsRestController() {
this.responseObject = new ResponseObject();
}
Expand Down Expand Up @@ -174,6 +184,52 @@ public ResponseObject getPhoneNumberValidation(HttpServletRequest request) {
return responseObject;
}

@GetMapping(value = "subjectNumberValidationProvider", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseObject validateSubjectNumberAndNationalId(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String fieldId = request.getParameter("fieldId");
String number = request.getParameter("subjectNumber");
String numberType = request.getParameter("numberType");
String STNumber = numberType.equals("STnumber") ? number : null;
String subjectNumber = numberType.equals("subjectNumber") ? number : null;
String nationalId = numberType.equals("nationalId") ? number : null;

responseObject.setStatus(false);
String queryResponse = "";
// We just care about duplicates but blank values do not count as duplicates
if (!(GenericValidator.isBlankOrNull(STNumber) && GenericValidator.isBlankOrNull(subjectNumber)
&& GenericValidator.isBlankOrNull(nationalId))) {
List<PatientSearchResults> results = searchResultsService.getSearchResultsExact(null, null, STNumber,
subjectNumber, nationalId, null, null, null, null, null);

boolean allowDuplicateSubjectNumber = ConfigurationProperties.getInstance()
.isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "true");
boolean allowDuplicateNationalId = ConfigurationProperties.getInstance()
.isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "true");
if (!results.isEmpty() && !GenericValidator.isBlankOrNull(subjectNumber)) {
queryResponse = (allowDuplicateSubjectNumber ? "warning#" + MessageUtil.getMessage("alert.warning")
: "fail#" + MessageUtil.getMessage("alert.error")) + ": "
+ MessageUtil.getMessage("error.duplicate.subjectNumber.warning");
responseObject.setBody(queryResponse);

} else if (!results.isEmpty() && !GenericValidator.isBlankOrNull(nationalId)) {
queryResponse = (allowDuplicateNationalId ? "warning#" + MessageUtil.getMessage("alert.warning")
: "fail#" + MessageUtil.getMessage("alert.error")) + ": "
+ MessageUtil.getMessage("error.duplicate.subjectNumber.warning");
responseObject.setBody(queryResponse);
} else if (!results.isEmpty()) {
queryResponse = "fail#" + MessageUtil.getMessage("alert.error") + ": "
+ MessageUtil.getMessage("error.duplicate.subjectNumber.warning");
responseObject.setBody(queryResponse);
}else{
responseObject.setStatus(true);
responseObject.setBody("Valid");
}
}
return responseObject;
}
public static class ResponseObject {

private boolean status = false;
Expand Down
Loading

0 comments on commit 1361f14

Please sign in to comment.