@@ -91,7 +91,7 @@ Patient looks something like this:
9191}
9292```
9393
94- The fhir-eswatini adaptor reduces this to :
94+ But with the ` fhir-eswatini ` adaptor, all we have to write is :
9595
9696``` js
9797b .patient ({
@@ -111,7 +111,7 @@ b.patient({
111111The "builder function" ` b.patient() ` handles the profile URL, the full
112112identifier type coding, and the extension structure automatically. It also
113113provides convenient facilities for mapping values from the incoming data
114- source - so sintead of something like this:
114+ source - so instead of something like this:
115115
116116```
117117state.patient = {
@@ -136,13 +136,14 @@ easier to read, easier to reason about, and easier to modify.
136136
137137### Builder functions
138138
139- All builder functions are available on the ` b ` (short for ` builders ` ) namespac .
139+ All builder functions are available on the ` b ` (short for ` builders ` ) namespace .
140140
141- There is a builder for every resource type in the Eswatini IG: ` b.patient() ` ,
142- ` b.encounter() ` , ` b.observation() ` , ` b.condition() ` and so on. See the
143- [ reference docs] ( /adaptors/packages/fhir-eswatini-docs ) for the full list.
141+ There is a builder for every resource type in the Eswatini IG: such as
142+ ` b.patient() ` , ` b.encounter() ` , ` b.observation() ` , ` b.condition() ` and so on.
143+ See the [ reference docs] ( /adaptors/packages/fhir-eswatini-docs ) for the full
144+ list.
144145
145- Pass a plain object with the properties you want:
146+ Pass a plain object with the properties you want to assign to the resource :
146147
147148``` js
148149const patient = b .patient ({
@@ -151,8 +152,22 @@ const patient = b.patient({
151152});
152153```
153154
154- Builders are not operations themselves. Pass them as an argument to an operation
155- like ` create() ` , or use them inside a callback:
155+ Some resource types, like Observation, support multiple profiles. Pass a profile
156+ name as the first value to these builders:
157+
158+ ``` js
159+ const patient = b .observation (' SzLabResult' , {
160+ code: ' CD4' ,
161+ });
162+ ```
163+
164+ The in-app code-editor provides full code-complete (typeahead) on all functions,
165+ including profile names.
166+
167+ Builders are not operations themselves, so you can't use the at the top level of
168+ your job code. Pass them as an argument to an operation like
169+ ` create(b.patient(...) ` or ` addToBundle(b.patient(...)) ` , or use them inside a
170+ callback:
156171
157172``` js
158173fn (state => {
@@ -163,11 +178,8 @@ fn(state => {
163178
164179### Bundling
165180
166- See the base ` fhir-4 ` docs for details of the ` createBundle ` , ` addToBundle ` and
167- ` uploadBundle ` functions.
168-
169- The ` fhir-eswatini ` adaptor will generate correct URLs for each entry, and sort
170- by dependency order.
181+ The ` fhir-eswatini ` adaptor provides API support to create, manage and upload
182+ bundles.
171183
172184``` js
173185addToBundle (
@@ -179,10 +191,47 @@ addToBundle(
179191uploadBundle ();
180192```
181193
194+ The final ` uploadBundle() ` function will generate correct URLs for each entry,
195+ and sort entries by dependency order.
196+
197+ See the base ` fhir-4 ` docs for details of the ` createBundle ` , ` addToBundle ` and
198+ ` uploadBundle ` functions.
199+
182200### Value mapping
183201
184- The adaptor knows the Eswatini IG's value sets, so short code values are
185- automatically expanded to full coded concepts.
202+ FHIR data structures are very verbose. In many cases, complex structure values
203+ can be mapped to a simple string values.
204+
205+ For example, an Encounter resource has a ` class ` property to specify the
206+ location the encounter took place:
207+
208+ ``` js
209+ b .encounter ({
210+ class: {
211+ code: ' OPD' ,
212+ display: ' Outpatient Department' ,
213+ system:
214+ ' https://hapifhir.eswatinihie.com/fhir/CodeSystem/SzEncounterClassificationCS' ,
215+ },
216+ });
217+ ```
218+
219+ Using value mappings generated from the Eswatini IG, we can accept a short-hand
220+ string value in the builder which will expand this whole structure internally:
221+
222+ ``` js
223+ b .encounter ({
224+ class: ' OPD' ,
225+ });
226+ ```
227+
228+ The builder knows the that ` class ` property of encounter is bound to a
229+ particular value set. So it will automatically try and lookup a string value
230+ against the list of known codes. If it finds one, it'll replace the string with
231+ the full object definition above.
232+
233+ This mapping applies to any property or extension for which the IG specifies a
234+ value set.
186235
187236For example, an identifier's ` type ` accepts a short code from the Eswatini
188237Person Identifications code system:
@@ -197,32 +246,38 @@ b.patient({
197246});
198247```
199248
200- The same applies to other coded fields. For example, an encounter's ` class `
201- accepts short codes like ` OPD ` , ` IPD ` , ` CO ` , and ` SO ` :
202-
203- ``` js
204- b .encounter ({
205- class: ' OPD' , // expands to full coding with system and display
206- });
207- ```
208-
209- You can pass mappings with the code or display values:
249+ Expands to:
210250
211251``` js
212252b .patient ({
213- inkundla: ' mbabane' , // or code 264
253+ identifier: {
254+ type: {
255+ coding: [
256+ {
257+ system:
258+ ' https://hapifhir.eswatinihie.com/fhir/CodeSystem/SzPersonIdentificationsCS' ,
259+ code: ' PI' ,
260+ display: ' Personal ID Number' ,
261+ },
262+ ],
263+ },
264+ system: ' http://homeaffairs.sys' ,
265+ value: ' 1999001000000' ,
266+ },
214267});
215268```
216269
217270To know the range of values allowed, follow the links in the docs to the value
218271set definition (the docs will link you straight into the Implementation Guide).
219- Any Code or Display value declared on that page is allowed .
272+ Any Code or Display value declared on that page is accepted .
220273
221274If a mapping fails, the value you passed in will be fed through the final FHIR
222275resource, unmapped and untouched.
223276
224277![ Example listing of code values from the FHIR IG] ( /img/fhir-eswatini-valueset-example.png )
225278
279+ ### Custom Value Mapping
280+
226281You can also define your own value mappings. This is useful when mapping your
227282input data into FHIR. Just declare the mappings at the top of your job code with
228283the correct URL and whatever values you want.
@@ -244,6 +299,17 @@ b.setValues(
244299);
245300```
246301
302+ ::: tip
303+
304+ Because it is a plain Javascript function, not an Operation, ` b.setValues ` can
305+ only be used inside a callback or fn block.
306+
307+ ` fhir-eswatini ` v0.6.0 provides a ` setMappings ` operation, with the same API as
308+ ` setValues ` , which allows value maps to be set from the top level of your job
309+ code.
310+
311+ :::
312+
247313Custom mappings like this do not override the default system values. In fact,
248314your custom mappings are expanded first and THEN the system mappings cut in - so
249315you can declare custom mappings which map right to codings, which will then be
@@ -267,8 +333,8 @@ b.patient({
267333});
268334```
269335
270- If you declare mappings relative to the format your source data, you can declare
271- the value based on your data without complex mapping code
336+ If you declare mappings relative to the format of your source data, you can
337+ declare the value based on your data without complex mapping code
272338
273339``` js
274340b .patient ({
0 commit comments