Skip to content

Commit

Permalink
Merge pull request #646 from aehrc/feature/strucDefToQues
Browse files Browse the repository at this point in the history
Feature - Structure Definition to Questionnaire algorithm
  • Loading branch information
fongsean authored Mar 4, 2024
2 parents 44e1e65 + 647f327 commit e6007a0
Show file tree
Hide file tree
Showing 13 changed files with 4,986 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function StandalonePropsPicker(props: StandalonePropsPickerProps) {
onShowResources
} = props;

console.log(state);

return (
<Box display="flex" justifyContent="space-between" mx={2}>
<FormControl>
Expand Down
1 change: 0 additions & 1 deletion packages/sdc-populate/src/utils/evaluateExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export function evaluateItemPopulationContexts(
if (itemPopulationContext) {
let evaluatedResult: any[];
const expression = itemPopulationContext.expression;
// console.log(itemPopulationContext.expression);

// Evaluate expression by LaunchPatient or PrePopQuery
try {
Expand Down
2 changes: 0 additions & 2 deletions packages/sdc-populate/src/utils/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,5 @@ export async function populate(
questionnaireResponse
);

console.log(cleanQuestionnaireResponse);

return createOutputParameters(cleanQuestionnaireResponse, issues);
}
11 changes: 11 additions & 0 deletions packages/structure-def-to-questionnaire/convertTypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Convert structure definition type codes to appropriate questionnaire item types
def convert_to_appropriate_type(item_type):
# convert id to string
if item_type == "id":
return "string"

# convert uri to url
if item_type == "uri":
return "url"

return item_type
336 changes: 336 additions & 0 deletions packages/structure-def-to-questionnaire/createItems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,336 @@
def add_required_and_repeats_attribute(element, item):
# required
if element.get("min", 0) > 0:
item["required"] = True

# repeats
if element.get("max", 0) == "*":
item["repeats"] = True

return item


def create_item(element, parent_link_id=None):
link_id = element["id"]

if link_id.startswith("Extension"):
link_id = parent_link_id + link_id.replace("Extension", "")

item = {
"linkId": link_id,
"text": link_id,
"type": "string",
"required": False,
"repeats": False,
}

item = add_required_and_repeats_attribute(element, item)

return item


def create_address_item(element, item):
if item["type"] == "group":
period_item = {
"linkId": f"{element['id']}.period",
"text": "Address.period",
"type": "group",
"required": False,
"repeats": False,
}
period_item = create_period_item(element, period_item)

item["item"] = [
{
"linkId": f"{element['id']}.use",
"text": "Address.use",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/address-use|4.0.1",
},
{
"linkId": f"{element['id']}.type",
"text": "Address.type",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/address-type|4.0.1",
},
{
"linkId": f"{element['id']}.text",
"text": "Address.text",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.line",
"text": "Address.line",
"type": "string",
"required": False,
"repeats": True,
},
{
"linkId": f"{element['id']}.city",
"text": "Address.city",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.district",
"text": "Address.district",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.state",
"text": "Address.state",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.postalCode",
"text": "Address.postalCode",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.country",
"text": "Address.country",
"type": "string",
"required": False,
"repeats": False,
},
period_item,
]

return item


def create_period_item(element, item):
if item["type"] == "group":
item["item"] = [
{
"linkId": f"{element['id']}.start",
"text": "Period.start",
"type": "dateTime",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.end",
"text": "Period.end",
"type": "dateTime",
"required": False,
"repeats": False,
},
]

return item


def create_human_name_item(element, item):
if item["type"] == "group":

period_item = {
"linkId": f"{element['id']}.period",
"text": "HumanName.period",
"type": "group",
"required": False,
"repeats": False,
}
period_item = create_period_item(element, period_item)

item["item"] = [
{
"linkId": f"{element['id']}.use",
"text": "HumanName.use",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/name-use|4.0.1",
},
{
"linkId": f"{element['id']}.text",
"text": "HumanName.text",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.family",
"text": "HumanName.family",
"type": "string",
"required": False,
"repeats": True,
},
{
"linkId": f"{element['id']}.given",
"text": "HumanName.given",
"type": "string",
"required": False,
"repeats": True,
},
{
"linkId": f"{element['id']}.prefix",
"text": "HumanName.prefix",
"type": "string",
"required": False,
"repeats": True,
},
{
"linkId": f"{element['id']}.suffix",
"text": "HumanName.suffix",
"type": "string",
"required": False,
"repeats": True,
},
period_item,
]

return item


def create_contact_point_item(element, item):
if item["type"] == "group":

period_item = {
"linkId": f"{element['id']}.period",
"text": "ContactPoint.period",
"type": "group",
"required": False,
"repeats": False,
}
period_item = create_period_item(element, period_item)

item["item"] = [
{
"linkId": f"{element['id']}.system",
"text": "ContactPoint.system",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/contact-point-system|4.0.1",
},
{
"linkId": f"{element['id']}.value",
"text": "ContactPoint.value",
"type": "string",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.use",
"text": "ContactPoint.use",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/contact-point-use|4.0.1",
},
{
"linkId": f"{element['id']}.rank",
"text": "ContactPoint.rank",
"type": "integer",
"required": False,
"repeats": False,
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/minValue",
"valueInteger": 1,
}
],
},
period_item,
]

return item


def create_identifier_item(element, item):
if item["type"] == "group":

codeable_concept_item = {
"linkId": f"{element['id']}.type",
"text": "Identifier.type",
"type": "group",
"required": False,
"repeats": False,
}
codeable_concept_item = create_codeable_concept_item(
element,
codeable_concept_item,
"http://hl7.org/fhir/ValueSet/identifier-type|4.0.1",
)

period_item = {
"linkId": f"{element['id']}.period",
"text": "ContactPoint.period",
"type": "group",
"required": False,
"repeats": False,
}
period_item = create_period_item(element, period_item)

item["item"] = [
{
"linkId": f"{element['id']}.use",
"text": "Identifier.use",
"type": "choice",
"required": False,
"repeats": False,
"answerValueSet": "http://hl7.org/fhir/ValueSet/identifier-use|4.0.1",
},
codeable_concept_item,
{
"linkId": f"{element['id']}.system",
"text": "Identifier.system",
"type": "uri",
"required": False,
"repeats": False,
},
{
"linkId": f"{element['id']}.value",
"text": "Identifier.value",
"type": "string",
"required": False,
"repeats": False,
},
period_item,
{
"linkId": f"{element['id']}.assigner",
"text": "Identifier.assigner",
"type": "reference",
"required": False,
"repeats": False,
},
]

return item


def create_codeable_concept_item(element, item, value_set_url):
if item["type"] == "group":
item["item"] = [
{
"linkId": f"{element['id']}.coding",
"text": "CodeableConcept.coding",
"type": "choice",
"required": False,
"repeats": True,
"answerValueSet": value_set_url,
},
{
"linkId": f"{element['id']}.text",
"text": "CodeableConcept.text",
"type": "string",
"required": False,
"repeats": False,
},
]

return item
Loading

0 comments on commit e6007a0

Please sign in to comment.