Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Apr 4, 2024
2 parents 799a6df + 13ca4c4 commit d8f1c6e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 34 deletions.
16 changes: 10 additions & 6 deletions src/common/subjectModelMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export const mapIndividual = individualDetails => {
return individual;
};

export const mapObservations = observations => {
export function mapObservations(observations) {
if (observations)
return observations.map(observation => {
return mapObservation(observation);
});
};
}

function getAnswers(answersJson) {
return map(answersJson, answerJson => {
Expand Down Expand Up @@ -84,7 +84,11 @@ export const mapConcept = conceptJson => {
return concept;
};

export const mapObservation = observationJson => {
function looksLikeRepeatableQuestionGroupValue(value) {
return _.isArrayLike(value) && value.length > 1 && _.isArrayLike(value[0]);
}

export function mapObservation(observationJson) {
if (observationJson) {
const observation = new Observation();
const concept = mapConcept(observationJson.concept);
Expand All @@ -96,7 +100,7 @@ export const mapObservation = observationJson => {
observationJson.location && addressLevelService.addAddressLevel(observationJson.location);
let value;
if (concept.isQuestionGroup()) {
if (_.isArrayLike(observationJson.value)) {
if (looksLikeRepeatableQuestionGroupValue(observationJson.value)) {
//RepeatableQuestionGroup
const repeatableQuestionGroupObservations = _.map(
observationJson.value,
Expand All @@ -115,7 +119,7 @@ export const mapObservation = observationJson => {
observation.valueJSON = value;
return observation;
}
};
}

//subject Dashboard profile Tab
export const mapProfile = subjectProfile => {
Expand Down Expand Up @@ -301,7 +305,7 @@ export const mapEncounterType = encounterType => {
return General.assignFields(encounterType, new EncounterType(), ["name", "uuid"]);
};

// general tab subject Dashbord
// general tab subject Dashboard
export const mapGeneral = subjectGeneral => {
if (subjectGeneral && subjectGeneral.encounters) {
return subjectGeneral.encounters.map(encounters => {
Expand Down
40 changes: 19 additions & 21 deletions src/dataEntryApp/components/QuestionGroupFormElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import React, { Fragment } from "react";
import { filter, includes, map, sortBy, get } from "lodash";
import { FormElement } from "./FormElement";
import { Concept, QuestionGroup } from "avni-models";

function getChildObservationValue(concept, questionGroupObservation) {
const qgObservationValue = questionGroupObservation
? questionGroupObservation.getValueWrapper()
: new QuestionGroup();
const childObs = qgObservationValue.findObservation(concept);
return childObs && childObs.getValueWrapper().getValue();
}
import _ from "lodash";

function getQuestionGroupLabel(formElement, isRepeatable, repeatableIndex) {
if (isRepeatable) return `${formElement.name} - ${repeatableIndex}`;
if (isRepeatable) return `${formElement.name} - ${repeatableIndex + 1}`;
return formElement.name;
}

Expand All @@ -23,7 +16,7 @@ export default function QuestionGroupFormElement({
filteredFormElements,
updateObs,
isRepeatable = false,
repeatableIndex
questionGroupIndex
}) {
const allChildren = sortBy(
filter(filteredFormElements, ffe => get(ffe, "group.uuid") === formElement.uuid && !ffe.voided),
Expand All @@ -43,18 +36,23 @@ export default function QuestionGroupFormElement({
concept.datatype
)
);
const childObservations = obsHolder.findObservation(formElement.concept);
const observation = obsHolder.findObservation(formElement.concept);
let questionGroup;
if (_.isNil(observation)) questionGroup = new QuestionGroup();
else if (formElement.repeatable)
questionGroup = observation.getValueWrapper().getGroupObservationAtIndex(questionGroupIndex);
else questionGroup = observation.getValueWrapper();

return (
<Fragment>
<div>{getQuestionGroupLabel(formElement, isRepeatable, repeatableIndex)}</div>
<div>{getQuestionGroupLabel(formElement, isRepeatable, questionGroupIndex)}</div>
<div style={{ flexDirection: "row", alignItems: "center", marginTop: "10px" }}>
{map(textNumericAndNotes, childFormElement => (
<FormElement
key={childFormElement.uuid}
concept={childFormElement.concept}
obsHolder={obsHolder}
value={getChildObservationValue(childFormElement.concept, childObservations)}
value={questionGroup.getValueForConcept(childFormElement.concept)}
validationResults={validationResults}
uuid={childFormElement.uuid}
update={value => {
Expand All @@ -70,22 +68,22 @@ export default function QuestionGroupFormElement({
))}
</div>
<div style={{ marginRight: "15px" }}>
{map(otherQuestions, fe => (
<div key={fe.uuid} style={{ marginTop: "20px" }}>
{map(otherQuestions, childFormElement => (
<div key={childFormElement.uuid} style={{ marginTop: "20px" }}>
<FormElement
concept={fe.concept}
concept={childFormElement.concept}
obsHolder={obsHolder}
value={getChildObservationValue(fe.concept, childObservations)}
value={questionGroup.getValueForConcept(childFormElement.concept)}
validationResults={validationResults}
uuid={fe.uuid}
uuid={childFormElement.uuid}
update={value => {
updateObs(formElement, value, fe);
updateObs(formElement, value, childFormElement);
}}
feIndex={fe.displayOrder}
feIndex={childFormElement.displayOrder}
filteredFormElements={filteredFormElements}
ignoreLineBreak={true}
>
{fe}
{childFormElement}
</FormElement>
</div>
))}
Expand Down
7 changes: 4 additions & 3 deletions src/dataEntryApp/components/RepeatableQuestionGroupElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { RepeatableQuestionGroup } from "openchs-models";
import QuestionGroupFormElement from "./QuestionGroupFormElement";
import _ from "lodash";

export function RepeatableQuestionGroupElement({
formElement,
Expand All @@ -9,8 +10,8 @@ export function RepeatableQuestionGroupElement({
filteredFormElements,
updateObs
}) {
const childObservations = obsHolder.findObservation(formElement.concept);
const repeatableQuestionGroup = new RepeatableQuestionGroup(childObservations);
let repeatableQuestionGroup = obsHolder.findObservation(formElement.concept);
if (_.isNil(repeatableQuestionGroup)) repeatableQuestionGroup = new RepeatableQuestionGroup();
return repeatableQuestionGroup.getValue().map((x, index) => {
return (
<QuestionGroupFormElement
Expand All @@ -20,7 +21,7 @@ export function RepeatableQuestionGroupElement({
updateObs={updateObs}
validationResults={validationResults}
isRepeatable={true}
repeatableIndex={1}
questionGroupIndex={index}
key={index}
/>
);
Expand Down
26 changes: 22 additions & 4 deletions src/dataEntryApp/services/FormElementService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ import { differenceWith, some, filter, flatMap, head, isEmpty, isNil, map, remov
import { getFormElementsStatuses } from "./RuleEvaluationService";

export default {
updateObservations(observationsHolder, formElement, value, childFormElement) {
updateObservations(
observationsHolder,
formElement,
value,
childFormElement,
questionGroupIndex = 0
) {
if (!isNil(childFormElement) && !isNil(childFormElement.groupUuid)) {
observationsHolder.updateGroupQuestion(formElement, childFormElement, value);

const questionGroupTypeObservation = observationsHolder.findObservation(formElement.concept);
if (formElement.repeatable) {
observationsHolder.updateRepeatableGroupQuestion(
questionGroupIndex,
formElement,
childFormElement,
value
);
} else {
observationsHolder.updateGroupQuestion(formElement, childFormElement, value);
}
const questionGroupTypeObservation = observationsHolder.findQuestionGroupObservation(
formElement.concept,
formElement,
questionGroupIndex
);
let questionGroup;
if (questionGroupTypeObservation) {
questionGroup = questionGroupTypeObservation.getValueWrapper();
Expand Down

0 comments on commit d8f1c6e

Please sign in to comment.